rhc 1.6.8 → 1.7.8
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/autocomplete/rhc_bash +1167 -0
- data/features/README.md +1 -1
- data/features/domain.feature +1 -1
- data/features/lib/rhc_helper/persistable.rb +4 -1
- data/features/multiple_cartridge.feature +4 -3
- data/features/sshkey.feature +3 -3
- data/features/support/assumptions.rb +3 -3
- data/features/support/env.rb +10 -0
- data/features/support/platform_support.rb +2 -2
- data/lib/rhc.rb +6 -0
- data/lib/rhc/auth/token.rb +4 -0
- data/lib/rhc/autocomplete.rb +50 -52
- data/lib/rhc/autocomplete_templates/{rhc.erb → bash.erb} +8 -2
- data/lib/rhc/cartridge_helpers.rb +1 -1
- data/lib/rhc/cli.rb +1 -7
- data/lib/rhc/command_runner.rb +45 -16
- data/lib/rhc/commands.rb +75 -55
- data/lib/rhc/commands/account.rb +7 -51
- data/lib/rhc/commands/alias.rb +26 -17
- data/lib/rhc/commands/app.rb +75 -39
- data/lib/rhc/commands/authorization.rb +4 -2
- data/lib/rhc/commands/base.rb +31 -29
- data/lib/rhc/commands/cartridge.rb +66 -44
- data/lib/rhc/commands/domain.rb +20 -8
- data/lib/rhc/commands/git_clone.rb +3 -3
- data/lib/rhc/commands/logout.rb +51 -0
- data/lib/rhc/commands/port_forward.rb +15 -11
- data/lib/rhc/commands/setup.rb +25 -0
- data/lib/rhc/commands/snapshot.rb +20 -10
- data/lib/rhc/commands/sshkey.rb +21 -7
- data/lib/rhc/commands/tail.rb +2 -2
- data/lib/rhc/commands/threaddump.rb +2 -2
- data/lib/rhc/context_helper.rb +0 -4
- data/lib/rhc/core_ext.rb +96 -76
- data/lib/rhc/exceptions.rb +6 -0
- data/lib/rhc/help_formatter.rb +19 -2
- data/lib/rhc/helpers.rb +32 -194
- data/lib/rhc/highline_extensions.rb +412 -0
- data/lib/rhc/output_helpers.rb +31 -67
- data/lib/rhc/rest.rb +4 -2
- data/lib/rhc/rest/alias.rb +0 -2
- data/lib/rhc/rest/application.rb +9 -4
- data/lib/rhc/rest/authorization.rb +0 -2
- data/lib/rhc/rest/base.rb +1 -1
- data/lib/rhc/rest/client.rb +11 -9
- data/lib/rhc/rest/domain.rb +5 -1
- data/lib/rhc/rest/gear_group.rb +0 -2
- data/lib/rhc/rest/key.rb +0 -2
- data/lib/rhc/rest/mock.rb +32 -10
- data/lib/rhc/ssh_helpers.rb +2 -2
- data/lib/rhc/usage_templates/command_help.erb +20 -13
- data/lib/rhc/usage_templates/command_syntax_help.erb +1 -3
- data/lib/rhc/usage_templates/help.erb +15 -16
- data/lib/rhc/usage_templates/options_help.erb +7 -9
- data/lib/rhc/wizard.rb +193 -159
- data/spec/rest_spec_helper.rb +2 -2
- data/spec/rhc/cli_spec.rb +36 -5
- data/spec/rhc/command_spec.rb +94 -42
- data/spec/rhc/commands/account_spec.rb +1 -75
- data/spec/rhc/commands/alias_spec.rb +28 -28
- data/spec/rhc/commands/app_spec.rb +141 -33
- data/spec/rhc/commands/apps_spec.rb +4 -4
- data/spec/rhc/commands/authorization_spec.rb +8 -8
- data/spec/rhc/commands/cartridge_spec.rb +18 -9
- data/spec/rhc/commands/domain_spec.rb +16 -16
- data/spec/rhc/commands/git_clone_spec.rb +3 -3
- data/spec/rhc/commands/logout_spec.rb +86 -0
- data/spec/rhc/commands/port_forward_spec.rb +9 -9
- data/spec/rhc/commands/server_spec.rb +5 -5
- data/spec/rhc/commands/setup_spec.rb +19 -5
- data/spec/rhc/commands/snapshot_spec.rb +12 -12
- data/spec/rhc/commands/sshkey_spec.rb +11 -11
- data/spec/rhc/commands/tail_spec.rb +5 -5
- data/spec/rhc/commands/threaddump_spec.rb +3 -3
- data/spec/rhc/config_spec.rb +6 -6
- data/spec/rhc/helpers_spec.rb +72 -219
- data/spec/rhc/highline_extensions_spec.rb +269 -0
- data/spec/rhc/rest_application_spec.rb +28 -1
- data/spec/rhc/rest_client_spec.rb +20 -21
- data/spec/rhc/rest_spec.rb +10 -0
- data/spec/rhc/wizard_spec.rb +72 -32
- data/spec/spec_helper.rb +86 -56
- data/spec/wizard_spec_helper.rb +7 -4
- metadata +165 -160
- data/spec/spec.opts +0 -1
data/spec/rest_spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rhc/rest/mock'
|
|
4
4
|
require 'rhc/exceptions'
|
5
5
|
require 'base64'
|
6
6
|
|
7
|
-
|
7
|
+
RSpec::Matchers.define :have_same_attributes_as do |expected|
|
8
8
|
match do |actual|
|
9
9
|
(actual.instance_variables == expected.instance_variables) &&
|
10
10
|
(actual.instance_variables.map { |i| instance_variable_get(i) } ==
|
@@ -26,6 +26,6 @@ module RestSpecHelper
|
|
26
26
|
include RHC::Rest::Mock
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
RSpec.configure do |configuration|
|
30
30
|
include(RestSpecHelper)
|
31
31
|
end
|
data/spec/rhc/cli_spec.rb
CHANGED
@@ -26,6 +26,20 @@ describe RHC::CLI do
|
|
26
26
|
it('should provide a --config switch') { run_output.should =~ /\-\-config FILE/ }
|
27
27
|
end
|
28
28
|
|
29
|
+
shared_examples_for 'a list of all commands' do
|
30
|
+
let(:arguments) { @arguments or raise "no arguments" }
|
31
|
+
it('should contain a message') { run_output.should =~ /Showing all commands/ }
|
32
|
+
it('should contain command help') { run_output.should =~ /Create an application./ }
|
33
|
+
it('should contain aliases') { run_output.should =~ /\(also/ }
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_examples_for 'a list of commands' do
|
37
|
+
let(:arguments) { @arguments or raise "no arguments" }
|
38
|
+
it('should contain a message') { run_output.should =~ /Showing commands matching '/ }
|
39
|
+
it('should contain command help') { run_output.should =~ /Create an application./ }
|
40
|
+
it('should contain aliases') { run_output.should =~ /\(also/ }
|
41
|
+
end
|
42
|
+
|
29
43
|
shared_examples_for 'a command-line options help page' do
|
30
44
|
let(:arguments) { @arguments or raise "no arguments" }
|
31
45
|
it('should contain an introduction') { run_output.should =~ /The following options can be passed to any/ }
|
@@ -92,6 +106,23 @@ describe RHC::CLI do
|
|
92
106
|
it_should_behave_like 'an invalid command'
|
93
107
|
end
|
94
108
|
|
109
|
+
context 'with help commands' do
|
110
|
+
before(:each) { @arguments = ['help', 'commands'] }
|
111
|
+
it_should_behave_like 'a list of all commands'
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with help and possible command matches' do
|
115
|
+
before(:each) { @arguments = ['help', 'app c'] }
|
116
|
+
it_should_behave_like 'a list of commands'
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'with help and a single matching command segment' do
|
120
|
+
let(:arguments){ ['help', 'app creat'] }
|
121
|
+
it("prints the usage for the command"){ run_output.should match('Usage: rhc app-create <') }
|
122
|
+
it("prints part of the description for the command"){ run_output.should match('OpenShift runs the components of your') }
|
123
|
+
it("prints a local option"){ run_output.should match('--namespace NAME') }
|
124
|
+
end
|
125
|
+
|
95
126
|
context 'with --help' do
|
96
127
|
before(:each){ @arguments = ['--help'] }
|
97
128
|
it_should_behave_like 'a global help page'
|
@@ -121,14 +152,14 @@ describe RHC::CLI do
|
|
121
152
|
describe '#set_terminal' do
|
122
153
|
before(:each) { mock_terminal }
|
123
154
|
it('should update $terminal.wrap_at') do
|
124
|
-
$stdin.should_receive(:tty?).
|
155
|
+
$stdin.should_receive(:tty?).once.and_return(true)
|
125
156
|
HighLine::SystemExtensions.should_receive(:terminal_size).and_return([5])
|
126
157
|
expect { RHC::CLI.set_terminal }.to change($terminal, :wrap_at)
|
127
158
|
end
|
128
|
-
it('should update $terminal.page_at') do
|
129
|
-
$stdin.should_receive(:tty?).
|
130
|
-
$stdout.should_receive(:tty?).
|
131
|
-
expect { RHC::CLI.set_terminal }.
|
159
|
+
it('should not update $terminal.page_at') do
|
160
|
+
$stdin.should_receive(:tty?).once.and_return(true)
|
161
|
+
$stdout.should_receive(:tty?).once.and_return(true)
|
162
|
+
expect { RHC::CLI.set_terminal }.to_not change($terminal, :page_at)
|
132
163
|
end
|
133
164
|
end
|
134
165
|
|
data/spec/rhc/command_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe RHC::Commands::Base do
|
|
8
8
|
let!(:config){ base_config }
|
9
9
|
|
10
10
|
before{ c = RHC::Commands.instance_variable_get(:@commands); @saved_commands = c && c.dup || nil }
|
11
|
-
after do
|
11
|
+
after do
|
12
12
|
(Kernel.send(:remove_const, subject) if subject.is_a?(Class)) rescue nil
|
13
13
|
RHC::Commands.instance_variable_set(:@commands, @saved_commands)
|
14
14
|
end
|
@@ -19,7 +19,7 @@ describe RHC::Commands::Base do
|
|
19
19
|
|
20
20
|
context 'when the class is at the root' do
|
21
21
|
subject do
|
22
|
-
Kernel.module_eval do
|
22
|
+
Kernel.module_eval do
|
23
23
|
class StaticRootClass < RHC::Commands::Base; def run; 1; end; end
|
24
24
|
end
|
25
25
|
StaticRootClass
|
@@ -27,8 +27,8 @@ describe RHC::Commands::Base do
|
|
27
27
|
its(:object_name) { should == 'static-root-class' }
|
28
28
|
end
|
29
29
|
context 'when the class is nested in a module' do
|
30
|
-
subject do
|
31
|
-
Kernel.module_eval do
|
30
|
+
subject do
|
31
|
+
Kernel.module_eval do
|
32
32
|
module Nested; class StaticRootClass < RHC::Commands::Base; def run; 1; end; end; end
|
33
33
|
end
|
34
34
|
Nested::StaticRootClass
|
@@ -72,8 +72,8 @@ describe RHC::Commands::Base do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'when statically defined' do
|
75
|
-
subject do
|
76
|
-
Kernel.module_eval do
|
75
|
+
subject do
|
76
|
+
Kernel.module_eval do
|
77
77
|
module Nested
|
78
78
|
class Static < RHC::Commands::Base
|
79
79
|
suppress_wizard
|
@@ -90,8 +90,8 @@ describe RHC::Commands::Base do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'when a command calls exit' do
|
93
|
-
subject do
|
94
|
-
Kernel.module_eval do
|
93
|
+
subject do
|
94
|
+
Kernel.module_eval do
|
95
95
|
class Failing < RHC::Commands::Base
|
96
96
|
def run
|
97
97
|
exit 2
|
@@ -122,93 +122,137 @@ describe RHC::Commands::Base do
|
|
122
122
|
summary "Test command execute-list"
|
123
123
|
def execute_list(args); 1; end
|
124
124
|
|
125
|
+
argument :arg1, "Test arg", ['--test'], :optional => true
|
126
|
+
argument :arg2, "Test arg list", ['--test2'], :arg_type => :list, :optional => true
|
127
|
+
argument :arg3, "Test arg list", ['--test3'], :arg_type => :list, :optional => true
|
128
|
+
summary "Test command execute-vararg"
|
129
|
+
def execute_vararg(arg1, arg2, arg3); 1; end
|
130
|
+
|
131
|
+
RHC::Helpers.global_option '--test-context', 'Test', :context => :context_var
|
132
|
+
def execute_implicit
|
133
|
+
end
|
134
|
+
|
135
|
+
argument :testarg, "Test arg", ["--testarg testarg"], :context => :context_var
|
136
|
+
summary "Test command execute"
|
137
|
+
def execute_context_arg(testarg); 1; end
|
138
|
+
|
125
139
|
def raise_error
|
126
140
|
raise StandardError.new("test exception")
|
127
141
|
end
|
128
142
|
def raise_exception
|
129
143
|
raise Exception.new("test exception")
|
130
144
|
end
|
145
|
+
|
146
|
+
protected
|
147
|
+
def context_var
|
148
|
+
"contextual"
|
149
|
+
end
|
131
150
|
end
|
132
151
|
end
|
133
152
|
Static
|
134
153
|
end
|
135
154
|
|
136
|
-
it("should register itself") { expect { subject }.to change(commands, :length).by(
|
155
|
+
it("should register itself") { expect { subject }.to change(commands, :length).by(8) }
|
137
156
|
it("should have an object name of the class") { subject.object_name.should == 'static' }
|
138
157
|
|
139
158
|
context 'and when test is called' do
|
140
|
-
it { expects_running('static
|
159
|
+
it { expects_running('static-test').should call(:test).on(instance).with(no_args) }
|
141
160
|
end
|
142
161
|
|
143
162
|
context 'and when execute is called with argument' do
|
144
|
-
it { expects_running('static
|
163
|
+
it { expects_running('static-execute', 'simplearg').should call(:execute).on(instance).with('simplearg') }
|
145
164
|
end
|
146
165
|
context 'and when execute is called with argument switch' do
|
147
|
-
it { expects_running('static
|
166
|
+
it { expects_running('static-execute', '--testarg', 'switcharg').should call(:execute).on(instance).with('switcharg') }
|
148
167
|
end
|
149
168
|
context 'and when execute is called with same argument and switch' do
|
150
|
-
it { expects_running('statis
|
169
|
+
it { expects_running('statis-execute', 'duparg', '--testarg', 'duparg2').should exit_with_code(1) }
|
151
170
|
end
|
152
171
|
|
153
172
|
context 'and when the provided option is ambiguous' do
|
154
|
-
it { expects_running('static
|
173
|
+
it { expects_running('static-execute', '-t', '--trace').should raise_error(OptionParser::AmbiguousOption) }
|
155
174
|
end
|
156
175
|
|
157
176
|
context 'and when execute is called with too many arguments' do
|
158
|
-
it { expects_running('static
|
177
|
+
it { expects_running('static-execute', 'arg1', 'arg2').should exit_with_code(1) }
|
159
178
|
end
|
160
179
|
|
161
180
|
context 'and when execute is called with a missing argument' do
|
162
|
-
it { expects_running('static
|
181
|
+
it { expects_running('static-execute').should exit_with_code(1) }
|
163
182
|
end
|
164
183
|
|
165
184
|
context 'and when execute_list is called' do
|
166
|
-
it { expects_running('static
|
167
|
-
it { expects_running('static
|
168
|
-
it { expects_running('static
|
169
|
-
it('should make the option available') { command_for('static
|
185
|
+
it { expects_running('static-execute-list', '--trace').should call(:execute_list).on(instance).with([]) }
|
186
|
+
it { expects_running('static-execute-list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
|
187
|
+
it { expects_running('static-execute-list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
|
188
|
+
it('should make the option available') { command_for('static-execute-list', '1', '2', '3').send(:options).tests.should == ['1','2','3'] }
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'and when execute_vararg is called' do
|
192
|
+
it{ expects_running('static-execute-vararg').should call(:execute_vararg).on(instance).with(nil, nil, nil) }
|
193
|
+
it{ expects_running('static-execute-vararg', '1', '2', '3').should call(:execute_vararg).on(instance).with('1', ['2', '3'], []) }
|
194
|
+
it("handles a list separator"){ expects_running('static-execute-vararg', '1', '2', '--', '3').should call(:execute_vararg).on(instance).with('1', ['2'], ['3']) }
|
195
|
+
it{ command_for('static-execute-vararg', '1', '2', '--', '3').send(:options).test.should == '1' }
|
196
|
+
it{ command_for('static-execute-vararg', '1', '2', '--', '3').send(:options).test2.should == ['2'] }
|
197
|
+
it{ command_for('static-execute-vararg', '1', '2', '--', '3').send(:options).test3.should == ['3'] }
|
198
|
+
end
|
199
|
+
context 'and when execute is called with a contextual global option' do
|
200
|
+
it("calls the helper") { command_for('static', 'execute-implicit').send(:options).test_context.should == 'contextual' }
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'and when execute-context-arg is called with a contextual argument' do
|
204
|
+
it("calls the helper") { command_for('static', 'execute-context-arg').send(:options).test_context.should == 'contextual' }
|
205
|
+
it("takes the argument") { command_for('static', 'execute-context-arg', 'arg1').send(:options).testarg.should == 'arg1' }
|
170
206
|
end
|
171
207
|
|
172
208
|
context 'and when an error is raised in a call' do
|
173
|
-
it { expects_running('static
|
209
|
+
it { expects_running('static-raise-error').should raise_error(StandardError, "test exception") }
|
174
210
|
end
|
175
211
|
|
176
212
|
context 'and when an exception is raised in a call' do
|
177
|
-
it { expects_running('static
|
213
|
+
it { expects_running('static-raise-exception').should raise_error(Exception, "test exception") }
|
178
214
|
end
|
179
215
|
|
180
216
|
context 'and when an exception is raised in a call with --trace option' do
|
181
|
-
it { expects_running('static
|
217
|
+
it { expects_running('static-raise-exception', "--trace").should raise_error(Exception, "test exception") }
|
182
218
|
end
|
183
219
|
|
184
220
|
context 'and when deprecated alias is called' do
|
185
|
-
it do
|
221
|
+
it("prints a warning") do
|
186
222
|
expects_running('static', 'exe', "arg").should call(:execute).on(instance).with('arg')
|
187
|
-
stderr.should match("Warning: This command is deprecated. Please use 'rhc static
|
223
|
+
stderr.should match("Warning: This command is deprecated. Please use 'rhc static-execute' instead.")
|
188
224
|
end
|
189
225
|
end
|
190
226
|
|
191
227
|
context 'and when deprecated alias is called with DISABLE_DEPRECATED env var' do
|
192
228
|
before { ENV['DISABLE_DEPRECATED'] = '1' }
|
193
229
|
after { ENV['DISABLE_DEPRECATED'] = nil }
|
194
|
-
it { expects_running('static', 'exe', 'arg', '--trace').should raise_error(RHC::DeprecatedError) }
|
230
|
+
it("raises an error") { expects_running('static', 'exe', 'arg', '--trace').should raise_error(RHC::DeprecatedError) }
|
195
231
|
end
|
196
232
|
end
|
197
233
|
end
|
198
234
|
|
199
235
|
describe "rest_client" do
|
200
236
|
let(:instance){ subject }
|
237
|
+
before{ RHC::Rest::Client.any_instance.stub(:api_version_negotiated).and_return(1.4) }
|
201
238
|
|
202
239
|
context "when initializing the object" do
|
203
|
-
let(:auth){ mock }
|
204
|
-
let(:basic_auth){ mock }
|
205
|
-
before{ RHC::Auth::Basic.should_receive(:new).
|
206
|
-
before{ RHC::Auth::Token.should_receive(:new).
|
207
|
-
|
208
|
-
|
209
|
-
subject.should_receive(:client_from_options).with(:auth =>
|
210
|
-
subject.send(:rest_client)
|
240
|
+
let(:auth){ mock('auth') }
|
241
|
+
let(:basic_auth){ mock('basic_auth') }
|
242
|
+
before{ RHC::Auth::Basic.should_receive(:new).at_least(1).times.with{ |arg| arg.should == instance.send(:options) }.and_return(basic_auth) }
|
243
|
+
before{ RHC::Auth::Token.should_receive(:new).any_number_of_times.with{ |arg, arg2, arg3| [arg, arg2, arg3].should == [instance.send(:options), basic_auth, instance.send(:token_store)] }.and_return(auth) }
|
244
|
+
|
245
|
+
context "with no options" do
|
246
|
+
before{ subject.should_receive(:client_from_options).with(:auth => basic_auth) }
|
247
|
+
it("should create only a basic auth object"){ subject.send(:rest_client) }
|
248
|
+
end
|
249
|
+
|
250
|
+
context "with use_authorization_tokens" do
|
251
|
+
before{ subject.send(:options).use_authorization_tokens = true }
|
252
|
+
before{ subject.should_receive(:client_from_options).with(:auth => auth) }
|
253
|
+
it("should create a token auth object"){ subject.send(:rest_client) }
|
211
254
|
end
|
255
|
+
|
212
256
|
it { subject.send(:rest_client).should be_a(RHC::Rest::Client) }
|
213
257
|
it { subject.send(:rest_client).should equal subject.send(:rest_client) }
|
214
258
|
end
|
@@ -217,7 +261,7 @@ describe RHC::Commands::Base do
|
|
217
261
|
subject{ Class.new(RHC::Commands::Base){ object_name :test; def run; 0; end } }
|
218
262
|
let(:instance) { subject.new }
|
219
263
|
let(:rest_client){ command_for(*arguments).send(:rest_client) }
|
220
|
-
let(:basic_auth){ rest_client.send(:auth).send(:auth) }
|
264
|
+
let(:basic_auth){ auth = rest_client.send(:auth); auth.is_a?(RHC::Auth::Basic) ? auth : auth.send(:auth) }
|
221
265
|
let(:stored_token){ nil }
|
222
266
|
before{ instance.send(:token_store).stub(:get).and_return(nil) unless stored_token }
|
223
267
|
|
@@ -257,10 +301,18 @@ describe RHC::Commands::Base do
|
|
257
301
|
let(:username){ 'foo' }
|
258
302
|
let(:stored_token){ 'a_token' }
|
259
303
|
let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
|
260
|
-
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(stored_token) }
|
261
304
|
before{ stub_api; stub_user(:token => stored_token) }
|
262
|
-
|
263
|
-
|
305
|
+
|
306
|
+
context "when tokens are not allowed" do
|
307
|
+
it("calls the server") { rest_client.send(:auth).is_a? RHC::Auth::Basic }
|
308
|
+
end
|
309
|
+
|
310
|
+
context "when tokens are allowed" do
|
311
|
+
let!(:config){ base_config{ |c, d| d.add('use_authorization_tokens', 'true') } }
|
312
|
+
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(stored_token) }
|
313
|
+
it("has token set") { command_for(*arguments).send(:token_for_user).should == stored_token }
|
314
|
+
it("calls the server") { rest_client.user }
|
315
|
+
end
|
264
316
|
end
|
265
317
|
|
266
318
|
context "with username and tokens enabled" do
|
@@ -268,9 +320,9 @@ describe RHC::Commands::Base do
|
|
268
320
|
let(:username){ 'foo' }
|
269
321
|
let(:auth_token){ stub(:token => 'a_token') }
|
270
322
|
let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
|
271
|
-
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.
|
323
|
+
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(nil) }
|
272
324
|
before{ stub_api(false, true); stub_api_request(:get, 'broker/rest/user', false).to_return{ |request| request.headers['Authorization'] =~ /Bearer/ ? simple_user(username) : {:status => 401} } }
|
273
|
-
it("should attempt to create a new token") do
|
325
|
+
it("should attempt to create a new token") do
|
274
326
|
rest_client.should_receive(:new_session).ordered.and_return(auth_token)
|
275
327
|
rest_client.user
|
276
328
|
end
|
@@ -280,9 +332,9 @@ describe RHC::Commands::Base do
|
|
280
332
|
let!(:config){ base_config{ |c, d| d.add('use_authorization_tokens', 'true') } }
|
281
333
|
let(:username){ 'foo' }
|
282
334
|
let(:arguments){ ['test', '-l', username, '--server', mock_uri] }
|
283
|
-
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.
|
335
|
+
before{ instance.send(:token_store).should_receive(:get).with{ |user, server| user.should == username; server.should == instance.send(:openshift_server) }.and_return(nil) }
|
284
336
|
before{ stub_api(false, false); stub_api_request(:get, 'broker/rest/user', false).to_return{ |request| request.headers['Authorization'] =~ /Basic/ ? simple_user(username) : {:status => 401} } }
|
285
|
-
it("should prompt for password") do
|
337
|
+
it("should prompt for password") do
|
286
338
|
basic_auth.should_receive(:ask).once.and_return('password')
|
287
339
|
rest_client.user
|
288
340
|
end
|
@@ -21,7 +21,7 @@ describe RHC::Commands::Account do
|
|
21
21
|
it('should show the gear capabilities') { run_output.should =~ /Allowed Gear Sizes:\s*small/ }
|
22
22
|
it('should show the consumed gears') { run_output.should =~ /Gears Used:\s*0/ }
|
23
23
|
it('should show the maximum gears') { run_output.should =~ /Gears Allowed:\s*3/ }
|
24
|
-
it { expect { run }.
|
24
|
+
it { expect { run }.to exit_with_code(0) }
|
25
25
|
|
26
26
|
context 'with a free plan' do
|
27
27
|
let(:user_plan_id){ 'free' }
|
@@ -38,78 +38,4 @@ describe RHC::Commands::Account do
|
|
38
38
|
it('should show') { run_output.should =~ /Plan:\s*Other/ }
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
describe '#logout' do
|
43
|
-
let(:arguments) { ['account', 'logout'] }
|
44
|
-
let(:username) { 'foo' }
|
45
|
-
let(:password) { 'pass' }
|
46
|
-
let(:supports_auth) { false }
|
47
|
-
let(:server) { mock_uri }
|
48
|
-
let!(:token_store) { RHC::Auth::TokenStore.new(Dir.mktmpdir) }
|
49
|
-
before{ user_config }
|
50
|
-
before do
|
51
|
-
stub_api(mock_user_auth, supports_auth)
|
52
|
-
stub_user
|
53
|
-
RHC::Auth::TokenStore.should_receive(:new).at_least(1).and_return(token_store)
|
54
|
-
end
|
55
|
-
|
56
|
-
it("should clear the token cache"){ expect{ run }.should call(:clear).on(token_store) }
|
57
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
58
|
-
it("should display a message"){ run_output.should match("All local sessions removed.") }
|
59
|
-
|
60
|
-
context "when --all is requested" do
|
61
|
-
let(:arguments) { ['account', 'logout', '--all'] }
|
62
|
-
|
63
|
-
context "if the server does not implement authorizations" do
|
64
|
-
it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*not supported/) }
|
65
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
66
|
-
end
|
67
|
-
|
68
|
-
context "if the server implements authorizations" do
|
69
|
-
let(:supports_auth) { true }
|
70
|
-
before{ stub_delete_authorizations }
|
71
|
-
|
72
|
-
it("should display a message"){ run_output.should match(/Deleting all authorizations associated with your account.*done/) }
|
73
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when --token is provided" do
|
78
|
-
let(:arguments) { ['account', 'logout', '--token', 'foo'] }
|
79
|
-
def user_auth; { :token => 'foo' }; end
|
80
|
-
|
81
|
-
context "if the server does not implement authorizations" do
|
82
|
-
it("should display a message"){ run_output.should match(/Ending session on server.*not supported/) }
|
83
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
84
|
-
end
|
85
|
-
|
86
|
-
context "if the server implements authorizations" do
|
87
|
-
let(:supports_auth) { true }
|
88
|
-
|
89
|
-
context "if the server returns successfully" do
|
90
|
-
before{ stub_delete_authorization('foo') }
|
91
|
-
|
92
|
-
it("should display a message"){ run_output.should match(/Ending session on server.*deleted/) }
|
93
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
94
|
-
it("should clear the token cache"){ expect{ run }.should call(:clear).on(token_store) }
|
95
|
-
end
|
96
|
-
|
97
|
-
context "if the server rejects the token" do
|
98
|
-
before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 401, :body => {}.to_json) }
|
99
|
-
|
100
|
-
it("should display a message"){ run_output.should match(/Ending session on server.*already closed/) }
|
101
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
102
|
-
it("should clear the token cache"){ expect{ run }.should call(:clear).on(token_store) }
|
103
|
-
end
|
104
|
-
|
105
|
-
context "if the server returns an unexpected error" do
|
106
|
-
before{ stub_request(:delete, mock_href('broker/rest/user/authorizations/foo', false)).to_return(:status => 500, :body => {}.to_json) }
|
107
|
-
|
108
|
-
it("should display a message"){ run_output.should match(/Ending session on server.*The server did not respond/) }
|
109
|
-
it("should exit with success"){ expect{ run }.should exit_with_code(0) }
|
110
|
-
it("should clear the token cache"){ expect{ run }.should call(:clear).on(token_store) }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
41
|
end
|
@@ -99,9 +99,9 @@ describe RHC::Commands::Alias do
|
|
99
99
|
|
100
100
|
context 'help is run' do
|
101
101
|
it "should display help" do
|
102
|
-
expect { run }.
|
102
|
+
expect { run }.to exit_with_code(0)
|
103
103
|
end
|
104
|
-
it('should output usage') { run_output.should match("Usage: rhc alias <
|
104
|
+
it('should output usage') { run_output.should match("Usage: rhc alias <action>$") }
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -110,9 +110,9 @@ describe RHC::Commands::Alias do
|
|
110
110
|
|
111
111
|
context 'help is run' do
|
112
112
|
it "should display help" do
|
113
|
-
expect { run }.
|
113
|
+
expect { run }.to exit_with_code(0)
|
114
114
|
end
|
115
|
-
it('should output usage') { run_output.should match("Usage: rhc alias
|
115
|
+
it('should output usage') { run_output.should match("Usage: rhc alias-add <application> <alias> [--namespace NAME]") }
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -121,9 +121,9 @@ describe RHC::Commands::Alias do
|
|
121
121
|
|
122
122
|
context 'help is run' do
|
123
123
|
it "should display help" do
|
124
|
-
expect { run }.
|
124
|
+
expect { run }.to exit_with_code(0)
|
125
125
|
end
|
126
|
-
it('should output usage') { run_output.should match("Usage: rhc alias
|
126
|
+
it('should output usage') { run_output.should match("Usage: rhc alias-remove <application> <alias> [--namespace NAME]") }
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -132,9 +132,9 @@ describe RHC::Commands::Alias do
|
|
132
132
|
|
133
133
|
context 'help is run' do
|
134
134
|
it "should display help" do
|
135
|
-
expect { run }.
|
135
|
+
expect { run }.to exit_with_code(0)
|
136
136
|
end
|
137
|
-
it('should output usage') { run_output.should match("Usage: rhc alias
|
137
|
+
it('should output usage') { run_output.should match("Usage: rhc alias-update-cert <application> <alias> --certificate FILE --private-key FILE [--passphrase passphrase]") }
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -143,9 +143,9 @@ describe RHC::Commands::Alias do
|
|
143
143
|
|
144
144
|
context 'help is run' do
|
145
145
|
it "should display help" do
|
146
|
-
expect { run }.
|
146
|
+
expect { run }.to exit_with_code(0)
|
147
147
|
end
|
148
|
-
it('should output usage') { run_output.should match("Usage: rhc alias
|
148
|
+
it('should output usage') { run_output.should match("Usage: rhc alias-delete-cert <application> <alias>") }
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -154,15 +154,15 @@ describe RHC::Commands::Alias do
|
|
154
154
|
|
155
155
|
context 'help is run' do
|
156
156
|
it "should display help" do
|
157
|
-
expect { run }.
|
157
|
+
expect { run }.to exit_with_code(0)
|
158
158
|
end
|
159
|
-
it('should output usage') { run_output.should match("Usage: rhc alias
|
159
|
+
it('should output usage') { run_output.should match("Usage: rhc alias-list <application>") }
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
describe 'add alias' do
|
164
164
|
let(:arguments) { ['alias', 'add', 'mock_app_0', 'www.foo.bar' ] }
|
165
|
-
it { expect { run }.
|
165
|
+
it { expect { run }.to exit_with_code(0) }
|
166
166
|
it { run_output.should =~ /Alias 'www.foo.bar' has been added/m }
|
167
167
|
end
|
168
168
|
|
@@ -172,7 +172,7 @@ describe RHC::Commands::Alias do
|
|
172
172
|
end
|
173
173
|
context 'remove alias successfully' do
|
174
174
|
let(:arguments) { ['alias', 'remove', 'mock_app_0', 'www.foo.bar' ] }
|
175
|
-
it { expect { run }.
|
175
|
+
it { expect { run }.to exit_with_code(0) }
|
176
176
|
it { run_output.should =~ /Alias 'www.foo.bar' has been removed/m }
|
177
177
|
end
|
178
178
|
context 'remove alias with server api <= 1.3' do
|
@@ -180,7 +180,7 @@ describe RHC::Commands::Alias do
|
|
180
180
|
before do
|
181
181
|
rest_client.stub(:api_version_negotiated).and_return(1.3)
|
182
182
|
end
|
183
|
-
it { expect { run }.
|
183
|
+
it { expect { run }.to exit_with_code(0) }
|
184
184
|
it { run_output.should =~ /Alias 'www.foo.bar' has been removed/m }
|
185
185
|
end
|
186
186
|
end
|
@@ -193,28 +193,28 @@ describe RHC::Commands::Alias do
|
|
193
193
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
|
194
194
|
'--certificate', File.expand_path('../../assets/cert.crt', __FILE__),
|
195
195
|
'--private-key', File.expand_path('../../assets/cert_key_rsa', __FILE__) ] }
|
196
|
-
it { expect { run }.
|
196
|
+
it { expect { run }.to exit_with_code(0) }
|
197
197
|
it { run_output.should =~ /SSL certificate successfully added/m }
|
198
198
|
end
|
199
199
|
context 'cert file not found' do
|
200
200
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
|
201
201
|
'--certificate', File.expand_path('../../assets/nothing.foo', __FILE__),
|
202
202
|
'--private-key', File.expand_path('../../assets/cert_key_rsa', __FILE__) ] }
|
203
|
-
it { expect { run }.
|
203
|
+
it { expect { run }.to exit_with_code(1) }
|
204
204
|
it { run_output.should =~ /Certificate file not found/m }
|
205
205
|
end
|
206
206
|
context 'private key file not found' do
|
207
207
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
|
208
208
|
'--certificate', File.expand_path('../../assets/cert.crt', __FILE__),
|
209
209
|
'--private-key', File.expand_path('../../assets/nothing.foo', __FILE__) ] }
|
210
|
-
it { expect { run }.
|
210
|
+
it { expect { run }.to exit_with_code(1) }
|
211
211
|
it { run_output.should =~ /Private key file not found/m }
|
212
212
|
end
|
213
213
|
context 'not existing certificate alias' do
|
214
214
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.unicorns.com',
|
215
215
|
'--certificate', File.expand_path('../../assets/cert.crt', __FILE__),
|
216
216
|
'--private-key', File.expand_path('../../assets/cert_key_rsa', __FILE__) ] }
|
217
|
-
it { expect { run }.
|
217
|
+
it { expect { run }.to exit_with_code(156) }
|
218
218
|
it { run_output.should =~ /Alias www.unicorns.com can't be found in application/m }
|
219
219
|
end
|
220
220
|
context 'fails if server does not support' do
|
@@ -224,21 +224,21 @@ describe RHC::Commands::Alias do
|
|
224
224
|
before do
|
225
225
|
rest_client.stub(:api_version_negotiated).and_return(1.3)
|
226
226
|
end
|
227
|
-
it { expect { run }.
|
227
|
+
it { expect { run }.to exit_with_code(1) }
|
228
228
|
it { run_output.should =~ /The server does not support SSL certificates for custom aliases/m }
|
229
229
|
end
|
230
230
|
context 'invalid certificate file (empty)' do
|
231
231
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
|
232
232
|
'--certificate', File.expand_path('../../assets/empty.txt', __FILE__),
|
233
233
|
'--private-key', File.expand_path('../../assets/cert_key_rsa', __FILE__) ] }
|
234
|
-
it { expect { run }.
|
234
|
+
it { expect { run }.to exit_with_code(1) }
|
235
235
|
it { run_output.should =~ /Invalid certificate file/m }
|
236
236
|
end
|
237
237
|
context 'invalid private key file (empty)' do
|
238
238
|
let(:arguments) { ['alias', 'update-cert', 'mock_app_0', 'www.foo.bar',
|
239
239
|
'--certificate', File.expand_path('../../assets/cert.crt', __FILE__),
|
240
240
|
'--private-key', File.expand_path('../../assets/empty.txt', __FILE__) ] }
|
241
|
-
it { expect { run }.
|
241
|
+
it { expect { run }.to exit_with_code(1) }
|
242
242
|
it { run_output.should =~ /Invalid private key file/m }
|
243
243
|
end
|
244
244
|
end
|
@@ -249,12 +249,12 @@ describe RHC::Commands::Alias do
|
|
249
249
|
end
|
250
250
|
context 'delete existing certificate' do
|
251
251
|
let(:arguments) { ['alias', 'delete-cert', 'mock_app_0', 'www.foo.bar', '--confirm'] }
|
252
|
-
it { expect { run }.
|
252
|
+
it { expect { run }.to exit_with_code(0) }
|
253
253
|
it { run_output.should =~ /SSL certificate successfully deleted/m }
|
254
254
|
end
|
255
255
|
context 'delete not existing certificate' do
|
256
256
|
let(:arguments) { ['alias', 'delete-cert', 'mock_app_0', 'www.unicorns.com', '--confirm'] }
|
257
|
-
it { expect { run }.
|
257
|
+
it { expect { run }.to exit_with_code(156) }
|
258
258
|
it { run_output.should =~ /Alias www.unicorns.com can't be found in application mock_app_0/m }
|
259
259
|
end
|
260
260
|
context 'fails if server does not support' do
|
@@ -262,7 +262,7 @@ describe RHC::Commands::Alias do
|
|
262
262
|
before do
|
263
263
|
rest_client.stub(:api_version_negotiated).and_return(1.3)
|
264
264
|
end
|
265
|
-
it { expect { run }.
|
265
|
+
it { expect { run }.to exit_with_code(1) }
|
266
266
|
it { run_output.should =~ /The server does not support SSL certificates for custom aliases/m }
|
267
267
|
end
|
268
268
|
end
|
@@ -273,14 +273,14 @@ describe RHC::Commands::Alias do
|
|
273
273
|
end
|
274
274
|
context 'list app with existing certificate' do
|
275
275
|
let(:arguments) { ['alias', 'list', 'mock_app_0'] }
|
276
|
-
it { expect { run }.
|
276
|
+
it { expect { run }.to exit_with_code(0) }
|
277
277
|
it { run_output.should =~ /Has Certificate?/m }
|
278
278
|
it { run_output.should =~ /Certificate Added/m }
|
279
279
|
it { run_output.should =~ /www.foo.bar/m }
|
280
280
|
end
|
281
281
|
context 'list app without certificates' do
|
282
282
|
let(:arguments) { ['alias', 'list', 'mock_app_1'] }
|
283
|
-
it { expect { run }.
|
283
|
+
it { expect { run }.to exit_with_code(0) }
|
284
284
|
it { run_output.should =~ /No aliases associated with the application mock_app_1/m }
|
285
285
|
end
|
286
286
|
context 'simple list is server does not support ssl certs' do
|
@@ -288,7 +288,7 @@ describe RHC::Commands::Alias do
|
|
288
288
|
before do
|
289
289
|
rest_client.stub(:api_version_negotiated).and_return(1.3)
|
290
290
|
end
|
291
|
-
it { expect { run }.
|
291
|
+
it { expect { run }.to exit_with_code(0) }
|
292
292
|
it { run_output.should =~ /no/m }
|
293
293
|
it { run_output.should =~ /-/m }
|
294
294
|
it { run_output.should =~ /www.foo.bar/m }
|