rhc 0.94.8 → 0.95.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +27 -1
- data/bin/rhc +15 -23
- data/bin/rhc-app +4 -1
- data/bin/rhc-chk +3 -0
- data/bin/rhc-create-app +3 -0
- data/bin/rhc-create-domain +3 -0
- data/bin/rhc-ctl-app +3 -0
- data/bin/rhc-ctl-domain +3 -0
- data/bin/rhc-domain +5 -2
- data/bin/rhc-domain-info +3 -0
- data/bin/rhc-port-forward +16 -18
- data/bin/rhc-snapshot +3 -0
- data/bin/rhc-sshkey +3 -0
- data/bin/rhc-tail-files +3 -0
- data/bin/rhc-user-info +1 -0
- data/features/README.md +70 -0
- data/features/lib/rhc_helper/app.rb +124 -0
- data/features/lib/rhc_helper/cartridge.rb +72 -0
- data/features/lib/rhc_helper/commandify.rb +154 -0
- data/features/lib/rhc_helper/domain.rb +50 -0
- data/features/lib/rhc_helper/httpify.rb +107 -0
- data/features/lib/rhc_helper/loggable.rb +39 -0
- data/features/lib/rhc_helper/persistable.rb +38 -0
- data/features/lib/rhc_helper/runnable.rb +41 -0
- data/features/lib/rhc_helper.rb +7 -0
- data/features/step_definitions/application_steps.rb +99 -0
- data/features/step_definitions/cartridge_steps.rb +42 -0
- data/features/step_definitions/client_steps.rb +32 -0
- data/features/step_definitions/domain_steps.rb +19 -0
- data/features/support/env.rb +99 -0
- data/features/verify.feature +123 -0
- data/lib/rhc/cli.rb +4 -1
- data/lib/rhc/commands/base.rb +28 -6
- data/lib/rhc/commands/server.rb +4 -1
- data/lib/rhc/commands/setup.rb +24 -0
- data/lib/rhc/commands.rb +10 -5
- data/lib/rhc/config.rb +90 -21
- data/lib/rhc/core_ext.rb +11 -2
- data/lib/rhc/coverage_helper.rb +35 -0
- data/lib/rhc/help_formatter.rb +30 -0
- data/lib/rhc/helpers.rb +41 -5
- data/lib/rhc/ssh_key_helpers.rb +72 -0
- data/lib/rhc/targz.rb +2 -8
- data/lib/rhc/wizard.rb +75 -58
- data/lib/rhc-common.rb +20 -13
- data/lib/rhc-rest.rb +3 -11
- data/spec/coverage_helper.rb +51 -0
- data/spec/rest_spec_helper.rb +86 -0
- data/spec/rhc/cli_spec.rb +19 -3
- data/spec/rhc/commands/server_spec.rb +2 -2
- data/spec/rhc/common_spec.rb +49 -0
- data/spec/rhc/config_spec.rb +328 -0
- data/spec/rhc/helpers_spec.rb +74 -1
- data/spec/rhc/rest_client_spec.rb +402 -0
- data/spec/rhc/rest_spec.rb +454 -0
- data/spec/rhc/targz_spec.rb +13 -0
- data/spec/rhc/wizard_spec.rb +305 -43
- data/spec/spec_helper.rb +30 -25
- metadata +124 -5
data/spec/rhc/wizard_spec.rb
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fakefs/safe'
|
3
2
|
require 'rhc/wizard'
|
4
3
|
require 'rhc/vendor/parseconfig'
|
5
4
|
require 'rhc/config'
|
6
5
|
|
7
|
-
# chmod isn't implemented in the released fakefs gem
|
8
|
-
# but is in git. Once the git version is released we
|
9
|
-
# should remove this and actively check permissions
|
10
|
-
class FakeFS::File
|
11
|
-
def self.chmod(*args)
|
12
|
-
# noop
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
6
|
describe RHC::Wizard do
|
17
7
|
before(:all) do
|
18
8
|
mock_terminal
|
@@ -80,6 +70,7 @@ describe RHC::Wizard do
|
|
80
70
|
end
|
81
71
|
|
82
72
|
it "should check for client tools" do
|
73
|
+
@wizard.setup_mock_has_git(true)
|
83
74
|
@wizard.run_next_stage
|
84
75
|
output = $terminal.read
|
85
76
|
output.should match("Checking for git \.\.\. found")
|
@@ -87,6 +78,9 @@ describe RHC::Wizard do
|
|
87
78
|
|
88
79
|
it "should ask for a namespace" do
|
89
80
|
@wizard.stub_user_info
|
81
|
+
$terminal.write_line("thisnamespaceistoobigandhastoomanycharacterstobevalid")
|
82
|
+
|
83
|
+
$terminal.write_line("invalidnamespace")
|
90
84
|
$terminal.write_line("testnamespace")
|
91
85
|
@wizard.run_next_stage
|
92
86
|
output = $terminal.read
|
@@ -166,7 +160,7 @@ describe RHC::Wizard do
|
|
166
160
|
end
|
167
161
|
|
168
162
|
it "should check for client tools and print they need to be installed" do
|
169
|
-
@wizard.
|
163
|
+
@wizard.setup_mock_has_git(false)
|
170
164
|
@wizard.run_next_stage
|
171
165
|
output = $terminal.read
|
172
166
|
output.should match("Checking for git \.\.\. needs to be installed")
|
@@ -258,7 +252,9 @@ describe RHC::Wizard do
|
|
258
252
|
output.should match("|#{short_name}|")
|
259
253
|
end
|
260
254
|
|
261
|
-
it "should check for client tools and find them" do
|
255
|
+
it "should check for client tools via package kit and find them" do
|
256
|
+
@wizard.setup_mock_package_kit(true)
|
257
|
+
|
262
258
|
@wizard.run_next_stage
|
263
259
|
output = $terminal.read
|
264
260
|
output.should match("Checking for git \.\.\. found")
|
@@ -336,6 +332,7 @@ describe RHC::Wizard do
|
|
336
332
|
end
|
337
333
|
|
338
334
|
it "should check for client tools and find them" do
|
335
|
+
@wizard.setup_mock_has_git(true)
|
339
336
|
@wizard.run_next_stage
|
340
337
|
output = $terminal.read
|
341
338
|
output.should match("Checking for git \.\.\. found")
|
@@ -396,22 +393,28 @@ describe RHC::Wizard do
|
|
396
393
|
cp["libra_server"].should == @wizard.libra_server
|
397
394
|
end
|
398
395
|
|
399
|
-
it "should check for ssh keys
|
396
|
+
it "should check for ssh keys, not find it on the server and update existing key" do
|
400
397
|
key_data = @wizard.get_mock_key_data
|
398
|
+
key_data['keys'].delete('73ce2cc1')
|
401
399
|
RHC.stub(:get_ssh_keys) do
|
402
400
|
key_data
|
403
401
|
end
|
404
402
|
|
405
403
|
@wizard.run_next_stage # key config is pretty much a noop here
|
406
404
|
|
405
|
+
@wizard.set_expected_key_name_and_action('default', 'update')
|
406
|
+
$terminal.write_line('yes')
|
407
|
+
$terminal.write_line('default')
|
408
|
+
|
407
409
|
# run the key check stage
|
408
410
|
@wizard.run_next_stage
|
409
411
|
|
410
412
|
output = $terminal.read
|
411
|
-
output.
|
413
|
+
output.should match("Updating key default")
|
412
414
|
end
|
413
415
|
|
414
416
|
it "should check for client tools and find them" do
|
417
|
+
@wizard.setup_mock_has_git(true)
|
415
418
|
@wizard.run_next_stage
|
416
419
|
output = $terminal.read
|
417
420
|
output.should match("Checking for git \.\.\. found")
|
@@ -445,33 +448,256 @@ describe RHC::Wizard do
|
|
445
448
|
end
|
446
449
|
|
447
450
|
context "Repeat run of rhc setup with everything set but platform set to Windows" do
|
451
|
+
before(:all) do
|
452
|
+
@wizard = RerunWizardDriver.new
|
453
|
+
@wizard.windows = true
|
454
|
+
@wizard.run_next_stage
|
455
|
+
end
|
448
456
|
|
449
|
-
it "should
|
457
|
+
it "should ask password input" do
|
458
|
+
@wizard.stub_rhc_client_new
|
459
|
+
# queue up input
|
460
|
+
$terminal.write_line "#{@wizard.mock_user}"
|
461
|
+
$terminal.write_line "password"
|
450
462
|
|
451
|
-
|
463
|
+
@wizard.stub_user_info
|
452
464
|
|
453
|
-
|
465
|
+
@wizard.run_next_stage
|
454
466
|
|
467
|
+
output = $terminal.read
|
468
|
+
output.should match("OpenShift login")
|
469
|
+
output.should =~ /(#{Regexp.escape("Password: ********\n")})$/
|
455
470
|
end
|
456
471
|
|
457
|
-
it "should
|
472
|
+
it "should write out a config" do
|
473
|
+
File.exists?(@wizard.config_path).should be false
|
474
|
+
@wizard.run_next_stage
|
475
|
+
File.readable?(@wizard.config_path).should be true
|
476
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
477
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
478
|
+
cp["libra_server"].should == @wizard.libra_server
|
479
|
+
end
|
458
480
|
|
481
|
+
it "should check for ssh keys and decline uploading them" do
|
482
|
+
@wizard.setup_mock_ssh
|
483
|
+
@wizard.run_next_stage
|
484
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
485
|
+
$terminal.write_line('no')
|
486
|
+
@wizard.run_next_stage
|
487
|
+
output = $terminal.read
|
488
|
+
output.should match("rhc sshkey")
|
459
489
|
end
|
460
490
|
|
461
491
|
it "should print out windows client tool info" do
|
492
|
+
@wizard.run_next_stage
|
493
|
+
output = $terminal.read
|
494
|
+
output.should match("Git for Windows")
|
495
|
+
end
|
462
496
|
|
497
|
+
it "should ask for namespace and decline entering one" do
|
498
|
+
@wizard.stub_user_info
|
499
|
+
$terminal.write_line("")
|
500
|
+
@wizard.run_next_stage
|
501
|
+
output = $terminal.read
|
502
|
+
output.should match("rhc domain create")
|
463
503
|
end
|
464
504
|
|
465
|
-
it "should
|
505
|
+
it "should list apps without domain" do
|
506
|
+
@wizard.stub_user_info([],
|
507
|
+
{"test1" => {},
|
508
|
+
"test2" => {}
|
509
|
+
}
|
510
|
+
)
|
511
|
+
@wizard.run_next_stage
|
512
|
+
output = $terminal.read
|
513
|
+
output.should match("test1 - no public url")
|
514
|
+
output.should match("test2 - no public url")
|
515
|
+
end
|
516
|
+
|
517
|
+
end
|
466
518
|
|
519
|
+
context "Do a complete run through the wizard" do
|
520
|
+
before(:all) do
|
521
|
+
@wizard = FirstRunWizardDriver.new
|
467
522
|
end
|
468
523
|
|
469
|
-
it "should
|
524
|
+
it "should run" do
|
525
|
+
@wizard.libra_server = nil
|
526
|
+
@wizard.stub_rhc_client_new
|
527
|
+
@wizard.stub_user_info
|
528
|
+
@wizard.setup_mock_ssh
|
470
529
|
|
530
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
531
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
532
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
533
|
+
|
534
|
+
$terminal.write_line "#{@wizard.mock_user}"
|
535
|
+
$terminal.write_line "password"
|
536
|
+
$terminal.write_line('no')
|
537
|
+
$terminal.write_line("")
|
538
|
+
|
539
|
+
@wizard.run().should be_true
|
471
540
|
end
|
472
541
|
|
473
|
-
it "should
|
542
|
+
it "should fail" do
|
543
|
+
@wizard.stub_rhc_client_new
|
544
|
+
@wizard.stub_user_info
|
545
|
+
@wizard.stub(:login_stage) { nil }
|
546
|
+
@wizard.run().should be_nil
|
547
|
+
end
|
548
|
+
|
549
|
+
it "should cover package kit install steps" do
|
550
|
+
@wizard.libra_server = nil
|
551
|
+
@wizard.stub_rhc_client_new
|
552
|
+
@wizard.stub_user_info
|
553
|
+
@wizard.setup_mock_ssh
|
554
|
+
@wizard.setup_mock_package_kit(false)
|
555
|
+
|
556
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
557
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
558
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
559
|
+
# we need to do this because get_character does not get caught
|
560
|
+
# by our mock terminal
|
561
|
+
@wizard.stub(:get_character) {ask ""}
|
562
|
+
|
563
|
+
$terminal.write_line ""
|
564
|
+
$terminal.write_line "password"
|
565
|
+
$terminal.write_line("no")
|
566
|
+
$terminal.write_line("yes")
|
567
|
+
$terminal.write_line("")
|
568
|
+
$terminal.write_line("")
|
569
|
+
|
570
|
+
@wizard.run().should be_true
|
571
|
+
|
572
|
+
output = $terminal.read
|
573
|
+
output.should match("You may safely continue while the installer is running")
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
context "Check SSHWizard" do
|
578
|
+
it "should generate and upload keys since the user does not have them" do
|
579
|
+
wizard = SSHWizardDriver.new
|
580
|
+
wizard.stub_rhc_client_new
|
581
|
+
wizard.stub_user_info
|
582
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
583
|
+
wizard.set_expected_key_name_and_action('default', 'add')
|
584
|
+
$terminal.write_line("yes")
|
585
|
+
|
586
|
+
wizard.run().should be_true
|
587
|
+
|
588
|
+
output = $terminal.read
|
589
|
+
output.should match("Sending new key default")
|
590
|
+
end
|
591
|
+
|
592
|
+
it "should pass through since the user has keys already" do
|
593
|
+
wizard = SSHWizardDriver.new
|
594
|
+
wizard.stub_rhc_client_new
|
595
|
+
wizard.stub_user_info
|
596
|
+
wizard.setup_mock_ssh(true)
|
597
|
+
key_data = wizard.get_mock_key_data
|
598
|
+
RHC.stub(:get_ssh_keys) do
|
599
|
+
key_data
|
600
|
+
end
|
601
|
+
|
602
|
+
wizard.run().should be_true
|
474
603
|
|
604
|
+
output = $terminal.read
|
605
|
+
output.should == ""
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
context "Check odds and ends" do
|
610
|
+
it "should call dbus_send_session_method and get multiple return values" do
|
611
|
+
wizard = FirstRunWizardDriver.new
|
612
|
+
wizard.stub(:dbus_send_exec) do |cmd|
|
613
|
+
"\\nboolean true\\nboolean false\\nstring hello\\nother world\\n"
|
614
|
+
end
|
615
|
+
results = wizard.send(:dbus_send_session_method, "test", "foo.bar", "bar/baz", "alpha.Beta", "")
|
616
|
+
results.should == [true, false, "hello", "world"]
|
617
|
+
end
|
618
|
+
|
619
|
+
it "should call dbus_send_session_method and get one return value" do
|
620
|
+
wizard = FirstRunWizardDriver.new
|
621
|
+
wizard.stub(:dbus_send_exec) do |cmd|
|
622
|
+
"\\nstring hello world\\n"
|
623
|
+
end
|
624
|
+
results = wizard.send(:dbus_send_session_method, "test", "foo.bar", "bar/baz", "alpha.Beta", "")
|
625
|
+
results.should == "hello world"
|
626
|
+
end
|
627
|
+
|
628
|
+
it "should cause has_git? to catch an exception and return false" do
|
629
|
+
wizard = FirstRunWizardDriver.new
|
630
|
+
wizard.stub(:git_version_exec){ raise "Fake Exception" }
|
631
|
+
wizard.send(:has_git?).should be_false
|
632
|
+
end
|
633
|
+
|
634
|
+
it "should cause package_kit_install to catch exception and call generic_unix_install_check" do
|
635
|
+
wizard = RerunWizardDriver.new
|
636
|
+
wizard.setup_mock_package_kit(false)
|
637
|
+
wizard.stub(:dbus_send_exec) do |cmd|
|
638
|
+
"Error: mock error" if cmd.start_with?("dbus-send")
|
639
|
+
end
|
640
|
+
wizard.send(:package_kit_install)
|
641
|
+
|
642
|
+
output = $terminal.read
|
643
|
+
output.should match("Checking for git ... needs to be installed")
|
644
|
+
output.should match("Automated installation of client tools is not supported")
|
645
|
+
end
|
646
|
+
|
647
|
+
it "should cause ssh_key_upload? to catch NoMethodError and call the fallback to get the fingerprint" do
|
648
|
+
wizard = RerunWizardDriver.new
|
649
|
+
Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
|
650
|
+
@fallback_run = false
|
651
|
+
wizard.stub(:ssh_keygen_fallback) { @fallback_run = true }
|
652
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
653
|
+
|
654
|
+
wizard.send(:ssh_key_uploaded?)
|
655
|
+
|
656
|
+
@fallback_run.should be_true
|
657
|
+
end
|
658
|
+
|
659
|
+
it "should cause upload_ssh_key to catch NoMethodError and call the fallback to get the fingerprint" do
|
660
|
+
wizard = RerunWizardDriver.new
|
661
|
+
wizard.ssh_keys = wizard.get_mock_key_data
|
662
|
+
@fallback_run = false
|
663
|
+
wizard.stub(:ssh_keygen_fallback) do
|
664
|
+
@fallback_run = true
|
665
|
+
"fingerprint AA:BB:CC:DD:EE:FF"
|
666
|
+
end
|
667
|
+
$?.stub(:exitstatus) { 255 }
|
668
|
+
Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
|
669
|
+
|
670
|
+
wizard.send(:upload_ssh_key).should be_false
|
671
|
+
|
672
|
+
output = $terminal.read
|
673
|
+
output.should match("Your ssh public key at .* can not be read")
|
674
|
+
@fallback_run.should be_true
|
675
|
+
end
|
676
|
+
|
677
|
+
it "should cause upload_ssh_key to catch NotImplementedError and return false" do
|
678
|
+
wizard = RerunWizardDriver.new
|
679
|
+
wizard.ssh_keys = wizard.get_mock_key_data
|
680
|
+
Net::SSH::KeyFactory.stub(:load_public_key) { raise NotImplementedError }
|
681
|
+
|
682
|
+
wizard.send(:upload_ssh_key).should be_false
|
683
|
+
|
684
|
+
output = $terminal.read
|
685
|
+
output.should match("Your ssh public key at .* can not be read")
|
686
|
+
end
|
687
|
+
|
688
|
+
it "should match ssh key fallback fingerprint to net::ssh fingerprint" do
|
689
|
+
# we need to write to a live file system so ssh-keygen can find it
|
690
|
+
FakeFS.deactivate!
|
691
|
+
wizard = RerunWizardDriver.new
|
692
|
+
Dir.mktmpdir do |dir|
|
693
|
+
wizard.setup_mock_ssh_keys(dir)
|
694
|
+
pub_ssh = File.join dir, "id_rsa.pub"
|
695
|
+
fallback_fingerprint = wizard.send :ssh_keygen_fallback, pub_ssh
|
696
|
+
internal_fingerprint, short_name = wizard.get_key_fingerprint pub_ssh
|
697
|
+
|
698
|
+
fallback_fingerprint.should == internal_fingerprint
|
699
|
+
end
|
700
|
+
FakeFS.activate!
|
475
701
|
end
|
476
702
|
end
|
477
703
|
|
@@ -492,21 +718,19 @@ describe RHC::Wizard do
|
|
492
718
|
end
|
493
719
|
|
494
720
|
def add_domain(domain_name)
|
495
|
-
raise "Error: domain name should be '#{@domain_name}' but got '#{domain_name}'" if domain_name != @domain_name
|
721
|
+
raise Rhc::Rest::ValidationException.new("Error: domain name should be '#{@domain_name}' but got '#{domain_name}'") if domain_name != @domain_name
|
496
722
|
|
497
723
|
MockDomain.new(domain_name)
|
498
724
|
end
|
499
725
|
end
|
500
726
|
|
501
727
|
attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir
|
502
|
-
def initialize
|
728
|
+
def initialize(*args)
|
503
729
|
RHC::Config.home_dir = '/home/mock_user'
|
504
|
-
super
|
730
|
+
super *args
|
505
731
|
@ssh_dir = "#{RHC::Config.home_dir}/.ssh/"
|
506
732
|
@libra_server = 'mock.openshift.redhat.com'
|
507
733
|
@mock_user = 'mock_user@foo.bar'
|
508
|
-
@mock_git_installed = true
|
509
|
-
@mock_package_kit_installed = false
|
510
734
|
@current_wizard_stage = nil
|
511
735
|
@platform_windows = false
|
512
736
|
end
|
@@ -552,6 +776,9 @@ default_rhlogin='#{rhlogin}'
|
|
552
776
|
libra_server = '#{@libra_server}'
|
553
777
|
EOF
|
554
778
|
end
|
779
|
+
|
780
|
+
# reload config
|
781
|
+
RHC::Config.home_dir = '/home/mock_user'
|
555
782
|
end
|
556
783
|
|
557
784
|
def setup_mock_ssh(add_ssh_key=false)
|
@@ -561,16 +788,27 @@ EOF
|
|
561
788
|
end
|
562
789
|
end
|
563
790
|
|
564
|
-
def
|
565
|
-
|
791
|
+
def setup_mock_package_kit(bool)
|
792
|
+
ENV['PATH'] = '/usr/bin' unless ENV['PATH']
|
793
|
+
ENV['DBUS_SESSION_BUS_ADDRESS'] = "present" unless ENV['DBUS_SESSION_BUS_ADDRESS']
|
794
|
+
unless File.exists?('/usr/bin/dbus-send')
|
795
|
+
FileUtils.mkdir_p '/usr/bin/'
|
796
|
+
File.open('/usr/bin/dbus-send', 'w') { |f| f.write('dummy') }
|
797
|
+
end
|
798
|
+
|
799
|
+
setup_mock_has_git(false)
|
800
|
+
|
801
|
+
self.stub(:dbus_send_session_method) do
|
802
|
+
bool
|
803
|
+
end
|
566
804
|
end
|
567
805
|
|
568
|
-
def
|
569
|
-
|
806
|
+
def setup_mock_has_git(bool)
|
807
|
+
self.stub(:"has_git?") { bool }
|
570
808
|
end
|
571
809
|
|
572
|
-
def
|
573
|
-
@
|
810
|
+
def windows=(bool)
|
811
|
+
@platform_windows = bool
|
574
812
|
end
|
575
813
|
|
576
814
|
def windows?
|
@@ -588,14 +826,18 @@ EOF
|
|
588
826
|
true
|
589
827
|
end
|
590
828
|
|
591
|
-
def get_key_fingerprint
|
829
|
+
def get_key_fingerprint(path=RHC::Config.ssh_pub_key_file_path)
|
592
830
|
# returns the fingerprint and the short name used as the default
|
593
831
|
# key name
|
594
|
-
fingerprint = Net::SSH::KeyFactory.load_public_key(
|
832
|
+
fingerprint = Net::SSH::KeyFactory.load_public_key(path).fingerprint
|
595
833
|
short_name = fingerprint[0, 12].gsub(/[^0-9a-zA-Z]/,'')
|
596
834
|
return fingerprint, short_name
|
597
835
|
end
|
598
836
|
|
837
|
+
def ssh_keys=(data)
|
838
|
+
@ssh_keys = data
|
839
|
+
end
|
840
|
+
|
599
841
|
def get_mock_key_data
|
600
842
|
key_data =
|
601
843
|
{"keys" => {
|
@@ -606,11 +848,8 @@ EOF
|
|
606
848
|
"fingerprint" => "0f:97:4b:82:87:bb:c6:dc:40:a3:c1:bc:bb:55:1e:fa"}
|
607
849
|
end
|
608
850
|
|
609
|
-
def
|
610
|
-
|
611
|
-
public_key_file = File.join(@ssh_dir, "id_rsa.pub")
|
612
|
-
File.open(private_key_file, 'w') do |f|
|
613
|
-
f.write <<EOF
|
851
|
+
def priv_key
|
852
|
+
<<EOF
|
614
853
|
-----BEGIN RSA PRIVATE KEY-----
|
615
854
|
MIICWwIBAAKBgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+Xb
|
616
855
|
saS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77
|
@@ -627,21 +866,44 @@ MMFKWlCIEEtimqRaSQJAPVA1E7AiEvfUv0kRT73tDf4p/BRJ7p2YwjxrGpDBQhG1
|
|
627
866
|
YI+4NOhWtAG3Uips++8RhvmLjv8y+TNKU31J1EJmYA==
|
628
867
|
-----END RSA PRIVATE KEY-----
|
629
868
|
EOF
|
630
|
-
|
869
|
+
end
|
631
870
|
|
632
|
-
|
633
|
-
|
871
|
+
def pub_key
|
872
|
+
<<EOF
|
634
873
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+XbsaS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3Sfw== OpenShift-Key
|
635
874
|
EOF
|
636
|
-
|
875
|
+
end
|
876
|
+
|
877
|
+
def setup_mock_ssh_keys(dir=@ssh_dir)
|
878
|
+
private_key_file = File.join(dir, "id_rsa")
|
879
|
+
public_key_file = File.join(dir, "id_rsa.pub")
|
880
|
+
File.open(private_key_file, 'w') { |f| f.write priv_key }
|
881
|
+
|
882
|
+
File.open(public_key_file, 'w') { |f| f.write pub_key }
|
637
883
|
end
|
638
884
|
end
|
639
885
|
|
640
886
|
class FirstRunWizardDriver < RHC::Wizard
|
641
887
|
include WizardDriver
|
888
|
+
|
889
|
+
def initialize
|
890
|
+
super '/home/mock_user/.openshift/express.conf'
|
891
|
+
end
|
642
892
|
end
|
643
893
|
|
644
894
|
class RerunWizardDriver < RHC::RerunWizard
|
645
895
|
include WizardDriver
|
896
|
+
|
897
|
+
def initialize
|
898
|
+
super '/home/mock_user/.openshift/express.conf'
|
899
|
+
end
|
900
|
+
end
|
901
|
+
|
902
|
+
class SSHWizardDriver < RHC::SSHWizard
|
903
|
+
include WizardDriver
|
904
|
+
|
905
|
+
def initialize
|
906
|
+
super 'mock_user@foo.bar', 'password'
|
907
|
+
end
|
646
908
|
end
|
647
909
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,32 +1,23 @@
|
|
1
|
-
|
2
|
-
#require 'spec'
|
1
|
+
require 'coverage_helper'
|
3
2
|
require 'webmock/rspec'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
add_filter 'lib/rhc-rest/' #temporary
|
13
|
-
add_filter 'lib/rhc/wizard.rb' #temporary
|
14
|
-
add_filter 'lib/rhc/config.rb' #temporary
|
3
|
+
require 'fakefs/safe'
|
4
|
+
|
5
|
+
# chmod isn't implemented in the released fakefs gem
|
6
|
+
# but is in git. Once the git version is released we
|
7
|
+
# should remove this and actively check permissions
|
8
|
+
class FakeFS::File
|
9
|
+
def self.chmod(*args)
|
10
|
+
# noop
|
15
11
|
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
rescue
|
26
|
-
puts "No coverage check, older Ruby"
|
27
|
-
end
|
13
|
+
# Epic fail - FakeFS manages to redefine this to '/'
|
14
|
+
PATH_SEPARATOR = ":"
|
15
|
+
|
16
|
+
def self.executable?(path)
|
17
|
+
# if the file exists we will assume it is executable
|
18
|
+
# for testing purposes
|
19
|
+
self.exists?(path)
|
28
20
|
end
|
29
|
-
rescue
|
30
21
|
end
|
31
22
|
|
32
23
|
#include 'mocha'
|
@@ -119,6 +110,20 @@ module ClassSpecHelpers
|
|
119
110
|
$terminal = MockHighLineTerminal.new @input, @output
|
120
111
|
end
|
121
112
|
|
113
|
+
def capture(&block)
|
114
|
+
old_stderr = $stderr
|
115
|
+
old_terminal = $terminal
|
116
|
+
@input = StringIO.new
|
117
|
+
@output = StringIO.new
|
118
|
+
$stderr = (@error = StringIO.new)
|
119
|
+
$terminal = MockHighLineTerminal.new @input, @output
|
120
|
+
yield
|
121
|
+
ensure
|
122
|
+
$stderr = old_stderr
|
123
|
+
$terminal = old_terminal
|
124
|
+
@output.to_s
|
125
|
+
end
|
126
|
+
|
122
127
|
def run
|
123
128
|
#Commander::Runner.instance_variable_set :"@singleton", nil
|
124
129
|
mock_terminal
|