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

Handle client_id/client_secret nil case. #85

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/uaa/token_issuer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def request_token(params)
headers['authorization'] = Http.basic_auth(@client_id, @client_secret)
else
headers['X-CF-ENCODED-CREDENTIALS'] = 'true'
headers['authorization'] = Http.basic_auth(CGI.escape(@client_id), CGI.escape(@client_secret))
headers['authorization'] = Http.basic_auth(CGI.escape(@client_id || ''), CGI.escape(@client_secret || ''))
end
reply = json_parse_reply(@key_style, *request(@token_target, :post,
'/oauth/token', Util.encode_form(params), headers))
Expand Down
30 changes: 29 additions & 1 deletion spec/token_issuer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ module CF::UAA

before do
#Util.default_logger(:trace)
@issuer = TokenIssuer.new('http://test.uaa.target', 'test_client', 'test!secret', options)
@issuer = TokenIssuer.new('http://test.uaa.target', client_id, client_secret, options)
end

let(:client_id) { 'test_client' }
let(:client_secret) { 'test!secret' }

subject { @issuer }

describe 'initialize' do
Expand Down Expand Up @@ -106,6 +109,31 @@ module CF::UAA
token.info['expires_in'].should == 98765
end

context "when client & client secret are nil" do
let(:client_id) { nil }
let(:client_secret) { nil }

it 'does not error' do
subject.set_request_handler do |url, method, body, headers|
headers['content-type'].should =~ /application\/x-www-form-urlencoded/
headers['accept'].should =~ /application\/json/
headers['X-CF-ENCODED-CREDENTIALS'].should == 'true'
headers['authorization'].should == 'Basic Og=='
url.should == 'http://test.uaa.target/oauth/token'
method.should == :post
reply = {access_token: 'test_access_token', token_type: 'BEARER',
scope: 'openid', expires_in: 98765}
[200, Util.json(reply), {'content-type' => 'application/json'}]
end
token = subject.owner_password_grant('joe+admin', "?joe's%password$@ ", 'openid')
token.should be_an_instance_of TokenInfo
token.info['access_token'].should == 'test_access_token'
token.info['token_type'].should =~ /^bearer$/i
token.info['scope'].should == 'openid'
token.info['expires_in'].should == 98765
end
end

it 'gets a token with passcode' do
subject.set_request_handler do |url, method, body, headers|
headers['content-type'].should =~ /application\/x-www-form-urlencoded/
Expand Down