Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the JSON data in load #36

Merged
merged 14 commits into from
Dec 14, 2017
Merged

Conversation

ashleym1972
Copy link
Contributor

Check to make sure that the loaded JSON actually contains data in the keys we are going to use before we use them, to avoid runtime exceptions on Nil.

Check to make sure that the loaded JSON actually contains data in the keys we are going to use before we use them, to avoid runtime exceptions on Nil.
@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-12.06%) to 87.938% when pulling cc4c70d on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@wallin wallin self-requested a review June 29, 2017 19:49
Copy link
Member

@wallin wallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ashleym1972, thank for you contribution. Would you mind adding a test for this.

@@ -20,6 +20,10 @@ def self.load_from_json(json)
raise RegistrationError, code: data['errorCode']
end

if data['clientData'].blank? || data['registrationData'].blank?
raise RegistrationError, code: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the code in a constant, for clarity

When trying to sign response make sue the data is correct and raise a known error rather than a method missing error on bad data.
@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-26.6%) to 73.359% when pulling 02e7162 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-26.5%) to 73.462% when pulling a8ad97a on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-51.5%) to 48.462% when pulling 9a88090 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

Coverage Status

Coverage decreased (-51.5%) to 48.462% when pulling bc64508 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

1 similar comment
@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-51.5%) to 48.462% when pulling bc64508 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage decreased (-26.5%) to 73.462% when pulling 77fee61 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 8928ba2 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jun 29, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 8928ba2 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@wallin
Copy link
Member

wallin commented Jul 3, 2017

Looks good to me. @mastahyeti any thoughts?

Copy link

@btoews btoews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems okay. Validating a JSON schema would be more robust, but would probably be overkill. Also, can you add a similar check to ClientData.load_from_json while you're at it?

@@ -4,6 +4,10 @@ class SignResponse

def self.load_from_json(json)
data = ::JSON.parse(json)
if data['clientData'].nil? || data['keyHandle'].nil? || data['signatureData'].nil?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing a #nil? check in one place and just checking that the key exists in the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which one people here prefer.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever, but it would be nice to be consistent if the intent is the same.

@@ -20,6 +21,10 @@ def self.load_from_json(json)
raise RegistrationError, code: data['errorCode']
end

if !data.key?('clientData') || !data.key?('registrationData')
raise RegistrationError, code: BAD_REQUEST
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error codes normally come from the browser. It might make more sense to pass a message: argument instead of a code:.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly that is not my use case. Additionally, the Rails / browser mind set in this library is a very bad idea.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error codes are specific to the JavaScript API (here). It would make more sense to specify an error message here than to reuse the codes from the JS API.

@coveralls
Copy link

coveralls commented Jul 24, 2017

Coverage Status

Coverage decreased (-8.5%) to 91.519% when pulling c8121f6 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jul 24, 2017

Coverage Status

Coverage decreased (-9.3%) to 90.734% when pulling 82a2076 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jul 24, 2017

Coverage Status

Coverage decreased (-9.3%) to 90.734% when pulling 82a2076 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jul 24, 2017

Coverage Status

Coverage decreased (-9.3%) to 90.734% when pulling 82a2076 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-9.3%) to 90.734% when pulling 9b90bb1 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling beeb140 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

1 similar comment
@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling beeb140 on ashleym1972:API_v1_1 into 16fbd3d on castle:API_v1_1.

@jnardone
Copy link

What's still missing here?

@wallin
Copy link
Member

wallin commented Dec 14, 2017

Sorry dropped the ball on this one. Merging

@wallin wallin merged commit 60671f7 into castle:API_v1_1 Dec 14, 2017
@jnardone
Copy link

Thanks @wallin - this library is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants