cf 4.1.5.rc7 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,16 +16,27 @@ module CF::Start
16
16
  :from_given => by_name(:organization)
17
17
  input :space, :desc => "Space", :alias => "-s",
18
18
  :from_given => by_name(:space)
19
+ input :sso, :desc => "Log in via SSO",
20
+ :alias => "--sso", :default => false
19
21
  def login
20
22
  show_context
21
23
 
22
- credentials = { :username => input[:username], :password => input[:password] }
24
+ expected_prompts = if input[:sso]
25
+ [:username, :passcode]
26
+ else
27
+ [:username, :password]
28
+ end
29
+
30
+ credentials = {
31
+ :username => input[:username],
32
+ :password => input[:password]
33
+ }
23
34
 
24
35
  prompts = client.login_prompts
25
36
 
26
37
  # ask username first
27
- if prompts.key? :username
28
- type, label = prompts.delete :username
38
+ if prompts.key?(:username)
39
+ type, label = prompts.delete(:username)
29
40
  credentials[:username] ||= ask_prompt(type, label)
30
41
  end
31
42
 
@@ -41,19 +52,18 @@ module CF::Start
41
52
  failed = false
42
53
 
43
54
  unless force?
44
- ask_prompts(credentials, prompts)
55
+ ask_prompts(credentials, prompts.slice(*expected_prompts))
45
56
  end
46
57
 
47
58
  with_progress("Authenticating") do |s|
48
59
  begin
49
- auth_token = client.login(credentials[:username], credentials[:password])
60
+ auth_token = client.login(credentials.slice(*expected_prompts))
50
61
  authenticated = true
51
62
  rescue CFoundry::Denied
52
63
  return if force?
53
-
54
64
  s.fail do
55
65
  failed = true
56
- credentials.delete(:password)
66
+ credentials = credentials.slice(:username)
57
67
  end
58
68
  end
59
69
  end
@@ -1,3 +1,3 @@
1
1
  module CF
2
- VERSION = "4.1.5.rc7".freeze
2
+ VERSION = "4.2.0".freeze
3
3
  end
@@ -28,74 +28,115 @@ describe CF::Start::Login do
28
28
  end
29
29
 
30
30
  describe "arguments" do
31
- subject(:arguments) { command.arguments }
31
+ subject { command.arguments }
32
+
32
33
  it "have the correct commands" do
33
- expect(arguments).to eq [{:type => :optional, :value => :email, :name => :username}]
34
+ expect(subject).to eq [{
35
+ :type => :optional,
36
+ :value => :email,
37
+ :name => :username
38
+ }]
34
39
  end
35
40
  end
36
41
  end
37
42
 
38
43
  describe "running the command" do
39
- before do
40
- stub_client
41
- end
44
+ before { stub_client }
42
45
 
43
46
  stub_home_dir_with { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
44
47
 
45
- let(:auth_token) { CFoundry::AuthToken.new("bearer some-new-access-token", "some-new-refresh-token") }
46
- let(:tokens_yaml) { YAML.load_file(File.expand_path(tokens_file_path)) }
47
- let(:tokens_file_path) { "~/.cf/tokens.yml" }
48
-
49
48
  before do
50
- client.stub(:login).with("my-username", "my-password") { auth_token }
51
49
  client.stub(:login_prompts).and_return(
52
- {
53
- :username => ["text", "Username"],
54
- :password => ["password", "8-digit PIN"]
55
- })
56
-
57
- stub_ask("Username", {}) { "my-username" }
58
- stub_ask("8-digit PIN", {:echo => "*", :forget => true}) { "my-password" }
50
+ :username => ["text", "username-prompt"],
51
+ :password => ["password", "password-prompt"],
52
+ :passcode => ["password", "passcode-prompt"]
53
+ )
59
54
  end
60
55
 
