Skip to content

Commit

Permalink
Pins JWT to ~> 1.0.0 and fixes tests.
Browse files Browse the repository at this point in the history
JWT started to return both the payload and a header when decoding a token since
[this pull request](jwt/ruby-jwt#35). This has
since become part of the version 1.0 release, so this gem might as well
encourage usage of 1.0 and get fixed tests for that.
  • Loading branch information
philnash committed Jul 21, 2014
1 parent 9bb1685 commit 6778a9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions spec/util/capability_spec.rb
Expand Up @@ -11,45 +11,45 @@ def queries(q)

it 'should return a valid jwt when #generate is called' do
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
decoded['scope'].should_not be_nil
decoded['iss'].should_not be_nil
decoded['exp'].should_not be_nil
end

it 'should properly set the iss key in the payload' do
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
decoded['iss'].should == 'myAccountSid'
end

it 'should properly set the exp key based on the default hour ttl' do
seconds = Time.now.to_i
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
decoded['exp'].should == seconds + 3600
end

it 'should properly set the exp key based on the ttl passed to #generate' do
ttl = rand 10000
seconds = Time.now.to_i
token = @capability.generate ttl
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
decoded['exp'].should == seconds + ttl
end

it 'should generate a proper incoming client scope string' do
@capability.allow_client_incoming 'andrew'
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [['incoming', {'clientName' => 'andrew'}]]
end

it 'should generate multiple proper incoming client scope strings' do
@capability.allow_client_incoming 'andrew'
@capability.allow_client_incoming 'bridget'
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [
['incoming', {'clientName' => 'andrew'}],
['incoming', {'clientName' => 'bridget'}]
Expand All @@ -59,7 +59,7 @@ def queries(q)
it 'should generate a proper outgoing client scope string' do
@capability.allow_client_outgoing 'myAppSid'
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [['outgoing', {'appSid' => 'myAppSid'}]]
end

Expand All @@ -70,7 +70,7 @@ def queries(q)
params_hash = {'appSid' => 'myAppSid', 'appParams' => app_params}
@capability.instance_eval {url_encode(params_hash)}
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [['outgoing', params_hash]]
end

Expand All @@ -79,7 +79,7 @@ def queries(q)
@capability.allow_client_incoming 'andrew'
@capability.allow_client_outgoing 'myAppSid'
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [
['incoming', {'clientName' => 'andrew'}],
['outgoing', {'clientName' => 'andrew', 'appSid' => 'myAppSid'}]
Expand All @@ -91,7 +91,7 @@ def queries(q)
@capability.allow_client_outgoing 'myAppSid'
@capability.allow_client_incoming 'andrew'
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
queries(decoded['scope']).should == [["incoming", {"clientName"=>"andrew"}], ["outgoing", {"clientName"=>"andrew", "appSid"=>"myAppSid"}]]
end

Expand All @@ -104,7 +104,7 @@ def queries(q)
params_hash = {'appSid' => 'myAppSid', 'appParams' => app_params, 'clientName' => 'andrew'}
@capability.instance_eval {url_encode(params_hash)}
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
scopes = queries(decoded['scope'])
scopes.shift.should == ["incoming", {"clientName"=>"andrew"}]
scope = scopes.shift
Expand All @@ -124,7 +124,7 @@ def queries(q)
params_hash = {'appSid' => 'myAppSid', 'appParams' => app_params, 'clientName' => 'andrew'}
@capability.instance_eval {url_encode(params_hash)}
token = @capability.generate
decoded = JWT.decode token, 'myAuthToken'
decoded, header = JWT.decode token, 'myAuthToken'
scopes = queries(decoded['scope'])
scopes.shift.should == ["incoming", {"clientName"=>"andrew"}]
scope = scopes.shift
Expand Down
2 changes: 1 addition & 1 deletion twilio-ruby.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|

s.add_dependency('multi_json', '>= 1.3.0')
s.add_dependency('builder', '>= 2.1.2')
s.add_dependency('jwt', '>= 0.1.2')
s.add_dependency('jwt', '~> 1.0.0')
s.add_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'
# Workaround for RBX <= 2.2.1, should be fixed in next version
s.add_dependency('rubysl') if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
Expand Down

0 comments on commit 6778a9a

Please sign in to comment.