Skip to content

Commit

Permalink
Merge pull request #17 from threedaymonk/truthiness
Browse files Browse the repository at this point in the history
Verify if verify is truthy (not just true)
  • Loading branch information
progrium committed Mar 13, 2013
2 parents 76fb4f2 + ffa5dd3 commit f7e7337
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.decode(jwt, key=nil, verify=true, &keyfinder)
rescue MultiJson::LoadError => e
raise JWT::DecodeError.new("Invalid segment encoding")
end
if verify == true
if verify
algo = header['alg']

if keyfinder
Expand Down
8 changes: 8 additions & 0 deletions spec/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
decoded_payload.should == @payload
end

it "checks the key when verify is truthy" do
right_secret = 'foo'
bad_secret = 'bar'
jwt = JWT.encode(@payload, right_secret)
verify = "yes" =~ /^y/i
lambda { JWT.decode(jwt, bad_secret, verify) }.should raise_error(JWT::DecodeError)
end

it "raises exception on unsupported crypto algorithm" do
lambda { JWT.encode(@payload, "secret", 'HS1024') }.should raise_error(NotImplementedError)
end
Expand Down

0 comments on commit f7e7337

Please sign in to comment.