@@ -470,6 +470,55 @@ module CF::UAA
470470 end
471471 end
472472
473+ context 'with jwt bearer grant' do
474+
475+ it 'gets a token with jwt bearer' do
476+ subject . set_request_handler do |url , method , body , headers |
477+ headers [ 'content-type' ] . should =~ /application\/ x-www-form-urlencoded/
478+ headers [ 'accept' ] . should =~ /application\/ json/
479+ headers [ 'X-CF-ENCODED-CREDENTIALS' ] . should == 'true'
480+ headers [ 'authorization' ] . should == 'Basic dGVzdF9jbGllbnQ6dGVzdCUyMXNlY3JldA=='
481+ url . should == 'http://test.uaa.target/oauth/token'
482+ method . should == :post
483+ reply = { access_token : 'test_access_token' , token_type : 'BEARER' ,
484+ scope : 'openid' , expires_in : 98765 }
485+ [ 200 , Util . json ( reply ) , { 'content-type' => 'application/json' } ]
486+ end
487+ token = subject . jwt_bearer_grant ( 'assertion' , 'openid' )
488+ token . should be_an_instance_of TokenInfo
489+ token . info [ 'access_token' ] . should == 'test_access_token'
490+ token . info [ 'token_type' ] . should =~ /^bearer$/i
491+ token . info [ 'scope' ] . should == 'openid'
492+ token . info [ 'expires_in' ] . should == 98765
493+ end
494+
495+ context "when client & client secret are nil" do
496+ let ( :client_id ) { nil }
497+ let ( :client_secret ) { nil }
498+
499+ it 'does not error' do
500+ subject . set_request_handler do |url , method , body , headers |
501+ headers [ 'content-type' ] . should =~ /application\/ x-www-form-urlencoded/
502+ headers [ 'accept' ] . should =~ /application\/ json/
503+ headers [ 'X-CF-ENCODED-CREDENTIALS' ] . should == 'true'
504+ headers [ 'authorization' ] . should == 'Basic Og=='
505+ url . should == 'http://test.uaa.target/oauth/token'
506+ method . should == :post
507+ reply = { access_token : 'test_access_token' , token_type : 'BEARER' ,
508+ scope : 'openid' , expires_in : 98765 }
509+ [ 200 , Util . json ( reply ) , { 'content-type' => 'application/json' } ]
510+ end
511+ token = subject . jwt_bearer_grant ( 'assertion' , 'openid' )
512+ token . should be_an_instance_of TokenInfo
513+ token . info [ 'access_token' ] . should == 'test_access_token'
514+ token . info [ 'token_type' ] . should =~ /^bearer$/i
515+ token . info [ 'scope' ] . should == 'openid'
516+ token . info [ 'expires_in' ] . should == 98765
517+ end
518+ end
519+
520+ end
521+
473522end
474523
475524end
0 commit comments