cfoundry 2.3.7.rc1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cfoundry/client.rb +2 -1
- data/lib/cfoundry/concerns/login_helpers.rb +4 -3
- data/lib/cfoundry/uaaclient.rb +11 -10
- data/lib/cfoundry/v2/client.rb +1 -1
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/uaaclient_spec.rb +11 -8
- data/spec/support/shared_examples/client_login_examples.rb +2 -2
- metadata +9 -6
data/lib/cfoundry/client.rb
CHANGED
@@ -19,11 +19,12 @@ require "cfoundry/v2/app_event"
|
|
19
19
|
|
20
20
|
require "cfoundry/v2/base"
|
21
21
|
require "cfoundry/v2/client"
|
22
|
+
#require "cfoundry/v2/fake_client"
|
22
23
|
|
23
24
|
module CFoundry
|
24
25
|
class Client < BaseClient
|
25
26
|
def self.new(*args)
|
26
|
-
|
27
|
+
warn "DEPRECATION WARNING: Please use CFoundry::Client.get instead of CFoundry::Client.new"
|
27
28
|
get(*args)
|
28
29
|
end
|
29
30
|
|
@@ -6,8 +6,9 @@ module CFoundry
|
|
6
6
|
@base.uaa.prompts
|
7
7
|
end
|
8
8
|
|
9
|
-
def login(
|
10
|
-
|
9
|
+
def login(credentials)
|
10
|
+
token_info = @base.uaa.authorize(credentials)
|
11
|
+
@base.token = AuthToken.from_uaa_token_info(token_info)
|
11
12
|
end
|
12
13
|
end
|
13
|
-
end
|
14
|
+
end
|
data/lib/cfoundry/uaaclient.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "cfoundry/baseclient"
|
2
|
-
require
|
2
|
+
require "uaa"
|
3
3
|
|
4
4
|
module CFoundry
|
5
5
|
class UAAClient
|
@@ -17,12 +17,10 @@ module CFoundry
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def authorize(
|
21
|
-
@username = username
|
22
|
-
@password = password
|
23
|
-
|
20
|
+
def authorize(credentials)
|
24
21
|
wrap_uaa_errors do
|
25
|
-
authenticate_with_password_grant ||
|
22
|
+
authenticate_with_password_grant(credentials) ||
|
23
|
+
authenticate_with_implicit_grant(credentials)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
@@ -103,9 +101,12 @@ module CFoundry
|
|
103
101
|
@uaa_url ||= CF::UAA::Misc.discover_uaa(target)
|
104
102
|
end
|
105
103
|
|
106
|
-
def authenticate_with_password_grant
|
104
|
+
def authenticate_with_password_grant(credentials)
|
107
105
|
begin
|
108
|
-
|
106
|
+
# Currently owner_password_grant method does not allow
|
107
|
+
# non-password based authenticate; so we have cheat a little bit.
|
108
|
+
token_issuer.send(:request_token,
|
109
|
+
{:grant_type => "password", :scope => nil}.merge(credentials))
|
109
110
|
rescue CF::UAA::BadResponse => e
|
110
111
|
status_code = e.message[/\d+/] || 400
|
111
112
|
raise CFoundry::Denied.new("Authorization failed", status_code)
|
@@ -114,9 +115,9 @@ module CFoundry
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
|
-
def authenticate_with_implicit_grant
|
118
|
+
def authenticate_with_implicit_grant(credentials)
|
118
119
|
begin
|
119
|
-
token_issuer.implicit_grant_with_creds(
|
120
|
+
token_issuer.implicit_grant_with_creds(credentials)
|
120
121
|
rescue CF::UAA::BadResponse => e
|
121
122
|
status_code = e.message[/\d+/] || 400
|
122
123
|
raise CFoundry::Denied.new("Authorization failed", status_code)
|
data/lib/cfoundry/v2/client.rb
CHANGED
data/lib/cfoundry/version.rb
CHANGED
@@ -72,24 +72,29 @@ EOF
|
|
72
72
|
let(:auth) { Object.new }
|
73
73
|
let(:issuer) { Object.new }
|
74
74
|
|
75
|
-
subject { uaa.authorize(
|
75
|
+
subject { uaa.authorize(creds) }
|
76
76
|
|
77
77
|
before do
|
78
|
-
issuer.stub(:
|
78
|
+
issuer.stub(:request_token) { auth }
|
79
79
|
uaa.stub(:token_issuer) { issuer }
|
80
80
|
end
|
81
81
|
|
82
82
|
include_examples "UAA wrapper"
|
83
83
|
|
84
84
|
it 'returns the token on successful authentication' do
|
85
|
-
issuer
|
85
|
+
issuer
|
86
|
+
.should_receive(:request_token)
|
87
|
+
.with(:grant_type => "password",
|
88
|
+
:scope => nil,
|
89
|
+
:username => username,
|
90
|
+
:password => password) { auth }
|
86
91
|
expect(subject).to eq auth
|
87
92
|
end
|
88
93
|
|
89
94
|
context 'when authorization fails' do
|
90
95
|
context 'in the expected way' do
|
91
96
|
it 'raises a CFoundry::Denied error' do
|
92
|
-
issuer.should_receive(:
|
97
|
+
issuer.should_receive(:request_token) { raise CF::UAA::BadResponse.new("401: FooBar") }
|
93
98
|
expect { subject }.to raise_error(CFoundry::Denied, "401: Authorization failed")
|
94
99
|
end
|
95
100
|
end
|
@@ -97,15 +102,13 @@ EOF
|
|
97
102
|
|
98
103
|
context 'in an unexpected way' do
|
99
104
|
it 'raises a CFoundry::Denied error' do
|
100
|
-
issuer.should_receive(:
|
105
|
+
issuer.should_receive(:request_token) { raise CF::UAA::BadResponse.new("no_status_code") }
|
101
106
|
expect { subject }.to raise_error(CFoundry::Denied, "400: Authorization failed")
|
102
107
|
end
|
103
108
|
end
|
104
109
|
|
105
110
|
context "with a CF::UAA::TargetError" do
|
106
|
-
before
|
107
|
-
issuer.stub(:owner_password_grant) { raise CF::UAA::TargetError.new("useless info") }
|
108
|
-
end
|
111
|
+
before { issuer.stub(:request_token) { raise CF::UAA::TargetError.new("useless info") } }
|
109
112
|
|
110
113
|
it "retries with implicit grant" do
|
111
114
|
issuer.should_receive(:implicit_grant_with_creds).with(:username => username, :password => password)
|
@@ -28,10 +28,10 @@ shared_examples_for 'client login' do
|
|
28
28
|
|
29
29
|
before do
|
30
30
|
client.base.stub(:uaa) { uaa }
|
31
|
-
uaa.stub(:authorize).with(email, password) { token_info }
|
31
|
+
uaa.stub(:authorize).with(:username => email, :password => password) { token_info }
|
32
32
|
end
|
33
33
|
|
34
|
-
subject { client.login(email, password) }
|
34
|
+
subject { client.login(:username => email, :password => password) }
|
35
35
|
|
36
36
|
it 'returns a UAA token' do
|
37
37
|
expect(subject).to be_a(CFoundry::AuthToken)
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.4.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Cloud Foundry Team
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-07-
|
13
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -416,13 +416,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
416
416
|
version: '0'
|
417
417
|
segments:
|
418
418
|
- 0
|
419
|
-
hash:
|
419
|
+
hash: -3185654219291849147
|
420
420
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
421
421
|
none: false
|
422
422
|
requirements:
|
423
|
-
- - ! '
|
423
|
+
- - ! '>='
|
424
424
|
- !ruby/object:Gem::Version
|
425
|
-
version:
|
425
|
+
version: '0'
|
426
|
+
segments:
|
427
|
+
- 0
|
428
|
+
hash: -3185654219291849147
|
426
429
|
requirements: []
|
427
430
|
rubyforge_project: cfoundry
|
428
431
|
rubygems_version: 1.8.25
|