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

Code review: Rspec test refactoring #85

Merged
merged 24 commits into from
Oct 27, 2015
Merged

Code review: Rspec test refactoring #85

merged 24 commits into from
Oct 27, 2015

Conversation

excpt
Copy link
Member

@excpt excpt commented Jun 10, 2015

Code review request. Please comment! :)

@excpt excpt added this to the Version 1.5.1 milestone Jun 10, 2015
@@ -163,17 +161,17 @@ def decode(jwt, key=nil, verify=true, options={}, &keyfinder)
if options[:verify_not_before] && payload.include?('nbf')
raise JWT::ImmatureSignature.new('Signature nbf has not been reached') unless payload['nbf'].to_i < (Time.now.to_i + options[:leeway])
end
if options[:verify_iss] && payload.include?('iss')
raise JWT::InvalidIssuerError.new("Invalid issuer. Expected #{options['iss']}, received #{payload['iss']}") unless payload['iss'].to_s == options['iss'].to_s
if options[:verify_iss] && options['iss']
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks like it could lead to problems with implementers:

if the caller passes :verify_iss but not 'iss' (or the other way around), then this could leas to an unexpected successful verification.

Probably worth adding a check and failing with an argument error in the case that one is specified but not both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review :)

Going to add more tests and implement checks for these cases.

@excpt excpt modified the milestones: Version 1.5.2, Version 1.5.1 Jun 22, 2015
expect(decoded_payload).to include(example_payload)
expect(decoded_payload2).to include(example_payload2)
end
it 'should decode a valid token' do
Copy link
Member

Choose a reason for hiding this comment

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

it should decode a valid token and it should generate a valid token are identical tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aj-michael How would you merge these two tests into a single test?

Copy link
Member

Choose a reason for hiding this comment

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

My apologies, I'm not saying they should be identical tests. I'm saying that at the moment, they are identical, as in they contain the same expressions. I don't believe they should be.

@aj-michael
Copy link
Member

Nitpick: can you choose a consistent syntax for hash literals with symbols? grep is counting 23 occurrences of :symbol => value syntax and 3 occurrences of symbol: value syntax.

@excpt
Copy link
Member Author

excpt commented Jul 28, 2015

@aj-michael This happens when I code on the train and look out of the window. Will fix that in upcoming commits.

Add fixtures/certs path
Update configuration
Used wrong curve -.- :/
Test coverage at 91%
Few validation specs missing
Remove 'NONE' fix
Add more tests for verifications
Copy paste new verification code from master
Comparing payloads now the right way
Payload hash key is always a string due to JSON en/de-coding
(cherry picked from commit ee7c24c)
Remove whitespaces
Add two iss claim tests from master branch.
Fix a typo.
excpt added a commit that referenced this pull request Oct 27, 2015
Code review: Rspec test refactoring
@excpt excpt merged commit 233fc14 into master Oct 27, 2015
@excpt excpt deleted the rspec-test-refactoring branch October 27, 2015 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants