rhc 1.2.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/bin/rhc +6 -8
  2. data/bin/rhc-chk +23 -10
  3. data/features/domain.feature +1 -1
  4. data/features/lib/rhc_helper.rb +3 -2
  5. data/features/lib/rhc_helper/api.rb +7 -0
  6. data/features/lib/rhc_helper/app.rb +8 -10
  7. data/features/lib/rhc_helper/domain.rb +2 -1
  8. data/features/lib/rhc_helper/runnable.rb +2 -24
  9. data/features/sshkey.feature +3 -3
  10. data/features/step_definitions/cartridge_steps.rb +6 -6
  11. data/features/step_definitions/client_steps.rb +0 -1
  12. data/features/step_definitions/sshkey_steps.rb +2 -2
  13. data/features/support/before_hooks.rb +0 -1
  14. data/features/support/env.rb +5 -3
  15. data/lib/rhc-common.rb +1 -1
  16. data/lib/rhc.rb +9 -8
  17. data/lib/rhc/auth.rb +3 -0
  18. data/lib/rhc/auth/basic.rb +54 -0
  19. data/lib/rhc/cartridge_helpers.rb +11 -5
  20. data/lib/rhc/cli.rb +4 -2
  21. data/lib/rhc/command_runner.rb +35 -30
  22. data/lib/rhc/commands.rb +127 -18
  23. data/lib/rhc/commands/account.rb +24 -0
  24. data/lib/rhc/commands/alias.rb +1 -1
  25. data/lib/rhc/commands/app.rb +210 -209
  26. data/lib/rhc/commands/apps.rb +22 -0
  27. data/lib/rhc/commands/base.rb +10 -77
  28. data/lib/rhc/commands/cartridge.rb +35 -35
  29. data/lib/rhc/commands/domain.rb +20 -13
  30. data/lib/rhc/commands/git_clone.rb +30 -0
  31. data/lib/rhc/commands/{port-forward.rb → port_forward.rb} +3 -3
  32. data/lib/rhc/commands/server.rb +28 -16
  33. data/lib/rhc/commands/setup.rb +18 -1
  34. data/lib/rhc/commands/snapshot.rb +4 -4
  35. data/lib/rhc/commands/sshkey.rb +4 -18
  36. data/lib/rhc/commands/tail.rb +32 -9
  37. data/lib/rhc/config.rb +168 -99
  38. data/lib/rhc/context_helper.rb +22 -9
  39. data/lib/rhc/core_ext.rb +41 -1
  40. data/lib/rhc/exceptions.rb +21 -5
  41. data/lib/rhc/git_helpers.rb +81 -0
  42. data/lib/rhc/help_formatter.rb +21 -1
  43. data/lib/rhc/helpers.rb +222 -87
  44. data/lib/rhc/output_helpers.rb +94 -110
  45. data/lib/rhc/rest.rb +15 -198
  46. data/lib/rhc/rest/api.rb +88 -0
  47. data/lib/rhc/rest/application.rb +29 -30
  48. data/lib/rhc/rest/attributes.rb +27 -0
  49. data/lib/rhc/rest/base.rb +29 -33
  50. data/lib/rhc/rest/cartridge.rb +42 -20
  51. data/lib/rhc/rest/client.rb +351 -89
  52. data/lib/rhc/rest/domain.rb +7 -13
  53. data/lib/rhc/rest/gear_group.rb +1 -1
  54. data/lib/rhc/rest/key.rb +7 -2
  55. data/lib/rhc/rest/mock.rb +609 -0
  56. data/lib/rhc/rest/user.rb +6 -2
  57. data/lib/rhc/{ssh_key_helpers.rb → ssh_helpers.rb} +58 -28
  58. data/lib/rhc/{targz.rb → tar_gz.rb} +0 -0
  59. data/lib/rhc/usage_templates/command_help.erb +4 -1
  60. data/lib/rhc/usage_templates/help.erb +24 -11
  61. data/lib/rhc/usage_templates/options_help.erb +14 -0
  62. data/lib/rhc/wizard.rb +283 -213
  63. data/spec/keys/example.pem +23 -0
  64. data/spec/keys/example_private.pem +27 -0
  65. data/spec/keys/server.pem +19 -0
  66. data/spec/rest_spec_helper.rb +3 -371
  67. data/spec/rhc/auth_spec.rb +226 -0
  68. data/spec/rhc/cli_spec.rb +41 -14
  69. data/spec/rhc/command_spec.rb +44 -15
  70. data/spec/rhc/commands/account_spec.rb +41 -0
  71. data/spec/rhc/commands/alias_spec.rb +16 -15
  72. data/spec/rhc/commands/app_spec.rb +115 -92
  73. data/spec/rhc/commands/apps_spec.rb +39 -0
  74. data/spec/rhc/commands/cartridge_spec.rb +134 -112
  75. data/spec/rhc/commands/domain_spec.rb +31 -86
  76. data/spec/rhc/commands/git_clone_spec.rb +56 -0
  77. data/spec/rhc/commands/{port-forward_spec.rb → port_forward_spec.rb} +27 -32
  78. data/spec/rhc/commands/server_spec.rb +28 -3
  79. data/spec/rhc/commands/setup_spec.rb +29 -11
  80. data/spec/rhc/commands/snapshot_spec.rb +4 -3
  81. data/spec/rhc/commands/sshkey_spec.rb +24 -56
  82. data/spec/rhc/commands/tail_spec.rb +26 -9
  83. data/spec/rhc/commands/threaddump_spec.rb +12 -11
  84. data/spec/rhc/config_spec.rb +211 -164
  85. data/spec/rhc/context_spec.rb +2 -0
  86. data/spec/rhc/helpers_spec.rb +242 -46
  87. data/spec/rhc/rest_application_spec.rb +42 -28
  88. data/spec/rhc/rest_client_spec.rb +110 -93
  89. data/spec/rhc/rest_spec.rb +220 -131
  90. data/spec/rhc/targz_spec.rb +1 -1
  91. data/spec/rhc/wizard_spec.rb +435 -624
  92. data/spec/spec.opts +1 -1
  93. data/spec/spec_helper.rb +140 -6
  94. data/spec/wizard_spec_helper.rb +326 -0
  95. metadata +163 -143
  96. data/lib/rhc/client.rb +0 -17
  97. data/lib/rhc/git_helper.rb +0 -59
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'rhc/targz'
2
+ require 'rhc/tar_gz'
3
3
 
4
4
  describe RHC::TarGz do
5
5
 
@@ -5,651 +5,502 @@ require 'rhc/vendor/parseconfig'
5
5
  require 'rhc/config'
6
6
  require 'ostruct'
7
7
  require 'rest_spec_helper'
8
+ require 'wizard_spec_helper'
9
+ require 'tmpdir'
10
+
11
+ # Allow to define the id method
12
+ OpenStruct.__send__(:define_method, :id) { @table[:id] } if RUBY_VERSION.to_f == 1.8
8
13
 
9
14
  describe RHC::Wizard do
10
- before(:all) do
11
- mock_terminal
12
- RHC::Config.set_defaults
13
- FakeFS.activate!
14
- FakeFS::FileSystem.clear
15
- end
16
15
 
17
- after(:all) do
18
- FakeFS.deactivate!
16
+ def mock_config
17
+ RHC::Config.stub(:home_dir).and_return('/home/mock_user')
19
18
  end
20
19
 
21
- context "First run of rhc" do
22
- before(:all) do
23
- @wizard = FirstRunWizardDriver.new
24
- end
25
-
26
- it "should print out first run greeting" do
27
- @wizard.run_next_stage
28
- greeting = $terminal.read
29
- greeting.count("\n").should >= 3
30
- greeting.should match(/OpenShift Client Tools \(RHC\) Setup Wizard/)
31
- end
32
-
33
- it "should ask for login and hide password input" do
34
- @wizard.stub_rhc_client_new
35
- # queue up input
36
- $terminal.write_line "#{@wizard.mock_user}"
37
- $terminal.write_line "password"
38
-
39
-
40
- @wizard.run_next_stage
41
-
42
- output = $terminal.read
43
- output.should match("Login to ")
44
- output.should match(/Password: [\*]{8}$/)
45
- end
46
-
47
- it "should write out a config" do
48
- File.exists?(@wizard.config_path).should be false
49
- @wizard.run_next_stage
50
- File.readable?(@wizard.config_path).should be true
51
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
52
- cp["default_rhlogin"].should == @wizard.mock_user
53
- cp["libra_server"].should == @wizard.libra_server
54
- end
55
-
56
- it "should write out generated ssh keys" do
57
- @wizard.setup_mock_ssh
58
- private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
59
- public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
60
- File.exists?(private_key_file).should be false
61
- File.exists?(public_key_file).should be false
62
- @wizard.run_next_stage
63
- File.exists?(private_key_file).should be true
64
- File.exists?(public_key_file).should be true
65
- end
66
-
67
- it "should ask to upload ssh keys" do
68
- @rest_client.stub(:get_ssh_keys) { @wizard.get_mock_key_data }
69
- $terminal.write_line('yes')
70
- @wizard.stub_rhc_client_new
71
- @wizard.ssh_keys = []
72
- @wizard.run_next_stage
73
- end
74
-
75
- it "should check for client tools" do
76
- @wizard.setup_mock_has_git(true)
77
- @wizard.run_next_stage
78
- output = $terminal.read
79
- output.should match("Checking for git \.\.\. found")
80
- end
81
-
82
- it "should ask for a namespace" do
83
- $terminal.write_line("thisnamespaceistoobigandhastoomanycharacterstobevalid")
84
-
85
- $terminal.write_line("invalidnamespace")
86
- $terminal.write_line("testnamespace")
87
- @wizard.run_next_stage
88
- output = $terminal.read
89
- output.should match("Checking for your namespace \.\.\. not found")
90
- end
91
-
92
- it "should show app creation commands" do
93
- @wizard.run_next_stage
94
- output = $terminal.read
95
- output.should match 'Below is a list of'
96
- end
20
+ let(:options){ (o = Commander::Command::Options.new).default(default_options); o }
21
+ let(:config){ RHC::Config.new.tap{ |c| c.stub(:home_dir).and_return('/home/mock_user') } }
22
+ let(:default_options){ {} }
97
23
 
98
- it "should show a thank you message" do
99
- @wizard.run_next_stage
100
- output = $terminal.read
101
- output.should match("The OpenShift client tools have been configured on your computer")
102
- end
24
+ describe "#finalize_stage" do
25
+ subject{ RHC::Wizard.new(config, options) }
26
+ before{ subject.should_receive(:say).with(/The OpenShift client tools have been configured/) }
27
+ it{ subject.send(:finalize_stage).should be_true }
103
28
  end
104
29
 
105
- context "Repeat run of rhc setup without anything set" do
106
- before(:all) do
107
- @wizard = RerunWizardDriver.new
108
- end
109
-
110
- it "should print out repeat run greeting" do
111
- @wizard.run_next_stage
112
- greeting = $terminal.read
113
- greeting.should match(/OpenShift Client Tools \(RHC\) Setup Wizard/)
114
- end
115
-
116
- it "should ask for login and hide password input" do
117
- @wizard.stub_rhc_client_new
118
- $terminal.write_line "#{@wizard.mock_user}"
119
- $terminal.write_line "password"
120
-
121
- @wizard.run_next_stage
122
-
123
- output = $terminal.read
124
- output.should match("Login to ")
125
- output.should match(/Password: [\*]{8}$/)
126
- end
127
-
128
- it "should write out a config" do
129
- File.exists?(@wizard.config_path).should be false
130
- @wizard.run_next_stage
131
- File.readable?(@wizard.config_path).should be true
132
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
133
- cp["default_rhlogin"].should == @wizard.mock_user
134
- cp["libra_server"].should == @wizard.libra_server
135
- end
136
-
137
- it "should write out generated ssh keys" do
138
- @wizard.setup_mock_ssh
139
- private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
140
- public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
141
- File.exists?(private_key_file).should be false
142
- File.exists?(public_key_file).should be false
143
- @wizard.run_next_stage
144
- File.exists?(private_key_file).should be true
145
- File.exists?(public_key_file).should be true
146
- end
147
-
148
- it "should upload ssh key as default" do
149
- @rest_client.stub(:sshkeys) {[]}
150
- @wizard.stub(:get_preferred_key_name) { 'default' }
151
- $terminal.write_line('yes')
152
- @wizard.run_next_stage
153
- end
154
-
155
- it "should check for client tools and print they need to be installed" do
156
- @wizard.setup_mock_has_git(false)
157
- @wizard.run_next_stage
158
- output = $terminal.read
159
- output.should match("Checking for git \.\.\. needs to be installed")
160
- output.should match("Automated installation of client tools is not supported for your platform")
161
- end
162
-
163
- it "should ask for a namespace" do
164
- $terminal.write_line("testnamespace")
165
- @wizard.run_next_stage
166
- output = $terminal.read
167
- output.should match("Checking for your namespace \.\.\. not found")
168
- end
169
-
170
- it "should show app creation commands" do
171
- @wizard.run_next_stage
172
- output = $terminal.read
173
- output.should match 'Below is a list of'
174
- end
175
-
176
- it "should show a thank you message" do
177
- @wizard.run_next_stage
178
- output = $terminal.read
179
- output.should match("Thank you")
180
- end
181
- end
182
-
183
- context "Repeat run of rhc setup with config set" do
184
- before(:all) do
185
- RHC::Config.set_defaults
186
- @wizard = RerunWizardDriver.new
187
- @wizard.setup_mock_config
188
- @wizard.run_next_stage # we can skip testing the greeting
189
- end
190
-
191
- it "should ask for password input with default login" do
192
- @wizard.stub_rhc_client_new
193
-
194
- $terminal.write_line("") # hit enter for default
195
- $terminal.write_line "password"
196
-
197
- @wizard.run_next_stage
198
-
199
- output = $terminal.read
200
- output.should match("|#{@wizard.mock_user}|")
201
- end
202
-
203
- it "should write out a config" do
204
- File.exists?(@wizard.config_path).should be true
205
- @wizard.run_next_stage
206
- File.readable?(@wizard.config_path).should be true
207
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
208
- cp["default_rhlogin"].should == @wizard.mock_user
209
- cp["libra_server"].should == @wizard.libra_server
210
- end
211
-
212
- it "should write out generated ssh keys" do
213
- @wizard.setup_mock_ssh
214
- private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
215
- public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
216
- File.exists?(private_key_file).should be false
217
- File.exists?(public_key_file).should be false
218
- @wizard.run_next_stage
219
- File.exists?(private_key_file).should be true
220
- File.exists?(public_key_file).should be true
221
- end
222
-
223
- it "should find out that you have not uploaded the default key and ask to name the key" do
224
- key_data = @wizard.get_mock_key_data
225
- @wizard.ssh_keys = key_data
226
- key_name = '73ce2cc1'
227
-
228
- fingerprint, short_name = @wizard.get_key_fingerprint
229
- @wizard.rest_client.stub(:find_key) { key_data.detect{|k| k.name == key_name} }
230
- $terminal.write_line('yes')
231
- $terminal.write_line(key_name) # answering with an existing key name
232
- @wizard.run_next_stage
233
- output = $terminal.read
234
- key_data.each do |key|
235
- output.should match("Name: #{key.name}")
236
- output.should match("Fingerprint: #{key.fingerprint}")
30
+ describe "#test_ssh_connectivity" do
31
+ subject{ RHC::Wizard.new(config, options) }
32
+ let(:app) do
33
+ app = Object.new
34
+ app.should_receive(:host).at_least(1).and_return('foo.com')
35
+ app.should_receive(:uuid).at_least(1).and_return('uuid')
36
+ app
37
+ end
38
+ let(:ssh) do
39
+ ssh = Object.new
40
+ ssh.should_receive(:close)
41
+ ssh
42
+ end
43
+
44
+ it "should not attempt an SSH connection" do
45
+ subject.should_receive(:ssh_key_uploaded?).and_return(true)
46
+ subject.should_receive(:applications).and_return([])
47
+ subject.send(:test_ssh_connectivity).should be_true
48
+ end
49
+ it "should attempt an SSH connection to the first app" do
50
+ subject.should_receive(:ssh_key_uploaded?).and_return(true)
51
+ subject.should_receive(:applications).and_return([app])
52
+ Net::SSH.should_receive(:start).with(app.host, app.uuid, {:timeout => 60}).and_return(ssh)
53
+ subject.send(:test_ssh_connectivity).should be_true
54
+ end
55
+ it "should handle a failed connection" do
56
+ subject.should_receive(:ssh_key_uploaded?).and_return(true)
57
+ subject.should_receive(:applications).and_return([app])
58
+ Net::SSH.should_receive(:start).and_raise(StandardError.new('an_error'))
59
+ subject.should_receive(:report_result) do |ssh, msg|
60
+ ssh.should be_nil
61
+ msg.should match('An SSH connection could not be established')
62
+ msg.should match('an_error')
237
63
  end
238
- output.should match("|#{short_name}|") # prompt with the default name
239
- end
240
-
241
- it "should check for client tools and find them" do
242
- @wizard.setup_mock_has_git(true)
243
- @wizard.run_next_stage
244
- output = $terminal.read
245
- output.should match("Checking for git \.\.\. found")
246
- end
247
-
248
- it "should ask for a namespace" do
249
- $terminal.write_line("testnamespace")
250
- @wizard.run_next_stage
251
- output = $terminal.read
252
- output.should match("Checking for your namespace \.\.\. not found")
253
- end
254
-
255
- it "should show app creation commands" do
256
- @wizard.run_next_stage
257
- output = $terminal.read
258
- output.should match 'Below is a list of'
259
- end
260
-
261
- it "should show a thank you message" do
262
- @wizard.run_next_stage
263
- output = $terminal.read
264
- output.should match("Thank you")
64
+ subject.send(:test_ssh_connectivity).should be_false
265
65
  end
266
66
  end
267
67
 
268
- context "Repeat run of rhc setup with config and ssh keys set" do
269
-
270
- before(:all) do
271
- @wizard = RerunWizardDriver.new
272
- @wizard.setup_mock_config
273
- @wizard.setup_mock_ssh(true)
274
- @wizard.run_next_stage # we can skip testing the greeting
275
- end
276
-
277
- it "should ask for password input with default login" do
278
- @wizard.stub_rhc_client_new
279
-
280
- $terminal.write_line("") # hit enter for default
281
- $terminal.write_line "password"
68
+ describe "#login_stage" do
69
+ let(:user){ 'test_user' }
70
+ let(:password){ 'test pass' }
71
+ let(:rest_client){ stub }
72
+ let(:auth){ subject.send(:auth) }
282
73
 
283
- @wizard.run_next_stage
74
+ subject{ RHC::Wizard.new(config, options) }
284
75
 
285
- output = $terminal.read
286
- output.should match("|#{@wizard.mock_user}|")
76
+ def expect_client_test
77
+ subject.should_receive(:new_client_for_options).ordered.and_return(rest_client)
78
+ rest_client.should_receive(:api).ordered
79
+ rest_client.should_receive(:user).ordered.and_return(true)
287
80
  end
288
-
289
- it "should write out a config" do
290
- File.exists?(@wizard.config_path).should be true
291
- @wizard.run_next_stage
292
- File.readable?(@wizard.config_path).should be true
293
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
294
- cp["default_rhlogin"].should == @wizard.mock_user
295
- cp["libra_server"].should == @wizard.libra_server
81
+ def expect_raise_from_api(error)
82
+ #subject.send(:auth).should_receive(:ask).with("Using #{user} to login to openshift.redhat.com").and_return(username).ordered
83
+ #subject.send(:auth).should_receive(:ask).with("Password: ").and_return(password).ordered
84
+ subject.should_receive(:new_client_for_options).ordered.and_return(rest_client)
85
+ rest_client.should_receive(:api).ordered.and_raise(error)
296
86
  end
297
87
 
298
- it "should check for ssh keys and find a match" do
299
- @wizard.stub(:ssh_key_uploaded?) { true } # an SSH key already exists
300
- @wizard.run_next_stage # key config is pretty much a noop here
301
-
302
- # run the key check stage
303
- @wizard.run_next_stage
88
+ it "should prompt for user and password" do
89
+ #auth.should_receive(:ask).with("Login to openshift.redhat.com: ").ordered.and_return(user)
90
+ #auth.should_receive(:ask).with("Password: ").ordered.and_return(password)
91
+ expect_client_test
304
92
 
305
- output = $terminal.read
306
- output.should_not match("ssh key must be uploaded")
93
+ subject.send(:login_stage).should be_true
307
94
  end
