pbox 1.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYRIGHT +1 -0
- data/LICENSE +11 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/autocomplete/pbox_bash +1639 -0
- data/bin/pbox +37 -0
- data/conf/protonbox.conf +8 -0
- data/features/assets/deploy.tar.gz +0 -0
- data/features/core_feature.rb +178 -0
- data/features/deployments_feature.rb +127 -0
- data/features/domains_feature.rb +49 -0
- data/features/keys_feature.rb +37 -0
- data/features/members_feature.rb +166 -0
- data/lib/rhc/auth/basic.rb +64 -0
- data/lib/rhc/auth/token.rb +102 -0
- data/lib/rhc/auth/token_store.rb +53 -0
- data/lib/rhc/auth.rb +5 -0
- data/lib/rhc/autocomplete.rb +66 -0
- data/lib/rhc/autocomplete_templates/bash.erb +39 -0
- data/lib/rhc/cartridge_helpers.rb +118 -0
- data/lib/rhc/cli.rb +40 -0
- data/lib/rhc/command_runner.rb +186 -0
- data/lib/rhc/commands/account.rb +25 -0
- data/lib/rhc/commands/alias.rb +124 -0
- data/lib/rhc/commands/app.rb +701 -0
- data/lib/rhc/commands/apps.rb +20 -0
- data/lib/rhc/commands/authorization.rb +96 -0
- data/lib/rhc/commands/base.rb +174 -0
- data/lib/rhc/commands/cartridge.rb +326 -0
- data/lib/rhc/commands/deployment.rb +82 -0
- data/lib/rhc/commands/domain.rb +167 -0
- data/lib/rhc/commands/env.rb +142 -0
- data/lib/rhc/commands/git_clone.rb +29 -0
- data/lib/rhc/commands/logout.rb +51 -0
- data/lib/rhc/commands/member.rb +148 -0
- data/lib/rhc/commands/port_forward.rb +197 -0
- data/lib/rhc/commands/server.rb +40 -0
- data/lib/rhc/commands/setup.rb +60 -0
- data/lib/rhc/commands/snapshot.rb +137 -0
- data/lib/rhc/commands/ssh.rb +51 -0
- data/lib/rhc/commands/sshkey.rb +97 -0
- data/lib/rhc/commands/tail.rb +47 -0
- data/lib/rhc/commands/threaddump.rb +14 -0
- data/lib/rhc/commands.rb +396 -0
- data/lib/rhc/config.rb +320 -0
- data/lib/rhc/context_helper.rb +121 -0
- data/lib/rhc/core_ext.rb +202 -0
- data/lib/rhc/coverage_helper.rb +33 -0
- data/lib/rhc/deployment_helpers.rb +88 -0
- data/lib/rhc/exceptions.rb +232 -0
- data/lib/rhc/git_helpers.rb +91 -0
- data/lib/rhc/help_formatter.rb +55 -0
- data/lib/rhc/helpers.rb +477 -0
- data/lib/rhc/highline_extensions.rb +479 -0
- data/lib/rhc/json.rb +51 -0
- data/lib/rhc/output_helpers.rb +260 -0
- data/lib/rhc/rest/activation.rb +11 -0
- data/lib/rhc/rest/alias.rb +42 -0
- data/lib/rhc/rest/api.rb +87 -0
- data/lib/rhc/rest/application.rb +332 -0
- data/lib/rhc/rest/attributes.rb +36 -0
- data/lib/rhc/rest/authorization.rb +8 -0
- data/lib/rhc/rest/base.rb +79 -0
- data/lib/rhc/rest/cartridge.rb +154 -0
- data/lib/rhc/rest/client.rb +650 -0
- data/lib/rhc/rest/deployment.rb +18 -0
- data/lib/rhc/rest/domain.rb +98 -0
- data/lib/rhc/rest/environment_variable.rb +15 -0
- data/lib/rhc/rest/gear_group.rb +16 -0
- data/lib/rhc/rest/httpclient.rb +145 -0
- data/lib/rhc/rest/key.rb +44 -0
- data/lib/rhc/rest/membership.rb +105 -0
- data/lib/rhc/rest/mock.rb +1024 -0
- data/lib/rhc/rest/user.rb +32 -0
- data/lib/rhc/rest.rb +148 -0
- data/lib/rhc/ssh_helpers.rb +378 -0
- data/lib/rhc/tar_gz.rb +51 -0
- data/lib/rhc/usage_templates/command_help.erb +51 -0
- data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
- data/lib/rhc/usage_templates/help.erb +35 -0
- data/lib/rhc/usage_templates/missing_help.erb +1 -0
- data/lib/rhc/usage_templates/options_help.erb +12 -0
- data/lib/rhc/vendor/okjson.rb +600 -0
- data/lib/rhc/vendor/parseconfig.rb +178 -0
- data/lib/rhc/vendor/sshkey.rb +253 -0
- data/lib/rhc/vendor/zliby.rb +628 -0
- data/lib/rhc/version.rb +5 -0
- data/lib/rhc/wizard.rb +633 -0
- data/lib/rhc.rb +34 -0
- data/spec/coverage_helper.rb +89 -0
- data/spec/direct_execution_helper.rb +338 -0
- data/spec/keys/example.pem +23 -0
- data/spec/keys/example_private.pem +27 -0
- data/spec/keys/server.pem +19 -0
- data/spec/rest_spec_helper.rb +31 -0
- data/spec/rhc/assets/cert.crt +22 -0
- data/spec/rhc/assets/cert_key_rsa +27 -0
- data/spec/rhc/assets/empty.txt +0 -0
- data/spec/rhc/assets/env_vars.txt +7 -0
- data/spec/rhc/assets/env_vars_2.txt +1 -0
- data/spec/rhc/assets/foo.txt +1 -0
- data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
- data/spec/rhc/assets/targz_sample.tar.gz +0 -0
- data/spec/rhc/auth_spec.rb +442 -0
- data/spec/rhc/cli_spec.rb +188 -0
- data/spec/rhc/command_spec.rb +435 -0
- data/spec/rhc/commands/account_spec.rb +42 -0
- data/spec/rhc/commands/alias_spec.rb +333 -0
- data/spec/rhc/commands/app_spec.rb +754 -0
- data/spec/rhc/commands/apps_spec.rb +39 -0
- data/spec/rhc/commands/authorization_spec.rb +145 -0
- data/spec/rhc/commands/cartridge_spec.rb +641 -0
- data/spec/rhc/commands/deployment_spec.rb +286 -0
- data/spec/rhc/commands/domain_spec.rb +383 -0
- data/spec/rhc/commands/env_spec.rb +493 -0
- data/spec/rhc/commands/git_clone_spec.rb +80 -0
- data/spec/rhc/commands/logout_spec.rb +86 -0
- data/spec/rhc/commands/member_spec.rb +228 -0
- data/spec/rhc/commands/port_forward_spec.rb +217 -0
- data/spec/rhc/commands/server_spec.rb +69 -0
- data/spec/rhc/commands/setup_spec.rb +118 -0
- data/spec/rhc/commands/snapshot_spec.rb +179 -0
- data/spec/rhc/commands/ssh_spec.rb +163 -0
- data/spec/rhc/commands/sshkey_spec.rb +188 -0
- data/spec/rhc/commands/tail_spec.rb +81 -0
- data/spec/rhc/commands/threaddump_spec.rb +84 -0
- data/spec/rhc/config_spec.rb +407 -0
- data/spec/rhc/helpers_spec.rb +524 -0
- data/spec/rhc/highline_extensions_spec.rb +314 -0
- data/spec/rhc/json_spec.rb +30 -0
- data/spec/rhc/rest_application_spec.rb +248 -0
- data/spec/rhc/rest_client_spec.rb +752 -0
- data/spec/rhc/rest_spec.rb +740 -0
- data/spec/rhc/targz_spec.rb +55 -0
- data/spec/rhc/wizard_spec.rb +756 -0
- data/spec/spec_helper.rb +575 -0
- data/spec/wizard_spec_helper.rb +330 -0
- metadata +435 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rest_spec_helper'
|
3
|
+
require 'rhc/commands/threaddump'
|
4
|
+
require 'rhc/config'
|
5
|
+
describe RHC::Commands::Threaddump do
|
6
|
+
let(:client_links) { mock_response_links(mock_client_links) }
|
7
|
+
let(:domain_0_links) { mock_response_links(mock_domain_links('mock_domain_0')) }
|
8
|
+
let(:domain_1_links) { mock_response_links(mock_domain_links('mock_domain_1')) }
|
9
|
+
let(:app_0_links) { mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0')) }
|
10
|
+
let!(:rest_client){ MockRestClient.new }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
user_config
|
14
|
+
rest_client.add_domain("mock_domain_0").add_application("mock_app_0", "ruby-1.8.7")
|
15
|
+
stub_api_request(:any, client_links['LIST_DOMAINS']['relative']).
|
16
|
+
to_return({ :body => {
|
17
|
+
:type => 'domains',
|
18
|
+
:data =>
|
19
|
+
[{ :id => 'mock_domain_0',
|
20
|
+
:links => mock_response_links(mock_domain_links('mock_domain_0')),
|
21
|
+
},
|
22
|
+
{ :id => 'mock_domain_1',
|
23
|
+
:links => mock_response_links(mock_domain_links('mock_domain_1')),
|
24
|
+
}]
|
25
|
+
}.to_json,
|
26
|
+
:status => 200
|
27
|
+
})
|
28
|
+
stub_api_request(:any, domain_0_links['LIST_APPLICATIONS']['relative']).
|
29
|
+
to_return({ :body => {
|
30
|
+
:type => 'applications',
|
31
|
+
:data =>
|
32
|
+
[{ :domain_id => 'mock_domain_0',
|
33
|
+
:name => 'mock_app_0',
|
34
|
+
:creation_time => Time.new.to_s,
|
35
|
+
:uuid => 1234,
|
36
|
+
:aliases => ['alias_1', 'alias_2'],
|
37
|
+
:server_identity => 'mock_server_identity',
|
38
|
+
:links => mock_response_links(mock_app_links('mock_domain_0','mock_app_0')),
|
39
|
+
}]
|
40
|
+
}.to_json,
|
41
|
+
:status => 200
|
42
|
+
})
|
43
|
+
stub_api_request(:post, app_0_links['THREAD_DUMP']['relative'], false).
|
44
|
+
to_return({ :body => {
|
45
|
+
:type => 'application',
|
46
|
+
:data =>
|
47
|
+
{ :domain_id => 'mock_domain_1',
|
48
|
+
:name => 'mock_app_0',
|
49
|
+
:creation_time => Time.new.to_s,
|
50
|
+
:uuid => 1234,
|
51
|
+
:aliases => ['alias_1', 'alias_2'],
|
52
|
+
:server_identity => 'mock_server_identity',
|
53
|
+
:links => mock_response_links(mock_app_links('mock_domain_1','mock_app_0')),
|
54
|
+
},
|
55
|
+
:messages => [{:text => 'Application test thread dump complete.: Success', :severity => 'result'}]
|
56
|
+
}.to_json,
|
57
|
+
:status => 200
|
58
|
+
})
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'help' do
|
62
|
+
let(:arguments) { ['threaddump', '--help'] }
|
63
|
+
|
64
|
+
context 'help is run' do
|
65
|
+
it "should display help" do
|
66
|
+
expect { run }.to exit_with_code(0)
|
67
|
+
end
|
68
|
+
it('should output usage') { run_output.should match("Usage: pbox threaddump") }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'threaddump' do
|
73
|
+
let(:arguments) { ['threaddump', 'mock_app_0'] }
|
74
|
+
it { expect { run }.to exit_with_code(0) }
|
75
|
+
it { run_output.should =~ /Application test thread dump complete/ }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'threaddump no args' do
|
79
|
+
let(:arguments) { ['threaddump'] }
|
80
|
+
context 'args not supplied' do
|
81
|
+
it { expect { run }.to exit_with_code(1) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,407 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/config'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
describe RHC::Config do
|
6
|
+
subject{ RHC::Config }
|
7
|
+
before do
|
8
|
+
ENV['PROTONBOX_SERVER'] = nil
|
9
|
+
ENV['HTTP_PROXY'] = nil
|
10
|
+
ENV['http_proxy'] = nil
|
11
|
+
mock_terminal
|
12
|
+
RHC::Config.stub(:home_dir).and_return('/home/mock_user')
|
13
|
+
FakeFS.activate!
|
14
|
+
FakeFS::FileSystem.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
FakeFS.deactivate!
|
19
|
+
ENV['HTTP_PROXY'] = nil
|
20
|
+
ENV['http_proxy'] = nil
|
21
|
+
ENV['PROTONBOX_SERVER'] = nil
|
22
|
+
RHC::Config.send(:instance_variable_set, :@default, nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "class" do
|
26
|
+
it("should raise when foo is invoked") { expect{ subject.method_missing(:foo) }.to raise_error(NoMethodError) }
|
27
|
+
it("should invoke a method on default") { subject.username.should be subject.default.username }
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:values){ {} }
|
31
|
+
|
32
|
+
describe "#use_config" do
|
33
|
+
subject{ RHC::Config.new.tap{ |c| c.stub(:load_config_files) } }
|
34
|
+
|
35
|
+
context "when an exception is raised" do
|
36
|
+
before{ subject.should_receive(:set_opts_config).with(File.expand_path('foo')).and_raise(Errno::EISDIR.new('foo')) }
|
37
|
+
it("should wrap the error"){ expect{ subject.use_config('foo') }.to raise_error(ArgumentError, /Unable to read configuration file.*foo/) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_options" do
|
42
|
+
subject do
|
43
|
+
RHC::Config.new.tap do |c|
|
44
|
+
c.stub(:home_dir).and_return('/home/mock_user')
|
45
|
+
c.stub(:load_config_files)
|
46
|
+
c.instance_variable_set(:@opts, values)
|
47
|
+
c.instance_variable_set(:@defaults, nil)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with an non true value for insecure" do
|
52
|
+
let(:values){ {'insecure' => 'untruth'} }
|
53
|
+
its(:to_options){ should == {:insecure => false} }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with an invalid timeout" do
|
57
|
+
let(:values){ {'timeout' => 'a'} }
|
58
|
+
it{ expect{ subject.to_options }.to raise_error(ArgumentError) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with standard values" do
|
62
|
+
let(:values) do
|
63
|
+
{
|
64
|
+
'insecure' => 'true',
|
65
|
+
'default_pblogin' => 'user',
|
66
|
+
'protonbox_server' => 'test.com',
|
67
|
+
'password' => 'pass',
|
68
|
+
'ssl_client_cert_file' => 'file1',
|
69
|
+
'ssl_ca_file' => 'file2',
|
70
|
+
'timeout' => '1',
|
71
|
+
'use_authorization_tokens' => 'true',
|
72
|
+
}
|
73
|
+
end
|
74
|
+
its(:to_options){ should == {:insecure => true, :timeout => 1, :ssl_ca_file => 'file2', :ssl_client_cert_file => 'file1', :pblogin => 'user', :password => 'pass', :server => 'test.com', :use_authorization_tokens => true} }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "Config default values with no files" do
|
79
|
+
before{ subject.initialize }
|
80
|
+
|
81
|
+
its(:has_global_config?){ should be_false }
|
82
|
+
its(:has_local_config?){ should be_false }
|
83
|
+
its(:has_opts_config?){ should be_false }
|
84
|
+
|
85
|
+
it "should return api.protonbox.com for the server" do
|
86
|
+
subject['protonbox_server'].should == "api.protonbox.com"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "Config values with /etc/protonbox/protonbox.conf" do
|
91
|
+
|
92
|
+
it "should have only a global config" do
|
93
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com", "global@protonbox.com")
|
94
|
+
subject.initialize
|
95
|
+
subject.has_global_config?.should be_true
|
96
|
+
subject.has_local_config?.should be_false
|
97
|
+
subject.has_opts_config?.should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should get values from the global config" do
|
101
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
102
|
+
"global@protonbox.com",
|
103
|
+
{"random_value" => 12})
|
104
|
+
subject.initialize
|
105
|
+
|
106
|
+
subject['protonbox_server'].should == "global.api.protonbox.com"
|
107
|
+
subject.default_pblogin.should == "global@protonbox.com"
|
108
|
+
subject['random_value'].should == "12"
|
109
|
+
subject['non_value'].should be_nil
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should have protonbox_server fallback to the default if not set in config" do
|
114
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
115
|
+
"global@protonbox.com")
|
116
|
+
subject.initialize
|
117
|
+
|
118
|
+
subject['protonbox_server'].should == "api.protonbox.com"
|
119
|
+
subject.default_pblogin.should == "global@protonbox.com"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "With a mock home dir" do
|
124
|
+
|
125
|
+
def stub_config
|
126
|
+
config = RHC::Config.new
|
127
|
+
RHC::Config.instance_variable_set(:@default, config)
|
128
|
+
config.stub(:home_dir).and_return(ConfigHelper.home_dir)
|
129
|
+
RHC::Config.stub(:new).and_return(config)
|
130
|
+
RHC::Config.default.should == config
|
131
|
+
config.read_config_files
|
132
|
+
end
|
133
|
+
|
134
|
+
context "Config values with ~/.protonbox/protonbox.conf" do
|
135
|
+
it "should have global and local config" do
|
136
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
137
|
+
"global@protonbox.com")
|
138
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
139
|
+
"local.api.protonbox.com","local@protonbox.com")
|
140
|
+
stub_config
|
141
|
+
|
142
|
+
subject.home_conf_path.should == File.join(ConfigHelper.home_dir, '.protonbox')
|
143
|
+
subject.local_config_path.should == File.join(ConfigHelper.home_dir, '.protonbox', 'protonbox.conf')
|
144
|
+
subject.has_global_config?.should be_true
|
145
|
+
subject.has_local_config?.should be_true
|
146
|
+
subject.has_opts_config?.should be_false
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should get values from local config" do
|
150
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
151
|
+
"global@protonbox.com",
|
152
|
+
{"random_value" => "12"})
|
153
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
154
|
+
"local.api.protonbox.com",
|
155
|
+
"local@protonbox.com",
|
156
|
+
{"random_value" => 11})
|
157
|
+
stub_config
|
158
|
+
|
159
|
+
subject['protonbox_server'].should == "local.api.protonbox.com"
|
160
|
+
subject.default_pblogin.should == "local@protonbox.com"
|
161
|
+
subject['random_value'].should == "11"
|
162
|
+
subject['non_value'].should be_nil
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should fallback to the default or global if not set in config" do
|
166
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
167
|
+
"global@protonbox.com")
|
168
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
169
|
+
nil,
|
170
|
+
nil,
|
171
|
+
{"random_value" => 11})
|
172
|
+
stub_config
|
173
|
+
|
174
|
+
subject['protonbox_server'].should == "api.protonbox.com"
|
175
|
+
subject.default_pblogin.should == "global@protonbox.com"
|
176
|
+
subject['random_value'].should == "11"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "Config values with PROTONBOX_SERVER ENV set" do
|
181
|
+
it "should get values from local config" do
|
182
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
183
|
+
"global@protonbox.com",
|
184
|
+
{"random_value" => "12"})
|
185
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
186
|
+
"local.api.protonbox.com",
|
187
|
+
"local@protonbox.com",
|
188
|
+
{"random_value" => 11})
|
189
|
+
ENV['PROTONBOX_SERVER'] = "env.api.protonbox.com"
|
190
|
+
|
191
|
+
stub_config
|
192
|
+
subject.set_local_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'))
|
193
|
+
|
194
|
+
subject['protonbox_server'].should == "env.api.protonbox.com"
|
195
|
+
subject.default_pblogin.should == "local@protonbox.com"
|
196
|
+
subject['random_value'].should == "11"
|
197
|
+
subject['non_value'].should be_nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "Config values with options set" do
|
202
|
+
it "should have global and local config" do
|
203
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
204
|
+
"global@protonbox.com")
|
205
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
206
|
+
"local.api.protonbox.com","local@protonbox.com")
|
207
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
208
|
+
"opts.api.protonbox.com",
|
209
|
+
"opts@protonbox.com")
|
210
|
+
stub_config
|
211
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
212
|
+
"random_val" => "ok"})
|
213
|
+
|
214
|
+
subject.has_global_config?.should be_true
|
215
|
+
subject.has_local_config?.should be_true
|
216
|
+
subject.has_opts_config?.should be_true
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should get values from local config" do
|
220
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.api.protonbox.com",
|
221
|
+
"global@protonbox.com",
|
222
|
+
{"random_value" => "12"})
|
223
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
224
|
+
"local.api.protonbox.com",
|
225
|
+
"local@protonbox.com",
|
226
|
+
{"random_value" => 11})
|
227
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
228
|
+
"opts.api.protonbox.com",
|
229
|
+
"opts@protonbox.com",
|
230
|
+
{"random_value" => 10})
|
231
|
+
stub_config
|
232
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
233
|
+
"random_val" => "ok"})
|
234
|
+
|
235
|
+
subject['protonbox_server'].should == "opts.api.protonbox.com"
|
236
|
+
subject.default_pblogin.should == "opts@protonbox.com"
|
237
|
+
subject['random_value'].should == "10"
|
238
|
+
subject['non_value'].should be_nil
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should fallback to the default or global or local if not set in config" do
|
242
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
|
243
|
+
"global@protonbox.com")
|
244
|
+
ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.protonbox', 'protonbox.conf'),
|
245
|
+
nil,
|
246
|
+
nil,
|
247
|
+
{"random_value" => 11,
|
248
|
+
"local_value" => "local"})
|
249
|
+
ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
|
250
|
+
nil,
|
251
|
+
nil,
|
252
|
+
{"random_value" => 10})
|
253
|
+
stub_config
|
254
|
+
subject.check_cpath({"config" => ConfigHelper.opts_config_path,
|
255
|
+
"random_val" => "ok"})
|
256
|
+
|
257
|
+
subject['protonbox_server'].should == "api.protonbox.com"
|
258
|
+
subject.default_pblogin.should == "global@protonbox.com"
|
259
|
+
subject['random_value'].should == "10"
|
260
|
+
subject['local_value'].should == "local"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "Debug options" do
|
266
|
+
it "should show debug as false because nothing is set" do
|
267
|
+
subject.initialize
|
268
|
+
ConfigHelper.check_legacy_debug({}).should be_false
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should show debug as 'true' because config is set" do
|
272
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
273
|
+
nil,
|
274
|
+
nil,
|
275
|
+
{"debug" => "true"})
|
276
|
+
subject.initialize
|
277
|
+
ConfigHelper.check_legacy_debug({}).should == "true"
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should show debug as false because config is set" do
|
281
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
282
|
+
nil,
|
283
|
+
nil,
|
284
|
+
{"debug" => "false"})
|
285
|
+
subject.initialize
|
286
|
+
ConfigHelper.check_legacy_debug({}).should be_false
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should show debug as true because config is set" do
|
290
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
291
|
+
nil,
|
292
|
+
nil,
|
293
|
+
{"debug" => "true"})
|
294
|
+
subject.initialize
|
295
|
+
ConfigHelper.check_legacy_debug({"debug" => false}).should be_true
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should show debug as true because opt is set" do
|
299
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
300
|
+
nil,
|
301
|
+
nil,
|
302
|
+
{"debug" => "false"})
|
303
|
+
subject.initialize
|
304
|
+
ConfigHelper.check_legacy_debug({"debug" => true}).should be_true
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context "Proxy ENV variable parsing" do
|
309
|
+
before do
|
310
|
+
subject.initialize
|
311
|
+
['http_proxy','HTTP_PROXY'].each do |var|
|
312
|
+
ENV[var] = nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should return a direct http connection" do
|
317
|
+
subject.using_proxy?.should_not == true
|
318
|
+
end
|
319
|
+
|
320
|
+
['http_proxy','HTTP_PROXY'].each do |var|
|
321
|
+
it "should retrun a proxy http connection for #{var}" do
|
322
|
+
ENV[var] = "fakeproxy.foo:8080"
|
323
|
+
# returns a generic class so we check to make sure it is not a
|
324
|
+
# Net::HTTP class and rely on simplecov to make sure the proxy
|
325
|
+
# code path was run
|
326
|
+
subject.using_proxy?.should == true
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context "it should have the correct values" do
|
331
|
+
let(:vars){ subject.proxy_vars }
|
332
|
+
before do
|
333
|
+
ENV['http_proxy'] = "my_user:my_pass@fakeproxy.foo:8080"
|
334
|
+
end
|
335
|
+
|
336
|
+
{
|
337
|
+
:user => 'my_user',
|
338
|
+
:pass => 'my_pass',
|
339
|
+
:address => 'fakeproxy.foo',
|
340
|
+
:port => 8080
|
341
|
+
}.each do |var,expected|
|
342
|
+
it "for #{var}" do
|
343
|
+
vars[var].should == expected
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context "Configuration file parsing" do
|
350
|
+
it "should exit if config file can't be read" do
|
351
|
+
ConfigHelper.write_out_config(ConfigHelper.global_config_path,
|
352
|
+
"global.api.protonbox.com",
|
353
|
+
"global@protonbox.com")
|
354
|
+
subject.initialize
|
355
|
+
RHC::Vendor::ParseConfig.stub(:new) { raise Errno::EACCES.new("Fake can't read file") }
|
356
|
+
subject.stub(:exit) { |code| code }
|
357
|
+
|
358
|
+
expect { subject.check_cpath({"config" => "fake.conf"}) }.to raise_error(Errno::EACCES)
|
359
|
+
|
360
|
+
# write out config file so it exists but is not readable
|
361
|
+
ConfigHelper.write_out_config("fake.conf",
|
362
|
+
"global.api.protonbox.com",
|
363
|
+
"global@protonbox.com")
|
364
|
+
|
365
|
+
expect { subject.read_config_files }.to raise_error(Errno::EACCES)
|
366
|
+
expect { subject.set_local_config("fake.conf") }.to raise_error(Errno::EACCES)
|
367
|
+
expect { subject.set_opts_config("fake.conf") }.to raise_error(Errno::EACCES)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
class ConfigHelper
|
373
|
+
@@global_config_path = '/etc/protonbox/protonbox.conf'
|
374
|
+
@@home_dir = '/home/mock_user'
|
375
|
+
@@opts_config_path = File.join(@@home_dir, "my.conf")
|
376
|
+
|
377
|
+
def self.global_config_path
|
378
|
+
@@global_config_path
|
379
|
+
end
|
380
|
+
|
381
|
+
def self.home_dir
|
382
|
+
@@home_dir
|
383
|
+
end
|
384
|
+
|
385
|
+
def self.opts_config_path
|
386
|
+
@@opts_config_path
|
387
|
+
end
|
388
|
+
|
389
|
+
def self.check_legacy_debug(opts)
|
390
|
+
# this simulates how the old rhc code checked for debug
|
391
|
+
# in the future this should all be filtered through the Config module
|
392
|
+
# and an app should just have to use subject.debug?
|
393
|
+
debug = RHC::Config['debug'] == 'false' ? nil : RHC::Config['debug']
|
394
|
+
debug = true if opts.has_key? 'debug'
|
395
|
+
debug
|
396
|
+
end
|
397
|
+
|
398
|
+
def self.write_out_config(config_path, server, login, other={})
|
399
|
+
FileUtils.mkdir_p File.dirname(config_path)
|
400
|
+
File.open(config_path, "w") do |f|
|
401
|
+
f.write "# This is a test file\n\n"
|
402
|
+
f.write("protonbox_server = #{server}\n") unless server.nil?
|
403
|
+
f.write("default_pblogin = #{login}\n\n") unless login.nil?
|
404
|
+
other.each { |key, value| f.write("#{key}=#{value}\n") }
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|