Skip to content

Commit

Permalink
uaa: scope uaa config portion for token decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Nugmanov and Dmitriy Kalinin committed Mar 20, 2013
1 parent c6e6b7c commit 155cc96
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/cloud_controller/runner.rb
Expand Up @@ -156,7 +156,7 @@ def populate_framework_and_runtimes
end

def create_app(config)
token_decoder = VCAP::UaaTokenDecoder.new(config)
token_decoder = VCAP::UaaTokenDecoder.new(config[:uaa])

Rack::Builder.new do
use Rack::CommonLogger
Expand Down
6 changes: 3 additions & 3 deletions lib/vcap/uaa_util.rb
Expand Up @@ -40,16 +40,16 @@ def decode_token_with_asymmetric_key(auth_token)
end

def decode_token_with_key(auth_token, options)
options = {:audience_ids => config[:uaa][:resource_id]}.merge(options)
options = {:audience_ids => config[:resource_id]}.merge(options)
CF::UAA::TokenCoder.new(options).decode(auth_token)
end

def symmetric_key
config[:uaa][:symmetric_secret]
config[:symmetric_secret]
end

def asymmetric_key
@asymmetric_key ||= UaaVerificationKey.new(config[:uaa])
@asymmetric_key ||= UaaVerificationKey.new(config)
end
end

Expand Down
3 changes: 1 addition & 2 deletions spec/api/spec_helper.rb
Expand Up @@ -41,8 +41,7 @@ module VCAP::CloudController::ApiSpecHelper
]

def app
token_decoder = VCAP::UaaTokenDecoder.new(config)

token_decoder = VCAP::UaaTokenDecoder.new(config[:uaa])
klass = Class.new(VCAP::CloudController::Controller)
klass.use(NginxUpload)
klass.new(config, token_decoder)
Expand Down
3 changes: 1 addition & 2 deletions spec/cloud_controller_spec.rb
Expand Up @@ -14,9 +14,8 @@
}}

def app
token_decoder = VCAP::UaaTokenDecoder.new(config)
token_decoder = VCAP::UaaTokenDecoder.new(config[:uaa])
token_decoder.stub(:decode_token => token_info)

described_class.new(config, token_decoder)
end

Expand Down
11 changes: 4 additions & 7 deletions spec/vcap/uaa_util_spec.rb
Expand Up @@ -8,16 +8,13 @@ module VCAP
subject { described_class.new(config_hash) }

let(:config_hash) do
{:redis => {},
:uaa => {
:resource_id => "resource-id",
:symmetric_secret => nil,
}}
{ :resource_id => "resource-id",
:symmetric_secret => nil }
end

describe "#decode_token" do
context "when symmetric key is used" do
before { config_hash[:uaa][:symmetric_secret] = "symmetric-key" }
before { config_hash[:symmetric_secret] = "symmetric-key" }

context "when toke is valid" do
it "uses UAA::TokenCoder to decode the token with skey" do
Expand Down Expand Up @@ -45,7 +42,7 @@ module VCAP
end

context "when asymmetric key is used" do
before { config_hash[:uaa][:symmetric_secret] = nil }
before { config_hash[:symmetric_secret] = nil }

before { Timecop.freeze(Time.now) }
after { Timecop.return }
Expand Down

0 comments on commit 155cc96

Please sign in to comment.