rhc 1.11.4 → 1.12.4
Sign up to get free protection for your applications and to get access to all the features.
- data/autocomplete/rhc_bash +39 -23
- data/features/domain.feature +8 -3
- data/features/lib/rhc_helper/commandify.rb +6 -0
- data/features/lib/rhc_helper/domain.rb +1 -1
- data/features/step_definitions/domain_steps.rb +9 -4
- data/lib/rhc/auth/basic.rb +4 -2
- data/lib/rhc/cli.rb +1 -0
- data/lib/rhc/commands/apps.rb +2 -4
- data/lib/rhc/commands/cartridge.rb +1 -0
- data/lib/rhc/commands/domain.rb +25 -11
- data/lib/rhc/commands/port_forward.rb +0 -1
- data/lib/rhc/commands/sshkey.rb +1 -1
- data/lib/rhc/helpers.rb +1 -0
- data/lib/rhc/highline_extensions.rb +2 -1
- data/lib/rhc/output_helpers.rb +21 -0
- data/lib/rhc/rest.rb +4 -2
- data/lib/rhc/rest/api.rb +9 -11
- data/lib/rhc/rest/application.rb +4 -0
- data/lib/rhc/rest/base.rb +11 -1
- data/lib/rhc/rest/cartridge.rb +1 -1
- data/lib/rhc/rest/client.rb +52 -29
- data/lib/rhc/rest/domain.rb +11 -1
- data/lib/rhc/rest/httpclient.rb +125 -0
- data/lib/rhc/rest/mock.rb +32 -8
- data/spec/rhc/auth_spec.rb +29 -22
- data/spec/rhc/command_spec.rb +13 -9
- data/spec/rhc/commands/account_spec.rb +2 -2
- data/spec/rhc/commands/app_spec.rb +9 -9
- data/spec/rhc/commands/authorization_spec.rb +11 -11
- data/spec/rhc/commands/cartridge_spec.rb +3 -3
- data/spec/rhc/commands/domain_spec.rb +51 -1
- data/spec/rhc/commands/logout_spec.rb +3 -3
- data/spec/rhc/commands/port_forward_spec.rb +7 -7
- data/spec/rhc/commands/server_spec.rb +2 -2
- data/spec/rhc/commands/setup_spec.rb +6 -6
- data/spec/rhc/commands/snapshot_spec.rb +10 -10
- data/spec/rhc/helpers_spec.rb +6 -6
- data/spec/rhc/rest_application_spec.rb +11 -11
- data/spec/rhc/rest_client_spec.rb +148 -36
- data/spec/rhc/rest_spec.rb +3 -3
- data/spec/rhc/wizard_spec.rb +20 -20
- data/spec/spec_helper.rb +52 -3
- metadata +5 -4
data/spec/rhc/helpers_spec.rb
CHANGED
@@ -70,7 +70,7 @@ describe AllRhcHelpers do
|
|
70
70
|
it_should_behave_like "colorized output"
|
71
71
|
end
|
72
72
|
|
73
|
-
it("should invoke debug from debug_error"){ expect{ subject.debug_error(
|
73
|
+
it("should invoke debug from debug_error"){ expect{ subject.debug_error(double(:class => "Mock", :message => 'msg', :backtrace => [])) }.to call(:debug).on($terminal).with("msg (Mock)\n ") }
|
74
74
|
|
75
75
|
it("should draw a table") do
|
76
76
|
subject.table([[10,2], [3,40]]) do |i|
|
@@ -211,12 +211,12 @@ describe AllRhcHelpers do
|
|
211
211
|
let(:arguments){ ['help', '--ssl-version=sslv3'] }
|
212
212
|
|
213
213
|
context 'on an older version of HTTPClient' do
|
214
|
-
before{ HTTPClient::SSLConfig.
|
214
|
+
before{ HTTPClient::SSLConfig.stub(:method_defined?).with(:ssl_version).and_return(false) }
|
215
215
|
it('should print an error') { run_output.should =~ /You are using an older version of the httpclient.*--ssl-version/ }
|
216
216
|
it('should error out') { expect{ run }.to exit_with_code(1) }
|
217
217
|
end
|
218
218
|
context 'a newer version of HTTPClient' do
|
219
|
-
before{ HTTPClient::SSLConfig.
|
219
|
+
before{ HTTPClient::SSLConfig.stub(:method_defined?).with(:ssl_version).and_return(true) }
|
220
220
|
it('should not print an error') { run_output.should_not =~ /You are using an older version of the httpclient.*--ssl-version/ }
|
221
221
|
it('should error out') { expect{ run }.to exit_with_code(0) }
|
222
222
|
end
|
@@ -248,9 +248,9 @@ describe AllRhcHelpers do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
context "#get_properties" do
|
251
|
-
it{ subject.send(:get_properties,
|
251
|
+
it{ subject.send(:get_properties, double(:plan_id => 'free'), :plan_id).should == [[:plan_id, 'Free']] }
|
252
252
|
context "when an error is raised" do
|
253
|
-
let(:bar){
|
253
|
+
let(:bar){ double.tap{ |s| s.should_receive(:foo).and_raise(::Exception) } }
|
254
254
|
it{ subject.send(:get_properties, bar, :foo).should == [[:foo, '<error>']] }
|
255
255
|
end
|
256
256
|
end
|
@@ -394,7 +394,7 @@ describe AllRhcHelpers do
|
|
394
394
|
let(:existent_host) { 'real_host' }
|
395
395
|
let(:nonexistent_host) { 'fake_host' }
|
396
396
|
|
397
|
-
before
|
397
|
+
before do
|
398
398
|
Resolv::Hosts.stub(:new) { resolver }
|
399
399
|
resolver.stub(:getaddress).with(existent_host) { existent_host }
|
400
400
|
resolver.stub(:getaddress).with(nonexistent_host){ Resolv::ResolvError }
|
@@ -55,14 +55,14 @@ module RHC
|
|
55
55
|
|
56
56
|
context "#add_cartridge" do
|
57
57
|
context "with a name" do
|
58
|
-
before{ stub_api_request(:any, app_links['ADD_CARTRIDGE']['relative']).with(:body => {:name => 'mock_cart_0'}.to_json).to_return(mock_cartridge_response) }
|
58
|
+
before{ stub_api_request(:any, app_links['ADD_CARTRIDGE']['relative'], false).with(:body => {:name => 'mock_cart_0'}.to_json).to_return(mock_cartridge_response) }
|
59
59
|
it "accepts a string" do
|
60
60
|
cart = app_obj.add_cartridge('mock_cart_0')
|
61
61
|
cart.should be_an_instance_of RHC::Rest::Cartridge
|
62
62
|
cart.name.should == 'mock_cart_0'
|
63
63
|
end
|
64
64
|
it "accepts an object" do
|
65
|
-
cart = app_obj.add_cartridge(
|
65
|
+
cart = app_obj.add_cartridge(double(:name => 'mock_cart_0', :url => nil))
|
66
66
|
cart.should be_an_instance_of RHC::Rest::Cartridge
|
67
67
|
cart.name.should == 'mock_cart_0'
|
68
68
|
end
|
@@ -74,7 +74,7 @@ module RHC
|
|
74
74
|
end
|
75
75
|
|
76
76
|
context "with a URL cart" do
|
77
|
-
before{ stub_api_request(:any, app_links['ADD_CARTRIDGE']['relative']).with(:body => {:url => 'http://foo.com'}.to_json).to_return(mock_cartridge_response(1, true)) }
|
77
|
+
before{ stub_api_request(:any, app_links['ADD_CARTRIDGE']['relative'], false).with(:body => {:url => 'http://foo.com'}.to_json).to_return(mock_cartridge_response(1, true)) }
|
78
78
|
it "raises without a param" do
|
79
79
|
app_obj.should_receive(:has_param?).with('ADD_CARTRIDGE','url').and_return(false)
|
80
80
|
expect{ app_obj.add_cartridge({:url => 'http://foo.com'}) }.to raise_error(RHC::Rest::DownloadingCartridgesNotSupported)
|
@@ -92,7 +92,7 @@ module RHC
|
|
92
92
|
end
|
93
93
|
it "accepts an object" do
|
94
94
|
app_obj.should_receive(:has_param?).with('ADD_CARTRIDGE','url').and_return(true)
|
95
|
-
cart = app_obj.add_cartridge(
|
95
|
+
cart = app_obj.add_cartridge(double(:url => 'http://foo.com'))
|
96
96
|
cart.should be_an_instance_of RHC::Rest::Cartridge
|
97
97
|
cart.name.should == 'mock_cart_0'
|
98
98
|
cart.url.should == 'http://a.url/0'
|
@@ -119,7 +119,7 @@ module RHC
|
|
119
119
|
context "when the server doesn't return aliases" do
|
120
120
|
let(:app_aliases){ nil }
|
121
121
|
context "when the client supports LIST_ALIASES" do
|
122
|
-
before{ stub_api_request(:any, app_links['LIST_ALIASES']['relative']).to_return(mock_alias_response(2)) }
|
122
|
+
before{ stub_api_request(:any, app_links['LIST_ALIASES']['relative'], false).to_return(mock_alias_response(2)) }
|
123
123
|
it{ app_obj.aliases.first.should be_an_instance_of RHC::Rest::Alias }
|
124
124
|
it{ app_obj.aliases.map(&:id).should == ['www.alias0.com', 'www.alias1.com'] }
|
125
125
|
end
|
@@ -132,8 +132,8 @@ module RHC
|
|
132
132
|
|
133
133
|
context "#cartridges" do
|
134
134
|
let(:num_carts){ 0 }
|
135
|
-
before
|
136
|
-
stub_api_request(:any, app_links['LIST_CARTRIDGES']['relative']).
|
135
|
+
before do
|
136
|
+
stub_api_request(:any, app_links['LIST_CARTRIDGES']['relative'], false).
|
137
137
|
to_return(mock_cartridge_response(num_carts))
|
138
138
|
end
|
139
139
|
context "with carts" do
|
@@ -170,8 +170,8 @@ module RHC
|
|
170
170
|
end
|
171
171
|
|
172
172
|
context "#gear_groups" do
|
173
|
-
before
|
174
|
-
stub_api_request(:any, app_links['GET_GEAR_GROUPS']['relative']).
|
173
|
+
before do
|
174
|
+
stub_api_request(:any, app_links['GET_GEAR_GROUPS']['relative'], false).
|
175
175
|
to_return(mock_gear_groups_response())
|
176
176
|
end
|
177
177
|
it "returns a list of all gear groups the current application" do
|
@@ -197,11 +197,11 @@ module RHC
|
|
197
197
|
@control_output = control_data.has_key?(:result) ? control_data[:result] : @control_event
|
198
198
|
@with_payload = control_data.has_key?(:payload) ? control_data[:payload] : true
|
199
199
|
if @with_payload
|
200
|
-
stub_api_request(:any, app_links[@control_link]['relative']).
|
200
|
+
stub_api_request(:any, app_links[@control_link]['relative'], false).
|
201
201
|
with(:body => { 'event' => @control_event }). # This is the critical part
|
202
202
|
to_return({ :body => { :data => @control_event }.to_json, :status => 200 })
|
203
203
|
else
|
204
|
-
stub_api_request(:any, app_links[@control_link]['relative']).
|
204
|
+
stub_api_request(:any, app_links[@control_link]['relative'], false).
|
205
205
|
to_return({ :body => { :data => @control_event }.to_json, :status => 200 })
|
206
206
|
end
|
207
207
|
end
|
@@ -43,6 +43,7 @@ module RHC
|
|
43
43
|
let(:app_0_links) { mock_response_links(mock_app_links('mock_domain_0', 'mock_app')) }
|
44
44
|
let(:user_links) { mock_response_links(mock_user_links) }
|
45
45
|
let(:key_links) { mock_response_links(mock_key_links) }
|
46
|
+
let(:api_links) { client_links }
|
46
47
|
|
47
48
|
context "#new" do
|
48
49
|
before do
|
@@ -78,9 +79,17 @@ module RHC
|
|
78
79
|
context "when server supports API versions [1.0, 1.1]" do
|
79
80
|
before :each do
|
80
81
|
stub_api_request(:get, '').
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
with(:headers => {'Accept' => 'application/json'}).
|
83
|
+
to_return({ :status => 200, :body => { :data => client_links, :version => '1.0', :supported_api_versions => [1.0, 1.1] }.to_json })
|
84
|
+
stub_api_request(:get, '').
|
85
|
+
with(:headers => {'Accept' => 'application/json;version=1.0'}).
|
86
|
+
to_return({ :status => 200, :body => { :data => client_links, :version => '1.0', :supported_api_versions => [1.0, 1.1] }.to_json })
|
87
|
+
stub_api_request(:get, '').
|
88
|
+
with(:headers => {'Accept' => 'application/json;version=1.1'}).
|
89
|
+
to_return({ :status => 200, :body => { :data => client_links, :version => '1.1', :supported_api_versions => [1.0, 1.1] }.to_json })
|
90
|
+
stub_api_request(:get, '').
|
91
|
+
with(:headers => {'Accept' => /application\/json;version=(1.2|1.3)/}).
|
92
|
+
to_raise(StandardError.new('Bad Version'))
|
84
93
|
stub_api_request(:get, 'api_error').
|
85
94
|
to_raise(HTTPClient::BadResponseError.new('API Error'))
|
86
95
|
stub_api_request(:get, 'other_error').
|
@@ -118,10 +127,10 @@ module RHC
|
|
118
127
|
end
|
119
128
|
|
120
129
|
context "with an instantiated client " do
|
121
|
-
before
|
130
|
+
before do
|
122
131
|
stub_api_request(:get, '').
|
123
132
|
to_return({ :body => {
|
124
|
-
:data =>
|
133
|
+
:data => api_links,
|
125
134
|
:supported_api_versions => [1.0, 1.1]
|
126
135
|
}.to_json,
|
127
136
|
:status => 200
|
@@ -130,7 +139,7 @@ module RHC
|
|
130
139
|
|
131
140
|
context "#add_domain" do
|
132
141
|
before do
|
133
|
-
stub_api_request(:any,
|
142
|
+
stub_api_request(:any, api_links['ADD_DOMAIN']['relative']).
|
134
143
|
to_return({ :body => {
|
135
144
|
:type => 'domain',
|
136
145
|
:supported_api_versions => [1.0, 1.1],
|
@@ -153,7 +162,7 @@ module RHC
|
|
153
162
|
|
154
163
|
context "#domains" do
|
155
164
|
before(:each) do
|
156
|
-
stub_api_request(:any,
|
165
|
+
stub_api_request(:any, api_links['LIST_DOMAINS']['relative']).
|
157
166
|
to_return({ :body => {
|
158
167
|
:type => 'domains',
|
159
168
|
:data =>
|
@@ -193,35 +202,105 @@ module RHC
|
|
193
202
|
end
|
194
203
|
|
195
204
|
context "#find_domain" do
|
196
|
-
|
197
|
-
|
205
|
+
context "when server does not support SHOW_DOMAIN" do
|
206
|
+
before do
|
207
|
+
stub_api_request(:any, api_links['LIST_DOMAINS']['relative']).
|
208
|
+
to_return({ :body => {
|
209
|
+
:type => 'domains',
|
210
|
+
:data =>
|
211
|
+
[{ :id => 'mock_domain_0',
|
212
|
+
:links => mock_response_links(mock_domain_links('mock_domain_0')),
|
213
|
+
},
|
214
|
+
{ :id => 'mock_domain_1',
|
215
|
+
:links => mock_response_links(mock_domain_links('mock_domain_1')),
|
216
|
+
}]
|
217
|
+
}.to_json,
|
218
|
+
:status => 200
|
219
|
+
})
|
220
|
+
end
|
221
|
+
it "returns a domain object for matching domain IDs" do
|
222
|
+
match = nil
|
223
|
+
expect { match = client.find_domain('mock_domain_0') }.to_not raise_error
|
224
|
+
match.id.should == 'mock_domain_0'
|
225
|
+
match.class.should == RHC::Rest::Domain
|
226
|
+
end
|
227
|
+
it "returns a domain object for matching case-insensitive domain IDs" do
|
228
|
+
match = nil
|
229
|
+
expect { match = client.find_domain('MOCK_DOMAIN_0') }.to_not raise_error
|
230
|
+
match.id.should == 'mock_domain_0'
|
231
|
+
match.class.should == RHC::Rest::Domain
|
232
|
+
end
|
233
|
+
it "raise an error when no matching domain IDs can be found" do
|
234
|
+
expect { client.find_domain('mock_domain_2') }.to raise_error(RHC::Rest::DomainNotFoundException)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "when server supports SHOW_DOMAIN" do
|
239
|
+
let(:api_links){ client_links.merge!(mock_response_links([['SHOW_DOMAIN', 'domains/:name', 'get']])) }
|
240
|
+
before do
|
241
|
+
stub_api_request(:any, api_links['SHOW_DOMAIN']['relative'].gsub(/:name/, 'mock_domain_0')).
|
242
|
+
to_return({ :body => {
|
243
|
+
:type => 'domain',
|
244
|
+
:data =>
|
245
|
+
{ :id => 'mock_domain_0',
|
246
|
+
:links => mock_response_links(mock_domain_links('mock_domain_0')),
|
247
|
+
}
|
248
|
+
}.to_json,
|
249
|
+
:status => 200
|
250
|
+
})
|
251
|
+
stub_api_request(:any, api_links['SHOW_DOMAIN']['relative'].gsub(/:name/, 'mock_domain_%^&')).
|
252
|
+
to_return({ :body => {
|
253
|
+
:type => 'domain',
|
254
|
+
:data =>
|
255
|
+
{ :id => 'mock_domain_%^&',
|
256
|
+
:links => mock_response_links(mock_domain_links('mock_domain_0')),
|
257
|
+
}
|
258
|
+
}.to_json,
|
259
|
+
:status => 200
|
260
|
+
})
|
261
|
+
stub_api_request(:any, api_links['SHOW_DOMAIN']['relative'].gsub(/:name/, 'mock_domain_2')).
|
262
|
+
to_return({ :body => {:messages => [{:exit_code => 127}]}.to_json,
|
263
|
+
:status => 404
|
264
|
+
})
|
265
|
+
end
|
266
|
+
it "returns a domain object for matching domain IDs" do
|
267
|
+
match = nil
|
268
|
+
expect { match = client.find_domain('mock_domain_0') }.to_not raise_error
|
269
|
+
match.id.should == 'mock_domain_0'
|
270
|
+
match.class.should == RHC::Rest::Domain
|
271
|
+
end
|
272
|
+
it "encodes special characters" do
|
273
|
+
match = nil
|
274
|
+
expect { match = client.find_domain('mock_domain_%^&') }.to_not raise_error
|
275
|
+
match.id.should == 'mock_domain_%^&'
|
276
|
+
match.class.should == RHC::Rest::Domain
|
277
|
+
end
|
278
|
+
it "raise an error when no matching domain IDs can be found" do
|
279
|
+
expect { client.find_domain('mock_domain_2') }.to raise_error(RHC::Rest::DomainNotFoundException)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context "when server supports LIST_DOMAINS_BY_OWNER" do
|
285
|
+
let(:api_links){ client_links.merge!(mock_response_links([['LIST_DOMAINS_BY_OWNER', 'domains', 'get']])) }
|
286
|
+
before do
|
287
|
+
stub_api_request(:any, "#{api_links['LIST_DOMAINS_BY_OWNER']['relative']}?owner=@self").
|
198
288
|
to_return({ :body => {
|
199
289
|
:type => 'domains',
|
200
|
-
:data =>
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
{ :id => 'mock_domain_1',
|
205
|
-
:links => mock_response_links(mock_domain_links('mock_domain_1')),
|
206
|
-
}]
|
290
|
+
:data => [{
|
291
|
+
:id => 'mock_domain_0',
|
292
|
+
:links => mock_response_links(mock_domain_links('mock_domain_0')),
|
293
|
+
}]
|
207
294
|
}.to_json,
|
208
295
|
:status => 200
|
209
296
|
})
|
210
297
|
end
|
211
|
-
it "returns
|
298
|
+
it "returns owned domains when called" do
|
212
299
|
match = nil
|
213
|
-
expect { match = client.
|
214
|
-
match.
|
215
|
-
match.
|
216
|
-
|
217
|
-
it "returns a domain object for matching case-insensitive domain IDs" do
|
218
|
-
match = nil
|
219
|
-
expect { match = client.find_domain('MOCK_DOMAIN_0') }.to_not raise_error
|
220
|
-
match.id.should == 'mock_domain_0'
|
221
|
-
match.class.should == RHC::Rest::Domain
|
222
|
-
end
|
223
|
-
it "raise an error when no matching domain IDs can be found" do
|
224
|
-
expect { client.find_domain('mock_domain_2') }.to raise_error(RHC::Rest::DomainNotFoundException)
|
300
|
+
expect { match = client.owned_domains }.to_not raise_error
|
301
|
+
match.length.should == 1
|
302
|
+
match.first.id.should == 'mock_domain_0'
|
303
|
+
match.first.class.should == RHC::Rest::Domain
|
225
304
|
end
|
226
305
|
end
|
227
306
|
|
@@ -295,7 +374,7 @@ module RHC
|
|
295
374
|
|
296
375
|
context "#cartridges" do
|
297
376
|
before(:each) do
|
298
|
-
stub_api_request(:any,
|
377
|
+
stub_api_request(:any, api_links['LIST_CARTRIDGES']['relative']).
|
299
378
|
to_return({ :body => {
|
300
379
|
:type => 'cartridges',
|
301
380
|
:data =>
|
@@ -339,7 +418,7 @@ module RHC
|
|
339
418
|
|
340
419
|
context "#find_cartridges" do
|
341
420
|
before(:each) do
|
342
|
-
stub_api_request(:any,
|
421
|
+
stub_api_request(:any, api_links['LIST_CARTRIDGES']['relative']).
|
343
422
|
to_return({ :body => {
|
344
423
|
:type => 'cartridges',
|
345
424
|
:data =>
|
@@ -381,7 +460,7 @@ module RHC
|
|
381
460
|
|
382
461
|
context "#user" do
|
383
462
|
before(:each) do
|
384
|
-
stub_api_request(:any,
|
463
|
+
stub_api_request(:any, api_links['GET_USER']['relative']).
|
385
464
|
to_return({ :body => {
|
386
465
|
:type => 'user',
|
387
466
|
:data =>
|
@@ -402,7 +481,7 @@ module RHC
|
|
402
481
|
|
403
482
|
context "#find_key" do
|
404
483
|
before(:each) do
|
405
|
-
stub_api_request(:any,
|
484
|
+
stub_api_request(:any, api_links['GET_USER']['relative']).
|
406
485
|
to_return({ :body => {
|
407
486
|
:type => 'user',
|
408
487
|
:data =>
|
@@ -448,7 +527,7 @@ module RHC
|
|
448
527
|
|
449
528
|
context "#delete_key" do
|
450
529
|
before(:each) do
|
451
|
-
stub_api_request(:any,
|
530
|
+
stub_api_request(:any, api_links['GET_USER']['relative']).
|
452
531
|
to_return({ :body => {
|
453
532
|
:type => 'user',
|
454
533
|
:data =>
|
@@ -496,7 +575,7 @@ module RHC
|
|
496
575
|
before :each do
|
497
576
|
stub_api_request(:get, '').
|
498
577
|
to_return({ :body => {
|
499
|
-
:data =>
|
578
|
+
:data => api_links,
|
500
579
|
:supported_api_versions => [1.0, 1.1]
|
501
580
|
}.to_json,
|
502
581
|
:status => 200
|
@@ -538,7 +617,7 @@ module RHC
|
|
538
617
|
end
|
539
618
|
|
540
619
|
describe "#supports_sessions?" do
|
541
|
-
before{ subject.should_receive(:api).at_least(2).times.and_return(
|
620
|
+
before{ subject.should_receive(:api).at_least(2).times.and_return(double) }
|
542
621
|
context "with ADD_AUTHORIZATION link" do
|
543
622
|
before{ subject.api.should_receive(:supports?).with('ADD_AUTHORIZATION').and_return(true) }
|
544
623
|
its(:supports_sessions?){ should be_true }
|
@@ -566,3 +645,36 @@ module RHC
|
|
566
645
|
end
|
567
646
|
end
|
568
647
|
end
|
648
|
+
|
649
|
+
module RHC
|
650
|
+
module Rest
|
651
|
+
describe HTTPClient do
|
652
|
+
end
|
653
|
+
|
654
|
+
describe WWWAuth::DeferredCredential do
|
655
|
+
subject{ described_class.new(nil, nil) }
|
656
|
+
its(:user){ should be_nil }
|
657
|
+
its(:passwd){ should be_nil }
|
658
|
+
|
659
|
+
context "with a username and password" do
|
660
|
+
subject{ described_class.new(username, password) }
|
661
|
+
let(:username){ 'a_user' }
|
662
|
+
let(:password){ 'a_password' }
|
663
|
+
|
664
|
+
its(:user){ should == username }
|
665
|
+
its(:passwd){ should == password }
|
666
|
+
its(:to_str){ should == ["#{username}:#{password}"].pack('m').tr("\n", '') }
|
667
|
+
end
|
668
|
+
|
669
|
+
context "with a deferred username and password" do
|
670
|
+
subject{ described_class.new(username, password) }
|
671
|
+
let(:username){ lambda{ 'a_user' } }
|
672
|
+
let(:password){ lambda{ 'a_password' } }
|
673
|
+
|
674
|
+
its(:user){ should == username.call }
|
675
|
+
its(:passwd){ should == password.call }
|
676
|
+
its(:to_str){ should == ["#{username.call}:#{password.call}"].pack('m').tr("\n", '') }
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end
|
data/spec/rhc/rest_spec.rb
CHANGED
@@ -95,12 +95,12 @@ module RHC
|
|
95
95
|
it{ expect{ invoked_with(false, nil) }.to raise_error(NoMethodError) }
|
96
96
|
|
97
97
|
context "with a self signed cert" do
|
98
|
-
it{ invoked_with(false,
|
98
|
+
it{ invoked_with(false, double(:current_cert => double(:issuer => '1', :subject => double(:cmp => 0)))).should be_false }
|
99
99
|
after{ subject.send(:self_signed?).should be_true }
|
100
100
|
end
|
101
101
|
|
102
102
|
context "with an intermediate signed cert" do
|
103
|
-
it{ invoked_with(false,
|
103
|
+
it{ invoked_with(false, double(:current_cert => double(:issuer => '2', :subject => double(:cmp => 1)), :error => 1, :error_string => 'a')).should be_false }
|
104
104
|
after{ subject.send(:self_signed?).should be_false }
|
105
105
|
end
|
106
106
|
|
@@ -519,7 +519,7 @@ module RHC
|
|
519
519
|
let(:url){ "http://fake.url" }
|
520
520
|
let(:proxy){ nil }
|
521
521
|
def response
|
522
|
-
|
522
|
+
double(:status => code, :content => json ? RHC::Json.encode(json) : body)
|
523
523
|
end
|
524
524
|
let(:method) { lambda{ subject.send(:handle_error!, response, url, client) } }
|
525
525
|
|
data/spec/rhc/wizard_spec.rb
CHANGED
@@ -103,9 +103,9 @@ describe RHC::Wizard do
|
|
103
103
|
describe "#login_stage" do
|
104
104
|
let(:user){ 'test_user' }
|
105
105
|
let(:password){ 'test pass' }
|
106
|
-
let(:rest_client){
|
106
|
+
let(:rest_client){ double }
|
107
107
|
let(:auth){ subject.send(:auth) }
|
108
|
-
let(:user_obj){
|
108
|
+
let(:user_obj){ double(:login => user) }
|
109
109
|
|
110
110
|
subject{ described_class.new(config, options) }
|
111
111
|
|
@@ -185,8 +185,8 @@ describe RHC::Wizard do
|
|
185
185
|
|
186
186
|
context "when the config has enabled tokens" do
|
187
187
|
let(:default_options){ {:rhlogin => user, :password => password, :server => server, :use_authorization_tokens => true} }
|
188
|
-
let(:store){
|
189
|
-
before{ RHC::Auth::TokenStore.
|
188
|
+
let(:store){ double }
|
189
|
+
before{ RHC::Auth::TokenStore.stub(:new).and_return(store) }
|
190
190
|
before{ expect_client_test(true) }
|
191
191
|
|
192
192
|
it "should check for an existing token" do
|
@@ -203,9 +203,9 @@ describe RHC::Wizard do
|
|
203
203
|
context "with a server that supports tokens" do
|
204
204
|
before{ expect_client_test(true) }
|
205
205
|
let(:token){ 'a_test_value' }
|
206
|
-
let(:auth_token){
|
207
|
-
let(:store){
|
208
|
-
before{ RHC::Auth::TokenStore.
|
206
|
+
let(:auth_token){ double(:token => token, :expires_in_seconds => 100) }
|
207
|
+
let(:store){ double }
|
208
|
+
before{ RHC::Auth::TokenStore.stub(:new).and_return(store) }
|
209
209
|
|
210
210
|
it "should not generate a token if the user does not request it" do
|
211
211
|
store.should_not_receive(:get)
|
@@ -273,11 +273,11 @@ describe RHC::Wizard do
|
|
273
273
|
|
274
274
|
context "with no settings" do
|
275
275
|
before do
|
276
|
-
stub_api
|
277
|
-
stub_user
|
276
|
+
stub_api(false)
|
277
|
+
challenge{ stub_user }
|
278
278
|
stub_no_keys
|
279
|
-
stub_no_domains
|
280
|
-
stub_simple_carts
|
279
|
+
challenge{ stub_no_domains }
|
280
|
+
stub_simple_carts(false)
|
281
281
|
end
|
282
282
|
|
283
283
|
it "should execute the minimal path" do
|
@@ -415,8 +415,8 @@ describe RHC::Wizard do
|
|
415
415
|
subject{ RHC::RerunWizard.new(config, options) }
|
416
416
|
|
417
417
|
before do
|
418
|
-
stub_api
|
419
|
-
stub_user
|
418
|
+
stub_api false
|
419
|
+
challenge{ stub_user }
|
420
420
|
stub_no_keys
|
421
421
|
stub_add_key
|
422
422
|
stub_api_request(:post, 'broker/rest/domains', user_auth).
|
@@ -427,7 +427,7 @@ describe RHC::Wizard do
|
|
427
427
|
:messages => [{:field => 'id', :severity => 'ERROR', :text => 'Too long', :exit_code => 123}]
|
428
428
|
}.to_json
|
429
429
|
})
|
430
|
-
stub_one_domain('testnamespace')
|
430
|
+
challenge{ stub_one_domain('testnamespace') }
|
431
431
|
stub_one_application('testnamespace', 'test1')
|
432
432
|
stub_simple_carts
|
433
433
|
end
|
@@ -464,8 +464,8 @@ describe RHC::Wizard do
|
|
464
464
|
subject{ RHC::SSHWizard.new(rest_client, config, options) }
|
465
465
|
|
466
466
|
before do
|
467
|
-
stub_api
|
468
|
-
stub_user
|
467
|
+
stub_api false
|
468
|
+
challenge{ stub_user }
|
469
469
|
end
|
470
470
|
|
471
471
|
context "with no server keys" do
|
@@ -517,7 +517,7 @@ describe RHC::Wizard do
|
|
517
517
|
it "should cause upload_ssh_key to catch NoMethodError and call the fallback to get the fingerprint" do
|
518
518
|
Net::SSH::KeyFactory.should_receive(:load_public_key).exactly(5).times.and_raise(NoMethodError)
|
519
519
|
wizard.stub(:ssh_keys).at_least(1).times.and_return(wizard.get_mock_key_data)
|
520
|
-
wizard.should_receive(:ssh_keygen_fallback).exactly(5).times.and_return(
|
520
|
+
wizard.should_receive(:ssh_keygen_fallback).exactly(5).times.and_return(double(:name => 'default', :fingerprint => 'AA:BB:CC:DD:EE:FF', :type => 'ssh-rsa' ))
|
521
521
|
|
522
522
|
input_line 'y'
|
523
523
|
|
@@ -580,7 +580,7 @@ describe RHC::Wizard do
|
|
580
580
|
wizard.ssh_keys = key_data
|
581
581
|
wizard.stub(:ssh_key_triple_for_default_key) { pub_key.chomp.split }
|
582
582
|
wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
|
583
|
-
wizard.rest_client =
|
583
|
+
wizard.rest_client = double('RestClient').tap{ |o| o.stub(:find_key) { key_data.detect { |k| k.name == key_name } } }
|
584
584
|
|
585
585
|
wizard.send(:upload_ssh_key, key_name)
|
586
586
|
output = last_output
|
@@ -596,7 +596,7 @@ describe RHC::Wizard do
|
|
596
596
|
wizard.ssh_keys = key_data
|
597
597
|
wizard.stub(:ssh_key_triple_for_default_key) { pub_key.chomp.split }
|
598
598
|
wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
|
599
|
-
wizard.rest_client =
|
599
|
+
wizard.rest_client = double('RestClient').tap{ |o| o.stub(:add_key) { true } }
|
600
600
|
|
601
601
|
wizard.send(:upload_ssh_key, "other")
|
602
602
|
output = last_output
|
@@ -748,7 +748,7 @@ end
|
|
748
748
|
|
749
749
|
describe RHC::DomainWizard do
|
750
750
|
context "with a rest client" do
|
751
|
-
let(:rest_client){
|
751
|
+
let(:rest_client){ double }
|
752
752
|
it{ described_class.new(nil, nil, rest_client).rest_client.should == rest_client }
|
753
753
|
it{ subject.stages == [:config_namespace_stage] }
|
754
754
|
it{ expect{ described_class.new(nil, nil, rest_client).send(:config_namespace, '') }.to call(:add_domain).on(rest_client).and_stop }
|