61
- subject { cf ["login"] }
62
-
63
- context "when there is a target" do
64
- before do
65
- CF::Populators::Target.any_instance.stub(:populate_and_save!)
66
- stub_precondition
67
- end
68
-
69
- it "logs in with the provided credentials and saves the token data to the YAML file" do
70
- subject
56
+ def self.it_logs_in_user_with_credentials(expected_credentials)
57
+ context "when there is a target" do
58
+ before { stub_precondition }
59
+
60
+ context "when user is successfully authenticated" do
61
+ before { client.stub(:login).with(expected_credentials) { auth_token } }
62
+ before { CF::Populators::Target.any_instance.stub(:populate_and_save!) }
63
+ let(:auth_token) { CFoundry::AuthToken.new("bearer some-new-access-token", "some-new-refresh-token") }
64
+
65
+ it "logs in with the provided credentials and saves the token data to the YAML file" do
66
+ subject
67
+ expect(tokens_yaml["https://api.some-domain.com"][:token]).to eq("bearer some-new-access-token")
68
+ expect(tokens_yaml["https://api.some-domain.com"][:refresh_token]).to eq("some-new-refresh-token")
69
+ end
70
+
71
+ it "calls use a PopulateTarget to ensure that an organization and space is set" do
72
+ CF::Populators::Target.should_receive(:new) { double(:target, :populate_and_save! => true) }
73
+ subject
74
+ end
75
+ end
71
76
 
72
- expect(tokens_yaml["https://api.some-domain.com"][:token]).to eq("bearer some-new-access-token")
73
- expect(tokens_yaml["https://api.some-domain.com"][:refresh_token]).to eq("some-new-refresh-token")
74
- end
77
+ context "when the user logs in with invalid credentials" do
78
+ before do
79
+ client
80
+ .should_receive(:login)
81
+ .with(expected_credentials)
82
+ .exactly(3).times
83
+ .and_raise(CFoundry::Denied)
84
+ end
85
+
86
+ it "informs the user gracefully about authentication failure" do
87
+ subject
88
+ expect(output).to say("Authenticating... FAILED")
89
+ end
90
+
91
+ it "does not save token data" do
92
+ expect {
93
+ subject
94
+ }.to_not change { tokens_yaml["https://api.some-domain.com"] }
95
+ end
96
+
97
+ it "does not call PopulateTarget" do
98
+ CF::Populators::Target.should_not_receive(:new)
99
+ subject
100
+ end
101
+ end
75
102
 
76
- it "calls use a PopulateTarget to ensure that an organization and space is set" do
77
- CF::Populators::Target.should_receive(:new) { double(:target, :populate_and_save! => true) }
78
- subject
103
+ def tokens_yaml
104
+ YAML.load_file(File.expand_path("~/.cf/tokens.yml"))
105
+ end
79
106
  end
80
107
 
81
- context "when the user logs in with invalid credentials" do
82
- before do
83
- client.should_receive(:login).with("my-username", "my-password").and_raise(CFoundry::Denied)
84
- end
108
+ context "when there is no target" do
109
+ before { client.stub(:target) { nil } }
85
110
 
86
- it "informs the user gracefully" do
111
+ it "tells the user to select a target" do
87
112
  subject
88
- expect(output).to say("Authenticating... FAILED")
113
+ expect(error_output).to say("Please select a target with 'cf target'.")
89
114
  end
90
115
  end
91
116
  end
92
117
 
93
- context "when there is no target" do
94
- it "tells the user to select a target" do
95
- client.stub(:target) { nil }
96
- subject
97
- expect(error_output).to say("Please select a target with 'cf target'.")
118
+ context "when user is trying to log in with username/password" do
119
+ subject { cf ["login"] }
120
+
121
+ before do
122
+ stub_ask("username-prompt", {}) { "my-username" }
123
+ stub_ask("password-prompt", {:echo => "*", :forget => true}) { "my-password" }
98
124
  end
