This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
client_login_examples.rb
84 lines (68 loc) · 2.08 KB
/
client_login_examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
shared_examples_for 'client login prompts' do
let(:uaa) { CFoundry::UAAClient.new }
let(:prompts) do
{
:user_id => ["text", "User ID"],
:pin => ["password", "Your 8-digit Pin #"]
}
end
before do
stub(client.base).uaa { uaa }
stub(uaa).prompts { prompts }
end
subject { client.login_prompts }
it 'returns the prompts provided by UAA' do
expect(subject).to eq(prompts)
end
end
shared_examples_for 'client login' do
let(:email) { 'test@test.com' }
let(:password) { 'secret' }
let(:uaa) { CFoundry::UAAClient.new }
let(:access_token) { "some-access-token" }
let(:token_info) { CF::UAA::TokenInfo.new({ :access_token => access_token, :token_type => "bearer" }) }
before do
stub(client.base).uaa { uaa }
stub(uaa).authorize(email, password) { token_info }
end
subject { client.login(email, password) }
it 'returns a UAA token' do
expect(subject).to be_a(CFoundry::AuthToken)
expect(subject.auth_header).to eq("bearer #{access_token}")
end
it 'saves the data as the token' do
subject
expect(client.token).to be_a(CFoundry::AuthToken)
expect(client.token.auth_header).to eq("bearer #{access_token}")
end
end
shared_examples_for 'client login prompts without UAA' do
let(:prompts) do
{
:user_id => ["text", "User ID"],
:pin => ["password", "Your 8-digit Pin #"]
}
end
subject { client.login_prompts }
it 'returns the prompts without UAA' do
expect(subject).to eq(prompts)
end
end
shared_examples_for 'client login without UAA' do
let(:email) { 'test@test.com' }
let(:password) { 'secret' }
let(:access_token) { "some-access-token" }
before do
stub(client.base).create_token { access_token }
end
subject { client.login(email, password) }
it 'returns a CC token' do
expect(subject).to be_a(CFoundry::AuthToken)
expect(subject.auth_header).to eq("bearer #{access_token}")
end
it 'saves the data as the token' do
subject
expect(client.token).to be_a(CFoundry::AuthToken)
expect(client.token.auth_header).to eq("bearer #{access_token}")
end
end