308
95
 
309
- it "should check for client tools and find them" do
310
- @wizard.setup_mock_has_git(true)
311
- @wizard.run_next_stage
312
- output = $terminal.read
313
- output.should match("Checking for git \.\.\. found")
314
- end
315
-
316
- it "should ask for a namespace" do
317
- $terminal.write_line("testnamespace")
318
- @wizard.run_next_stage
319
- output = $terminal.read
320
- output.should match("Checking for your namespace \.\.\. not found")
321
- end
96
+ context "with credentials" do
97
+ let(:default_options){ {:rhlogin => user, :password => password} }
322
98
 
323
- it "should show app creation commands" do
324
- @wizard.run_next_stage
325
- output = $terminal.read
326
- output.should match 'Below is a list of'
327
- end
328
-
329
- it "should show a thank you message" do
330
- @wizard.run_next_stage
331
- output = $terminal.read
332
- output.should match("Thank you")
333
- end
334
- end
99
+ it "should warn about a self signed cert error" do
100
+ expect_raise_from_api(RHC::Rest::SelfSignedCertificate.new('reason', 'message'))
101
+ subject.should_receive(:warn).with(/server's certificate is self-signed/).ordered
102
+ subject.should_receive(:openshift_online_server?).ordered.and_return(true)
103
+ subject.should_receive(:warn).with(/server between you and OpenShift/).ordered
335
104
 
336
- context "Repeat run of rhc setup with everything set" do
337
- before(:all) do
338
- @namespace = 'testnamespace'
339
- @wizard = RerunWizardDriver.new
340
- @rest_client = RestSpecHelper::MockRestClient.new
341
- domain = @rest_client.add_domain(@namespace)
342
- domain.add_application('test1', 'mock_standalone_cart-1')
343
- domain.add_application('test2', 'mock_standalone_cart-2')
344
- @wizard.setup_mock_config("old_mock_user@bar.baz")
345
- @wizard.setup_mock_ssh(true)
346
- @wizard.setup_mock_domain_and_applications(@namespace, 'test1' => :default, 'test2' => :default)
347
- @wizard.run_next_stage # we can skip testing the greeting
348
- end
349
-
350
- it "should ask password input with default login(use a different one)" do
351
- $terminal.write_line(@wizard.mock_user)
352
- $terminal.write_line "password"
353
-
354
- @wizard.run_next_stage
355
-
356
- output = $terminal.read
357
- output.should match("|old_mock_user@bar.baz|")
358
- end
359
-
360
- it "should write out a config" do
361
- File.exists?(@wizard.config_path).should be true
362
- @wizard.run_next_stage
363
- File.readable?(@wizard.config_path).should be true
364
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
365
- cp["default_rhlogin"].should == @wizard.mock_user
366
- cp["libra_server"].should == @wizard.libra_server
367
- end
105
+ subject.send(:login_stage).should be_nil
106
+ end
368
107
 
369
- it "should check for ssh keys, not find it on the server and update existing key" do
370
- key_data = @wizard.get_mock_key_data
371
- key_data.delete_if { |k| k.name == '73ce2cc1' }
372
- key_name = 'default'
373
- @rest_client.stub(:sshkeys) { key_data }
374
- @rest_client.stub(:find_key) { key_data.detect {|k| k.name == key_name } }
108
+ it "should warn about a cert error for Online" do
109
+ expect_raise_from_api(RHC::Rest::CertificateVerificationFailed.new('reason', 'message'))
110
+ subject.should_receive(:warn).with(/server's certificate could not be verified/).ordered
111
+ subject.should_receive(:openshift_online_server?).ordered.and_return(true)
112
+ subject.should_receive(:warn).with(/server between you and OpenShift/).ordered
375
113
 
376
- @wizard.run_next_stage # key config is pretty much a noop here
114
+ subject.send(:login_stage).should be_nil
115
+ end
377
116
 
378
- $terminal.write_line('yes')
379
- $terminal.write_line(key_name)
117
+ it "should warn about a cert error for custom server and continue" do
118
+ expect_raise_from_api(RHC::Rest::CertificateVerificationFailed.new('reason', 'message'))
119
+ subject.should_receive(:warn).with(/server's certificate could not be verified/).ordered
120
+ subject.should_receive(:openshift_online_server?).ordered.and_return(false)
121
+ subject.should_receive(:warn).with(/bypass this check/).ordered
122
+ subject.should_receive(:agree).with(/Connect without checking/).ordered.and_return(true)
123
+ expect_client_test
380
124
 
381
- # run the key check stage
382
- @wizard.run_next_stage
125
+ subject.send(:login_stage).should be_true
126
+ options.insecure.should be_true
127
+ end
383
128
 
384
- output = $terminal.read
385
- output.should match("Key with the name #{key_name} already exists. Updating")
386
- end
129
+ it "should warn about a cert error for custom server and be cancelled" do
130
+ expect_raise_from_api(RHC::Rest::CertificateVerificationFailed.new('reason', 'message'))
131
+ subject.should_receive(:warn).with(/server's certificate could not be verified/).ordered
132
+ subject.should_receive(:openshift_online_server?).ordered.and_return(false)
133
+ subject.should_receive(:warn).with(/bypass this check/).ordered
134
+ subject.should_receive(:agree).with(/Connect without checking/).ordered.and_return(false)
387
135
 
388
- it "should check for client tools and find them" do
389
- @wizard.setup_mock_has_git(true)
390
- @wizard.run_next_stage
391
- output = $terminal.read
392
- output.should match("Checking for git \.\.\. found")
136
+ subject.send(:login_stage).should be_nil
137
+ options.insecure.should be_false
138
+ end
393
139
  end
140
+ end
394
141
 
395
- it "should show namespace" do
396
- @wizard.run_next_stage
397
- output = $terminal.read
398
- output.should match("Checking for your namespace ... found namespace:")
399
- output.should match(@namespace)
400
- end
142
+ #TODO: Implement more stage level specs
401
143
 
402
- it "should list apps" do
403
- @wizard.run_next_stage
404
- output = $terminal.read
405
- output.should match("test1 - https://test1-#{@namespace}.#{@wizard.libra_server}/")
406
- output.should match("test2 - https://test2-#{@namespace}.#{@wizard.libra_server}/")
407
- end
144
+ context "when the wizard is run" do
145
+ subject{ RHC::RerunWizard.new(config, options) }
408
146
 
409
- it "should show a thank you message" do
410
- @wizard.run_next_stage
411
- output = $terminal.read
412
- output.should match("Thank you")
147
+ before(:each) do
148
+ mock_terminal
149
+ FakeFS.activate!
150
+ FakeFS::FileSystem.clear
151
+ mock_config
152
+ RHC::Config.initialize
413
153
  end
414
- end
415
154
 
416
- context "Repeat run of rhc setup with everything set but platform set to Windows" do
417
- before(:all) do
418
- @wizard = RerunWizardDriver.new
419
- @wizard.windows = true
420
- @wizard.run_next_stage
155
+ after(:all) do
156
+ FakeFS.deactivate!
421
157
  end
422
158
 
423
- it "should ask password input" do
424
- @wizard.stub_rhc_client_new
425
- # queue up input
426
- $terminal.write_line "#{@wizard.mock_user}"
427
- $terminal.write_line "password"
159
+ #after{ FileUtils.rm_rf(@tmpdir) if @tmpdir }
160
+ let(:home_dir){ '/home/mock_user' }#@tmpdir = Dir.mktmpdir }
161
+ let(:config){ RHC::Config.new.tap{ |c| c.stub(:home_dir).and_return(home_dir) } }
428
162
 
429
- @wizard.run_next_stage
163
+ let(:options){ (o = Commander::Command::Options.new).default(default_options); o }
164
+ let(:default_options){ {:server => mock_uri} }
165
+ let(:username){ mock_user }
166
+ let(:password){ 'password' }
167
+ let(:user_auth){ {:user => username, :password => password} }
430
168
 
431
- output = $terminal.read
432
- output.should match("Login to ")
433
- output.should match(/Password: [\*]{8}$/)
169
+ describe "#run" do
170
+ context "when a stage returns nil" do
171
+ before{ subject.stub(:greeting_stage).and_return(nil) }
172
+ it "should exit after that stage" do
173
+ subject.should_receive(:login_stage).never
174
+ subject.run.should be_nil
175
+ end
176
+ end
434
177
  end
435
178
 
436
- it "should write out a config" do
437
- File.exists?(@wizard.config_path).should be false
438
- @wizard.run_next_stage
439
- File.readable?(@wizard.config_path).should be true
440
- cp = RHC::Vendor::ParseConfig.new @wizard.config_path
441
- cp["default_rhlogin"].should == @wizard.mock_user
442
- cp["libra_server"].should == @wizard.libra_server
443
- end
179
+ context "with no settings" do
180
+ before do
181
+ stub_api
182
+ stub_user
183
+ stub_no_keys
184
+ stub_no_domains
185
+ stub_simple_carts
186
+ end
444
187
 
445
- it "should check for ssh keys and decline uploading them" do
446
- @wizard.setup_mock_ssh
447
- @wizard.run_next_stage
448
- RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
449
- $terminal.write_line('no')
450
- @wizard.run_next_stage
451
- output = $terminal.read
452
- output.should match("rhc sshkey")
453
- end
188
+ it "should execute the minimal path" do
189
+ should_greet_user
190
+ should_challenge_for(username, password)
191
+ should_write_config
192
+ should_create_an_ssh_keypair
193
+ should_skip_uploading_key
194
+ should_find_git
195
+ should_not_find_problems
196
+ should_skip_creating_namespace
197
+ should_list_types_of_apps_to_create
198
+ should_be_done
199
+ end
454
200
 
455
- it "should print out windows client tool info" do
456
- @wizard.run_next_stage
457
- output = $terminal.read
458
- output.should match("Git for Windows")
459
- end
201
+ context "on windows systems" do
202
+ before{ subject.stub(:windows?).and_return(true) }
203
+ it "should display windows info" do
204
+ should_greet_user
205
+ should_challenge_for(username, password)
206
+ should_write_config
207
+ should_create_an_ssh_keypair
208
+ should_skip_uploading_key
209
+ should_display_windows_info
210
+ end
211
+ end
460
212
 
461
- it "should ask for namespace and decline entering one" do
462
- $terminal.write_line("")
463
- @wizard.run_next_stage
464
- output = $terminal.read
465
- output.should match("rhc domain create")
466
- end
213
+ context "when the user enters a domain and uploads a key" do
214
+ before do
215
+ stub_create_default_key
216
+ stub_api_request(:post, 'broker/rest/domains', user_auth).
217
+ with(:body => /(thisnamespaceistoobig|invalidnamespace)/).
218
+ to_return({
219
+ :status => 409,
220
+ :body => {
221
+ :messages => [{:field => 'id', :severity => 'ERROR', :text => 'Too long', :exit_code => 123}]
222
+ }.to_json
223
+ })
224
+ stub_create_domain('testnamespace')
225
+ end
226
+ it "should create the domain" do
227
+ should_greet_user
228
+ should_challenge_for(username, password)
229
+ should_write_config
230
+ should_create_an_ssh_keypair
231
+ should_upload_default_key
232
+ should_find_git
233
+ should_not_find_problems
234
+ should_create_a_namespace
235
+ should_list_types_of_apps_to_create
236
+ should_be_done
237
+ end
238
+ end
467
239
 
468
- it "should list apps without domain" do
469
- @wizard.setup_mock_domain_and_applications(nil, 'test1' => nil, 'test2' => nil)
470
- @wizard.run_next_stage
471
- output = $terminal.read
472
- output.should match("test1 - no public url")
473
- output.should match("test2 - no public url")
474
- end
240
+ context "when the user inputs incorrect authentication" do
241
+ before{ stub_api_request(:get, 'broker/rest/user', :user => username, :password => 'invalid').to_return(:status => 401) }
242
+ it "should prompt them again" do
243
+ should_greet_user
244
+
245
+ input_line username
246
+ input_line 'invalid'
247
+ input_line password
248
+ next_stage.should_not be_nil
249
+
250
+ last_output do |s|
251
+ s.should match("Login to ")
252
+ s.should match("Username or password is not correct")
253
+ s.scan("Password: *").length.should == 2
254
+ end
255
+ end
256
+ end
475
257
 
476
- end
258
+ context "when the default key is not uploaded" do
259
+ before{ stub_one_key('a'); stub_update_key('a') }
260
+ it "should prompt for the new key" do
261
+ should_greet_user
262
+ should_challenge_for(username, password)
263
+ should_write_config
264
+ should_create_an_ssh_keypair
265
+
266
+ input_line 'yes'
267
+ input_line 'a'
268
+ next_stage
269
+ last_output do |s|
270
+ s.should match(/a \(type: ssh-rsa\)/)
271
+ s.should match("Fingerprint: #{rsa_key_fingerprint_public}")
272
+ s.should match(" name |a|")
273
+ end
274
+ end
275
+ end
477
276
 
478
- context "Do a complete run through the wizard" do
479
- before(:all) do
480
- @wizard = FirstRunWizardDriver.new
277
+ context "when the default key already exists on the server" do
278
+ before{ setup_mock_ssh(true) }
279
+ before{ stub_mock_ssh_keys }
280
+
281
+ it "should prompt for the new key" do
282
+ should_greet_user
283
+ should_challenge_for(username, password)
284
+ should_write_config
285
+ should_not_create_an_ssh_keypair
286
+ should_find_matching_server_key
287
+ end
288
+ end
481
289
  end
482
290
 
483
- it "should run" do
484
- @wizard.libra_server = nil
485
- @wizard.stub_rhc_client_new
486
- @wizard.setup_mock_ssh
291
+ context "with login and existing domain and app" do
292
+ let(:default_options){ {:rhlogin => username, :server => mock_uri} }
293
+ subject{ RHC::RerunWizard.new(config, options) }
294
+
295
+ before do
296
+ stub_api(:user => username)
297
+ stub_user
298
+ stub_no_keys
299
+ stub_create_default_key
300
+ stub_api_request(:post, 'broker/rest/domains', user_auth).
301
+ with(:body => /(thisnamespaceistoobig|invalidnamespace)/).
302
+ to_return({
303
+ :status => 409,
304
+ :body => {
305
+ :messages => [{:field => 'id', :severity => 'ERROR', :text => 'Too long', :exit_code => 123}]
306
+ }.to_json
307
+ })
308
+ stub_one_domain('testnamespace')
309
+ stub_one_application('testnamespace', 'test1')
310
+ stub_simple_carts
311
+ end
487
312
 
488
- RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
489
- mock_carts = ['ruby', 'python', 'jbosseap']
490
- @rest_client.stub(:cartridges) { mock_carts }
313
+ it "should skip steps that have already been completed" do
314
+ should_greet_user
315
+ should_challenge_for(nil, password)
316
+ should_write_config
317
+ should_create_an_ssh_keypair
318
+ should_upload_default_key
319
+ should_not_find_git
320
+ should_check_remote_server
321
+ should_find_a_namespace('testnamespace')
322
+ should_find_apps(['test1', 'testnamespace'])
323
+ should_be_done
324
+ end
491
325
 
492
- $terminal.write_line "#{@wizard.mock_user}"
493
- $terminal.write_line "password"
494
- $terminal.write_line('no')
495
- $terminal.write_line("")
326
+ context "with different config" do
327
+ let(:config_option){ setup_different_config }
328
+ let(:default_options){ {:rhlogin => username, :server => mock_uri, :config => config_option} }
496
329
 
497
- @wizard.run().should be_true
330
+ it "should overwrite the config" do
331
+ should_greet_user
332
+ should_challenge_for(nil, password)
333
+ should_overwrite_config
334
+ end
335
+ end
498
336
  end
499
337
 
500
- it "should fail" do
501
- @wizard.stub_rhc_client_new
502
- @wizard.stub(:login_stage) { nil }
503
- @wizard.run().should be_nil
504
- end
505
- end
338
+ context "with SSHWizard" do
339
+ let(:default_options){ {:rhlogin => username, :password => password} }
340
+ let(:auth){ RHC::Auth::Basic.new(options) }
341
+ let(:rest_client){ RHC::Rest::Client.new(:server => mock_uri, :auth => auth) }
342
+ subject{ RHC::SSHWizard.new(rest_client, config, options) }
506
343
 
507
- context "Check SSHWizard" do
508
- it "should generate and upload keys since the user does not have them" do
509
- wizard = SSHWizardDriver.new
510
- key_name = 'default'
511
- $terminal.write_line("yes\n#{key_name}\n")
344
+ before do
345
+ stub_api(user_auth)
346
+ stub_user
347
+ end
512
348
 
513
- wizard.run().should be_true
349
+ context "with no server keys" do
350
+ before{ stub_no_keys }
351
+ before{ stub_create_default_key }
514
352
 
515
- output = $terminal.read
516
- output.should match("Uploading key '#{key_name}'")
517
- end
353
+ it "should generate and upload keys since the user does not have them" do
354
+ input_line "yes"
355
+ input_line 'default'
356
+ input_line ""
518
357
 
519
- it "should pass through since the user has keys already" do
520
- wizard = SSHWizardDriver.new
521
- wizard.stub(:ssh_key_uploaded?) { true }
522
- wizard.run().should be_true
358
+ should_create_an_ssh_keypair
359
+ should_upload_default_key
523
360
 
524
- output = $terminal.read
525
- output.should == ""
526
- end
527
- end
361
+ #last_output.should match("Uploading key 'default'")
362
+ end
528
363
 
529
- context "Check odds and ends" do
364
+ context "with default keys created" do
365
+ before{ setup_mock_ssh(true) }
366
+ it "should upload the default key" do
367
+ should_not_create_an_ssh_keypair
368
+ should_upload_default_key
369
+ end
370
+ end
371
+ end
530
372
 
531
- it "should cause has_git? to catch an exception and return false" do
532
- wizard = FirstRunWizardDriver.new
533
- wizard.stub(:git_version_exec){ raise "Fake Exception" }
534
- wizard.send(:has_git?).should be_false
373
+ context "with the server having the default key" do
374
+ before{ setup_mock_ssh(true) }
375
+ before{ stub_mock_ssh_keys }
376
+ it "should pass through since the user has keys already" do
377
+ subject.run.should be_true
378
+ last_output.should == ""
379
+ end
380
+ end
535
381
  end
536
382
 
537
- it "should cause ssh_key_upload? to catch NoMethodError and call the fallback to get the fingerprint" do
538
- wizard = RerunWizardDriver.new
539
- Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
540
- @fallback_run = false
541
- wizard.stub(:ssh_keygen_fallback) { @fallback_run = true }
542
- key_data = wizard.get_mock_key_data
543
- @rest_client.stub(:sshkeys) { key_data }
383
+ context "Check odds and ends" do
384
+ before(:each) { mock_config }
385
+ let(:wizard){ RerunWizardDriver.new }
544
386
 
545
- wizard.send(:ssh_key_uploaded?)
387
+ it "should cause ssh_key_upload? to catch NoMethodError and call the fallback to get the fingerprint" do
388
+ Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
389
+ @fallback_run = false
390
+ wizard.stub(:ssh_keygen_fallback) { @fallback_run = true }
391
+ key_data = wizard.get_mock_key_data
392
+ @rest_client.stub(:sshkeys) { key_data }
546
393
 
547
- @fallback_run.should be_true
548
- end
394
+ wizard.send(:ssh_key_uploaded?)
549
395
 
550
- it "should cause upload_ssh_key to catch NoMethodError and call the fallback to get the fingerprint" do
551
- wizard = RerunWizardDriver.new
552
- wizard.ssh_keys = wizard.get_mock_key_data
553
- @fallback_run = false
554
- wizard.stub(:ssh_keygen_fallback) do
555
- @fallback_run = true
556
- [OpenStruct.new( :name => 'default', :fingerprint => 'AA:BB:CC:DD:EE:FF', :type => 'ssh-rsa' )]
396
+ @fallback_run.should be_true
557
397
  end
558
- $?.stub(:exitstatus) { 255 }
559
- Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
560
-
561
- wizard.send(:upload_ssh_key).should be_false
562
398
 
563
- output = $terminal.read
564
- output.should match("Your ssh public key at .* is invalid or unreadable\.")
565
- @fallback_run.should be_true
566
- end
399
+ it "should cause upload_ssh_key to catch NoMethodError and call the fallback to get the fingerprint" do
400
+ wizard.ssh_keys = wizard.get_mock_key_data
401
+ @fallback_run = false
402
+ wizard.stub(:ssh_keygen_fallback) do
403
+ @fallback_run = true
404
+ [OpenStruct.new( :name => 'default', :fingerprint => 'AA:BB:CC:DD:EE:FF', :type => 'ssh-rsa' )]
405
+ end
406
+ $?.stub(:exitstatus) { 255 }
407
+ Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
408
+
409
+ wizard.send(:upload_ssh_key).should be_false
410
+
411
+ output = last_output
412
+ output.should match("Your ssh public key at .* is invalid or unreadable\.")
413
+ @fallback_run.should be_true
414
+ end
567
415
 
568
- it "should cause upload_ssh_key to catch NotImplementedError and return false" do
569
- wizard = RerunWizardDriver.new
570
- wizard.ssh_keys = wizard.get_mock_key_data
571
- Net::SSH::KeyFactory.stub(:load_public_key) { raise NotImplementedError }
416
+ it "should cause upload_ssh_key to catch NotImplementedError and return false" do
417
+ wizard.ssh_keys = wizard.get_mock_key_data
418
+ Net::SSH::KeyFactory.stub(:load_public_key) { raise NotImplementedError }
572
419
 
573
- wizard.send(:upload_ssh_key).should be_false
420
+ wizard.send(:upload_ssh_key).should be_false
574
421
 
575
- output = $terminal.read
576
- output.should match("Your ssh public key at .* is invalid or unreadable\.")
577
- end
422
+ output = last_output
423
+ output.should match("Your ssh public key at .* is invalid or unreadable\.")
424
+ end
578
425
 
579
- it "should match ssh key fallback fingerprint to net::ssh fingerprint" do
580
- # we need to write to a live file system so ssh-keygen can find it
581
- FakeFS.deactivate!
582
- wizard = RerunWizardDriver.new
583
- Dir.mktmpdir do |dir|
584
- wizard.setup_mock_ssh_keys(dir)
585
- pub_ssh = File.join dir, "id_rsa.pub"
586
- fallback_fingerprint = wizard.send :ssh_keygen_fallback, pub_ssh
587
- internal_fingerprint, short_name = wizard.get_key_fingerprint pub_ssh
588
-
589
- fallback_fingerprint.should == internal_fingerprint
426
+ it "should match ssh key fallback fingerprint to net::ssh fingerprint" do
427
+ # we need to write to a live file system so ssh-keygen can find it
428
+ FakeFS.deactivate!
429
+ Dir.mktmpdir do |dir|
430
+ setup_mock_ssh_keys(dir)
431
+ pub_ssh = File.join dir, "id_rsa.pub"
432
+ fallback_fingerprint = wizard.send :ssh_keygen_fallback, pub_ssh
433
+ internal_fingerprint, short_name = wizard.get_key_fingerprint pub_ssh
434
+
435
+ fallback_fingerprint.should == internal_fingerprint
436
+ end
437
+ FakeFS.activate!
590
438
  end
591
- FakeFS.activate!
592
- end
593
-
594
- context "when REST Client gets ValidationException for #add_domain" do
595
- it "prints the exception message" do
596
- msg = "Resource conflict"
597
- wizard = FirstRunWizardDriver.new
598
- wizard.rest_client.stub(:add_domain) { raise RHC::Rest::ValidationException, msg }
599
- $terminal.write_line "testnamespace" # try to add a namespace
600
- $terminal.write_line '' # the above input will raise exception.
601
- # we now skip configuring namespace.
602
- wizard.send(:ask_for_namespace)
603
- output = $terminal.read
604
- output.should match msg
439
+
440
+ context "with the first run wizard" do
441
+ let(:wizard){ FirstRunWizardDriver.new }
442
+
443
+ it "prints the exception message when a domain error occurs" do
444
+ msg = "Resource conflict"
445
+ wizard.rest_client.stub(:add_domain) { raise RHC::Rest::ValidationException, msg }
446
+ input_line "testnamespace" # try to add a namespace
447
+ input_line '' # the above input will raise exception.
448
+ # we now skip configuring namespace.
449
+ wizard.send(:ask_for_namespace)
450
+ output = last_output
451
+ output.should match msg
452
+ end
453
+
454
+ it "should update the key correctly" do
455
+ key_name = 'default'
456
+ key_data = wizard.get_mock_key_data
457
+ wizard.ssh_keys = key_data
458
+ wizard.stub(:get_preferred_key_name) { key_name }
459
+ wizard.stub(:ssh_key_triple_for_default_key) { pub_key.chomp.split }
460
+ wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
461
+ wizard.rest_client.stub(:find_key) { key_data.detect { |k| k.name == key_name } }
462
+
463
+ wizard.send(:upload_ssh_key)
464
+ output = last_output
465
+ output.should match 'Updating'
466
+ end
467
+
468
+ it 'should pick a usable SSH key name' do
469
+ File.exists?('1').should be_false
470
+ key_name = 'default'
471
+ key_data = wizard.get_mock_key_data
472
+ Socket.stub(:gethostname) { key_name }
473
+ input_line("\n") # to accept default key name
474
+ wizard.ssh_keys = key_data
475
+ wizard.stub(:ssh_key_triple_for_default_key) { pub_key.chomp.split }
476
+ wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
477
+ wizard.rest_client.stub(:add_key) { true }
478
+
479
+ wizard.send(:upload_ssh_key)
480
+ output = last_output
481
+ # since the clashing key name is short, we expect to present
482
+ # a key name with "1" attached to it.
483
+ output.should match "|" + key_name + "1" + "|"
484
+ File.exists?('1').should be_false
485
+ end
605
486
  end
606
487
  end
607
-
608
- it "should update the key correctly" do
609
- key_name = 'default'
610
- wizard = FirstRunWizardDriver.new
611
- key_data = wizard.get_mock_key_data
612
- wizard.ssh_keys = key_data
613
- wizard.stub(:get_preferred_key_name) { key_name }
614
- wizard.stub(:ssh_key_triple_for_default_key) { wizard.pub_key.chomp.split }
615
- wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
616
- wizard.rest_client.stub(:find_key) { key_data.detect { |k| k.name == key_name } }
617
-
618
- wizard.send(:upload_ssh_key)
619
- output = $terminal.read
620
- output.should match 'Updating'
621
- end
622
-
623
- it 'should pick a usable SSH key name' do
624
- key_name = 'default'
625
- wizard = FirstRunWizardDriver.new
626
- key_data = wizard.get_mock_key_data
627
- Socket.stub(:gethostname) { key_name }
628
- $terminal.write_line("\n") # to accept default key name
629
- wizard.ssh_keys = key_data
630
- wizard.stub(:ssh_key_triple_for_default_key) { wizard.pub_key.chomp.split }
631
- wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
632
- wizard.rest_client.stub(:add_key) { true }
633
-
634
- wizard.send(:upload_ssh_key)
635
- output = $terminal.read
636
- # since the clashing key name is short, we expect to present
637
- # a key name with "1" attached to it.
638
- output.should match "|" + key_name + "1" + "|"
639
- end
640
488
  end
641
489
 
642
490
  module WizardDriver
643
491
 
644
- attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir, :rest_client
492
+ attr_accessor :mock_user, :rest_client
645
493
  def initialize(*args)
646
- RHC::Config.home_dir = '/home/mock_user'
494
+ if args.empty?
495
+ args = [RHC::Config.new, Commander::Command::Options.new]
496
+ args[1].default(args[0].to_options)
497
+ end
647
498
  super *args
648
- @ssh_dir = "#{RHC::Config.home_dir}/.ssh/"
649
- @libra_server = 'fake.foo'
499
+ raise "No options" if options.nil?
650
500
  @mock_user = 'mock_user@foo.bar'
651
501
  @current_wizard_stage = nil
652
502
  @platform_windows = false
503
+ #self.stub(:openshift_server).and_return('fake.foo')
653
504
  end
654
505
 
655
506
  def run_next_stage
@@ -669,30 +520,21 @@ describe RHC::Wizard do
669
520
  end
670
521
 
671
522
  def setup_mock_config(rhlogin=@mock_user)
672
- FileUtils.mkdir_p File.dirname(@config_path)
673
- File.open(@config_path, "w") do |file|
523
+ FileUtils.mkdir_p File.dirname(RHC::Config.local_config_path)
524
+ File.open(RHC::Config.local_config_path, "w") do |file|
674
525
  file.puts <<EOF
675
526
  # Default user login
676
527
  default_rhlogin='#{rhlogin}'
677
528
 
678
529
  # Server API
679
- libra_server = '#{@libra_server}'
530
+ libra_server = '#{openshift_server}'
680
531
  EOF
681
532
  end
682
533
 
683
534
  # reload config
684
- @config.home_dir = '/home/mock_user'
685
- end
686
-
687
- def setup_mock_ssh(add_ssh_key=false)
688
- FileUtils.mkdir_p @ssh_dir
689
- if add_ssh_key
690
- setup_mock_ssh_keys
691
- end
692
- end
693
-
694
- def setup_mock_has_git(bool)
695
- self.stub(:"has_git?") { bool }
535
+ @config = RHC::Config.initialize
536
+ RHC::Config.ssh_dir.should =~ /mock_user/
537
+ @config.ssh_dir.should =~ /mock_user/
696
538
  end
697
539
 
698
540
  def setup_mock_domain_and_applications(domain, apps = {})
@@ -701,7 +543,7 @@ EOF
701
543
  apps.each do |app, url|
702
544
  apps_ary.push OpenStruct.new(
703
545
  :name => app,
704
- :app_url => url == :default ? "http://#{app}-#{domain}.#{@libra_server}/" : url,
546
+ :app_url => url == :default ? "http://#{app}-#{domain}.#{openshift_server}/" : url,
705
547
  :u => true
706
548
  )
707
549
  end
@@ -736,6 +578,12 @@ EOF
736
578
  self.type = type
737
579
  self.content = content
738
580
  end
581
+ def type
582
+ @table[:type]
583
+ end
584
+ def type=(type)
585
+ @table[:type] = type
586
+ end
739
587
  end
740
588
 
741
589
  def get_mock_key_data
@@ -747,68 +595,31 @@ EOF
747
595
  ]
748
596
  end
749
597
 
750
- def priv_key
751
- <<EOF
752
- -----BEGIN RSA PRIVATE KEY-----
753
- MIICWwIBAAKBgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+Xb
754
- saS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77
755
- fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3SfwIDAQAB
756
- AoGAbMC+xZp5TsPEokOywWeH6cdWgZF5wpF7Dw7Nx34F2AFkfYWYAgVKaSxizHHv
757
- i1VdFmOBGw7Gaq+BiXXyGwEvdpmgDoZDwvJrShZef5LwYnJ/NCqjZ8Xbb9z4VxCL
758
- pkqMFFpEeNQcIDLZRF8Z1prRQnOL+Z498P6d3G/UWkR5NXkCQQDsGlpJzJwAPpwr
759
- YZ98LgKT0n2WHeCrMQ9ZyJQl3Dz40qasQmIotB+mdIh87EFex7vvyiuzRC5rfcoX
760
- CBHEkQpVAkEA2UFNBKgI1v5+16K0/CXPakQ25AlGODDv2VXlHwRPOayUG/Tn2joj
761
- fj0T4/pu9AGhz0oVXFlz7iO8PEwFU+plgwJAKD2tmdp31ErXj0VKS34EDnHX2dgp
762
- zMPF3AWlynYpJjexFLcTx+A7bMF76d7SnXbpf0sz+4/pYYTFBvvnG1ulKQJACJsR
763
- lfGiCAIkvB3x1VsaEDeLhRTo9yjZF17TqJrfGIXBiCn3VSmgZku9EfbFllzKMA/b
764
- MMFKWlCIEEtimqRaSQJAPVA1E7AiEvfUv0kRT73tDf4p/BRJ7p2YwjxrGpDBQhG1
765
- YI+4NOhWtAG3Uips++8RhvmLjv8y+TNKU31J1EJmYA==
766
- -----END RSA PRIVATE KEY-----
767
- EOF
598
+ def config_path
599
+ config.path
768
600
  end
769
-
770
- def pub_key
771
- <<EOF
772
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+XbsaS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3Sfw== OpenShift-Key
773
- EOF
774
- end
775
-
776
- def setup_mock_ssh_keys(dir=@ssh_dir)
777
- private_key_file = File.join(dir, "id_rsa")
778
- public_key_file = File.join(dir, "id_rsa.pub")
779
- File.open(private_key_file, 'w') { |f| f.write priv_key }
780
-
781
- File.open(public_key_file, 'w') { |f| f.write pub_key }
782
- end
783
-
784
- def config(local_conf_path)
785
- conf = RHC::Config
786
- conf.set_local_config(local_conf_path, false)
787
- conf
601
+ def openshift_server
602
+ super
788
603
  end
604
+ # def config(local_conf_path=nil)
605
+ # @config.set_local_config(local_conf_path, false) if local_conf_path
606
+ # @config
607
+ # end
789
608
  end
790
609
 
791
610
  class FirstRunWizardDriver < RHC::Wizard
792
611
  include WizardDriver
793
-
794
- def initialize
795
- super config('/home/mock_user/.openshift/express.conf')
796
- end
797
612
  end
798
613
 
799
614
  class RerunWizardDriver < RHC::RerunWizard
800
615
  include WizardDriver
801
-
802
- def initialize
803
- super config('/home/mock_user/.openshift/express.conf')
804
- end
805
616
  end
806
617
 
807
618
  class SSHWizardDriver < RHC::SSHWizard
808
619
  include WizardDriver
809
620
 
810
621
  def initialize
811
- super RestSpecHelper::MockRestClient.new
622
+ super RestSpecHelper::MockRestClient.new, RHC::Config.new, Commander::Command::Options.new
812
623
  end
813
624
  end
814
625
  end