125
+
126
+ it_logs_in_user_with_credentials(
127
+ :username => "my-username", :password => "my-password")
128
+ end
129
+
130
+ context "when user is trying to log in via sso" do
131
+ subject { cf ["login", "--sso"] }
132
+
133
+ before do
134
+ stub_ask("username-prompt", {}) { "my-username" }
135
+ stub_ask("passcode-prompt", {:echo => "*", :forget => true}) { "my-passcode" }
136
+ end
137
+
138
+ it_logs_in_user_with_credentials(
139
+ :username => "my-username", :passcode => "my-passcode")
99
140
  end
100
141
  end
101
142
  end
@@ -46,10 +46,10 @@ if ENV['CF_V2_RUN_INTEGRATION']
46
46
 
47
47
  # TODO: not this.
48
48
  client = CFoundry::V2::Client.new("https://#{target}")
49
- client.login(email, password)
49
+ client.login(:username => email, :password => password)
50
50
  user = client.current_user
51
51
  guid = user.guid
52
- client.login(username, password)
52
+ client.login(:username => username, :password => password)
53
53
  user.delete!
54
54
 
55
55
  BlueShell::Runner.run("#{cf_bin} login #{email} --password #{password}") do |runner|
@@ -19,7 +19,7 @@ if ENV['CF_V2_RUN_INTEGRATION']
19
19
 
20
20
  let(:client) do
21
21
  client = CFoundry::V2::Client.new("https://#{target}")
22
- client.login(username, password)
22
+ client.login(:username => username, :password => password)
23
23
  client
24
24
  end
25
25
 
@@ -39,10 +39,10 @@ if ENV['CF_V2_RUN_INTEGRATION']
39
39
  #end
40
40
 
41
41
  # TODO: not this.
42
- client.login(new_user, password)
42
+ client.login(:username => new_user, :password => password)
43
43
  user = client.current_user
44
44
  guid = user.guid
45
- client.login(username, password)
45
+ client.login(:username => username, :password => password)
46
46
  user.delete!
47
47
 
48
48
  logout
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5.rc7
5
- prerelease: 6
4
+ version: 4.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cloud Foundry Team
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.3.7.rc1
54
+ version: 2.4.0
55
55
  - - <
56
56
  - !ruby/object:Gem::Version
57
57
  version: '3.0'
@@ -62,7 +62,7 @@ dependencies:
62
62
  requirements:
63
63
  - - ! '>='
64
64
  - !ruby/object:Gem::Version
65
- version: 2.3.7.rc1
65
+ version: 2.4.0
66
66
  - - <
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
@@ -287,7 +287,7 @@ dependencies:
287
287
  requirements:
288
288
  - - ~>
289
289
  - !ruby/object:Gem::Version
290
- version: '2.11'
290
+ version: '2.14'
291
291
  type: :development
292
292
  prerelease: false
293
293
  version_requirements: !ruby/object:Gem::Requirement
@@ -295,7 +295,7 @@ dependencies:
295
295
  requirements:
296
296
  - - ~>
297
297
  - !ruby/object:Gem::Version
298
- version: '2.11'
298
+ version: '2.14'
299
299
  - !ruby/object:Gem::Dependency
300
300
  name: rspec-instafail
301
301
  requirement: !ruby/object:Gem::Requirement
@@ -621,13 +621,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
621
621
  version: '0'
622
622
  segments:
623
623
  - 0
624
- hash: -2597973038898250794
624
+ hash: -3067736144323404377
625
625
  required_rubygems_version: !ruby/object:Gem::Requirement
626
626
  none: false
627
627
  requirements:
628
- - - ! '>'
628
+ - - ! '>='
629
629
  - !ruby/object:Gem::Version
630
- version: 1.3.1
630
+ version: '0'
631
+ segments:
632
+ - 0
633
+ hash: -3067736144323404377
631
634
  requirements: []
632
635
  rubyforge_project: cf
633
636
  rubygems_version: 1.8.25