brightbox-cli 2.2.0 → 2.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +5 -2
- data/brightbox-cli.gemspec +1 -1
- data/lib/brightbox/cli/config.rb +19 -0
- data/lib/brightbox-cli/accounts.rb +2 -2
- data/lib/brightbox-cli/api.rb +4 -4
- data/lib/brightbox-cli/commands/accounts/default.rb +1 -1
- data/lib/brightbox-cli/commands/accounts/list.rb +1 -1
- data/lib/brightbox-cli/commands/config/client-add.rb +2 -2
- data/lib/brightbox-cli/commands/config/client-default.rb +3 -3
- data/lib/brightbox-cli/commands/config/client-list.rb +6 -6
- data/lib/brightbox-cli/commands/config/client-remove.rb +4 -4
- data/lib/brightbox-cli/commands/config/user-add.rb +2 -2
- data/lib/brightbox-cli/commands/login.rb +53 -0
- data/lib/brightbox-cli/config/accounts.rb +5 -0
- data/lib/brightbox-cli/config/authentication_tokens.rb +10 -3
- data/lib/brightbox-cli/config/cache.rb +8 -12
- data/lib/brightbox-cli/config/clients.rb +14 -38
- data/lib/brightbox-cli/config/sections.rb +70 -13
- data/lib/brightbox-cli/config/user_application.rb +13 -5
- data/lib/brightbox-cli/config.rb +22 -14
- data/lib/brightbox-cli/connection_manager.rb +2 -2
- data/lib/brightbox-cli/gli_global_hooks.rb +25 -28
- data/lib/brightbox-cli/version.rb +1 -1
- data/lib/brightbox_cli.rb +4 -0
- data/spec/cassettes/Brightbox_BBConfig/_add_section/when_config_exists_and_overwrite_duplicates_is_false/does_not_update_the_config_file.yml +199 -0
- data/spec/cassettes/Brightbox_BBConfig/_add_section/when_config_exists_and_overwrite_duplicates_is_true/does_not_update_the_config_file.yml +199 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/does_not_alter_the_configuration.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/updates_access_token.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/updates_refresh_token.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/does_not_alter_the_configuration.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/updates_access_token.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/updates_refresh_token.yml +99 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/does_not_alter_the_configuration.yml +149 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/updates_access_token.yml +149 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/updates_refresh_token.yml +149 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_no_config_exists/creates_the_configuration.yml +101 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_no_config_exists/refreshed_tokens.yml +101 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_using_an_email_and_suffix/creates_the_configuration.yml +101 -0
- data/spec/cassettes/Brightbox_BBConfig_add_login/when_using_an_email_and_suffix/refreshed_tokens.yml +101 -0
- data/spec/cassettes/brightbox_accounts/list/_when_access_token_expired_/does_not_report_invalid_token_errors.yml +64 -18
- data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_/does_not_report_invalid_token_errors.yml +62 -16
- data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_error.yml +101 -0
- data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_prompt_to_rerun_the_command.yml +101 -0
- data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/prompts_for_the_password.yml +101 -0
- data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/requests_access_tokens.yml +101 -0
- data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/sets_up_the_config.yml +101 -0
- data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/does_not_error.yml +101 -0
- data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/does_not_prompt_to_rerun_the_command.yml +101 -0
- data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/prompts_for_the_password.yml +101 -0
- data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/requests_access_tokens.yml +101 -0
- data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/sets_up_the_config.yml +101 -0
- data/spec/cassettes/brightbox_login/when_default_account_is_passed/does_not_error.yml +51 -0
- data/spec/cassettes/brightbox_login/when_default_account_is_passed/does_not_prompt_to_rerun_the_command.yml +51 -0
- data/spec/cassettes/brightbox_login/when_default_account_is_passed/prompts_for_the_password.yml +51 -0
- data/spec/cassettes/brightbox_login/when_default_account_is_passed/requests_access_tokens.yml +51 -0
- data/spec/cassettes/brightbox_login/when_default_account_is_passed/sets_up_the_config.yml +51 -0
- data/spec/cassettes/brightbox_login/when_no_config_is_present/does_not_error.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_config_is_present/does_not_prompt_to_rerun_the_command.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_config_is_present/requests_access_tokens.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_config_is_present/sets_up_the_config.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_password_is_given/does_not_error.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_password_is_given/does_not_prompt_to_rerun_the_command.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_password_is_given/prompts_for_the_password.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_password_is_given/requests_access_tokens.yml +101 -0
- data/spec/cassettes/brightbox_login/when_no_password_is_given/sets_up_the_config.yml +101 -0
- data/spec/commands/accounts/list_spec.rb +1 -0
- data/spec/commands/login_spec.rb +239 -0
- data/spec/configs/user_app.ini +0 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/config_helpers.rb +5 -0
- data/spec/unit/brightbox/account/all_spec.rb +1 -3
- data/spec/unit/brightbox/api/conn_spec.rb +3 -0
- data/spec/unit/brightbox/api/find_spec.rb +3 -0
- data/spec/unit/brightbox/bb_config/account_spec.rb +2 -0
- data/spec/unit/brightbox/bb_config/add_login_spec.rb +222 -0
- data/spec/unit/brightbox/bb_config/client_name_spec.rb +4 -12
- data/spec/unit/brightbox/bb_config/client_named_spec.rb +1 -1
- data/spec/unit/brightbox/bb_config/config_directory_exists_spec.rb +5 -2
- data/spec/unit/brightbox/bb_config/config_directory_spec.rb +4 -2
- data/spec/unit/brightbox/bb_config/config_spec.rb +4 -8
- data/spec/unit/brightbox/bb_config/default_account_spec.rb +10 -6
- data/spec/unit/brightbox/bb_config/find_or_set_default_account_spec.rb +2 -0
- data/spec/unit/brightbox/bb_config/renew_tokens_spec.rb +3 -0
- data/spec/unit/brightbox/bb_config/section_names_spec.rb +46 -0
- data/spec/unit/brightbox/bb_config/using_client_spec.rb +12 -12
- data/spec/unit/brightbox/bb_config_spec.rb +0 -1
- data/spec/unit/brightbox/cloud_ip/find_spec.rb +3 -0
- data/spec/unit/brightbox/config/user_application/to_fog_spec.rb +33 -29
- data/spec/unit/brightbox/config/user_application/valid_spec.rb +0 -32
- data/spec/unit/brightbox/connection_manager/fetch_connection_spec.rb +7 -3
- data/spec/unit/brightbox/firewall_policy/apply_to_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_policy/create_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_policy/destroy_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_policy/find_or_call_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_policy/find_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_rule/create_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_rule/destroy_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_rule/find_spec.rb +3 -0
- data/spec/unit/brightbox/firewall_rule/from_policy_spec.rb +3 -0
- data/spec/unit/brightbox/server/destroy_spec.rb +4 -0
- data/spec/unit/brightbox/server/find_or_call_spec.rb +3 -0
- data/spec/unit/brightbox/server/find_spec.rb +4 -0
- data/spec/unit/brightbox/server/shutdown_spec.rb +4 -0
- data/spec/unit/brightbox/server/start_spec.rb +4 -0
- data/spec/unit/brightbox/server/stop_spec.rb +4 -0
- data/spec/unit/brightbox/server/update_spec.rb +4 -0
- data/spec/unit/brightbox/server_group/find_spec.rb +3 -0
- data/spec/unit/brightbox/user_collaboration/get_for_account_spec.rb +3 -0
- metadata +90 -3
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Brightbox::BBConfig, "#add_login" do
|
|
4
|
+
let(:config) { Brightbox::BBConfig.new }
|
|
5
|
+
|
|
6
|
+
let(:email) { "jason.null@brightbox.com" }
|
|
7
|
+
let(:password) { "N:B3e%7Cmh" }
|
|
8
|
+
let(:api_url) { ENV["BRIGHTBOX_API_URL"] || "http://api.brightbox.dev" }
|
|
9
|
+
|
|
10
|
+
context "when no config exists", vcr: true do
|
|
11
|
+
let(:expected_config) do
|
|
12
|
+
<<EOS
|
|
13
|
+
[core]
|
|
14
|
+
default_client = #{email}
|
|
15
|
+
|
|
16
|
+
[#{email}]
|
|
17
|
+
username = #{email}
|
|
18
|
+
api_url = #{api_url}
|
|
19
|
+
auth_url = #{api_url}
|
|
20
|
+
default_account = acc-12345
|
|
21
|
+
|
|
22
|
+
EOS
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
before do
|
|
26
|
+
remove_config
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "creates the configuration" do
|
|
30
|
+
FauxIO.new do
|
|
31
|
+
config.add_login(email, password)
|
|
32
|
+
end
|
|
33
|
+
expect(config_file_contents).to eq(expected_config)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "refreshed tokens" do
|
|
37
|
+
FauxIO.new do
|
|
38
|
+
expect { config.add_login(email, password) }.not_to raise_error
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
expect(cached_access_token(config)).to eq(config.access_token)
|
|
42
|
+
expect(cached_refresh_token(config)).to eq(config.refresh_token)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when logged in previously", vcr: true do
|
|
47
|
+
let(:original_config) { config_file_contents }
|
|
48
|
+
|
|
49
|
+
before do
|
|
50
|
+
FauxIO.new { config.add_login(email, password) }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "does not alter the configuration" do
|
|
54
|
+
FauxIO.new do
|
|
55
|
+
expect {
|
|
56
|
+
config.add_login(email, password)
|
|
57
|
+
}.not_to change { config_file_contents }.from(original_config)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "updates access token" do
|
|
62
|
+
FauxIO.new do
|
|
63
|
+
expect { config.add_login(email, password) }.to change {
|
|
64
|
+
config.access_token
|
|
65
|
+
}.from(cached_access_token(config))
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "updates refresh token" do
|
|
70
|
+
FauxIO.new do
|
|
71
|
+
expect { config.add_login(email, password) }.to change {
|
|
72
|
+
config.refresh_token
|
|
73
|
+
}.from(cached_refresh_token(config))
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when configured with custom options", vcr: true do
|
|
79
|
+
let(:original_config) { config_file_contents }
|
|
80
|
+
|
|
81
|
+
let(:custom_url) { ENV["BRIGHTBOX_API_URL"] || "http://api.brightbox.dev" }
|
|
82
|
+
let(:custom_app_id) { "app-23456" }
|
|
83
|
+
let(:custom_app_secret) { "ho04hondtzjjdf4" }
|
|
84
|
+
let(:custom_default_account) { "acc-23456" }
|
|
85
|
+
|
|
86
|
+
let(:custom_options) do
|
|
87
|
+
{
|
|
88
|
+
api_url: custom_url,
|
|
89
|
+
auth_url: custom_url,
|
|
90
|
+
default_account: custom_default_account,
|
|
91
|
+
client_id: custom_app_id,
|
|
92
|
+
secret: custom_app_secret
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
before do
|
|
97
|
+
FauxIO.new { config.add_login(email, password, custom_options) }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "does not alter the configuration" do
|
|
101
|
+
FauxIO.new do
|
|
102
|
+
expect {
|
|
103
|
+
config.add_login(email, password)
|
|
104
|
+
}.not_to change { config_file_contents }.from(original_config)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
expect(config_file_contents).to match("[#{email}]")
|
|
108
|
+
expect(config_file_contents).to match("api_url = #{custom_url}")
|
|
109
|
+
expect(config_file_contents).to match("auth_url = #{custom_url}")
|
|
110
|
+
expect(config_file_contents).to match("username = #{email}")
|
|
111
|
+
expect(config_file_contents).to match("default_account = #{custom_default_account}")
|
|
112
|
+
expect(config_file_contents).to match("default_client = #{email}")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "updates access token" do
|
|
116
|
+
FauxIO.new do
|
|
117
|
+
expect { config.add_login(email, password) }.to change {
|
|
118
|
+
config.access_token
|
|
119
|
+
}.from(cached_access_token(config))
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "updates refresh token" do
|
|
124
|
+
FauxIO.new do
|
|
125
|
+
expect { config.add_login(email, password) }.to change {
|
|
126
|
+
config.refresh_token
|
|
127
|
+
}.from(cached_refresh_token(config))
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context "when altering a custom option", vcr: true do
|
|
133
|
+
let(:original_config) { config_file_contents }
|
|
134
|
+
|
|
135
|
+
let(:custom_url) { ENV["BRIGHTBOX_API_URL"] || "http://api.brightbox.dev" }
|
|
136
|
+
let(:custom_app_id) { "app-23456" }
|
|
137
|
+
let(:custom_app_secret) { "ho04hondtzjjdf4" }
|
|
138
|
+
let(:custom_default_account) { "acc-23456" }
|
|
139
|
+
|
|
140
|
+
let(:custom_options) do
|
|
141
|
+
{
|
|
142
|
+
api_url: custom_url,
|
|
143
|
+
auth_url: custom_url,
|
|
144
|
+
default_account: custom_default_account,
|
|
145
|
+
client_id: custom_app_id,
|
|
146
|
+
secret: custom_app_secret
|
|
147
|
+
}
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
before do
|
|
151
|
+
FauxIO.new { config.add_login(email, password, custom_options) }
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "does not alter the configuration" do
|
|
155
|
+
FauxIO.new do
|
|
156
|
+
expect {
|
|
157
|
+
config.add_login(email, password)
|
|
158
|
+
}.not_to change { config_file_contents }.from(original_config)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
expect(config_file_contents).to match("[#{email}]")
|
|
162
|
+
expect(config_file_contents).to match("api_url = #{custom_url}")
|
|
163
|
+
expect(config_file_contents).to match("username = #{email}")
|
|
164
|
+
expect(config_file_contents).to match("default_account = #{custom_default_account}")
|
|
165
|
+
expect(config_file_contents).to match("default_client = #{email}")
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "updates access token" do
|
|
169
|
+
FauxIO.new do
|
|
170
|
+
expect { config.add_login(email, password) }.to change {
|
|
171
|
+
config.access_token
|
|
172
|
+
}.from(cached_access_token(config))
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "updates refresh token" do
|
|
177
|
+
FauxIO.new do
|
|
178
|
+
expect { config.add_login(email, password) }.to change {
|
|
179
|
+
config.refresh_token
|
|
180
|
+
}.from(cached_refresh_token(config))
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context "when using an email and suffix", vcr: true do
|
|
186
|
+
let(:client_name) { "#{email}/dev" }
|
|
187
|
+
let(:expected_config) do
|
|
188
|
+
<<EOS
|
|
189
|
+
[core]
|
|
190
|
+
default_client = #{client_name}
|
|
191
|
+
|
|
192
|
+
[#{client_name}]
|
|
193
|
+
username = #{email}
|
|
194
|
+
api_url = #{api_url}
|
|
195
|
+
auth_url = #{api_url}
|
|
196
|
+
default_account = acc-12345
|
|
197
|
+
|
|
198
|
+
EOS
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
before do
|
|
202
|
+
remove_config
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it "creates the configuration" do
|
|
206
|
+
FauxIO.new do
|
|
207
|
+
config.add_login(client_name, password)
|
|
208
|
+
end
|
|
209
|
+
expect(config_file_contents).to eq(expected_config)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "refreshed tokens" do
|
|
213
|
+
FauxIO.new do
|
|
214
|
+
expect { config.add_login(email, password) }.not_to raise_error
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
expect(cached_access_token(config)).to eq(config.access_token)
|
|
218
|
+
expect(cached_refresh_token(config)).to eq(config.refresh_token)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|
|
@@ -56,39 +56,31 @@ describe Brightbox::BBConfig do
|
|
|
56
56
|
[cli-12345]
|
|
57
57
|
client_id = cli-12345
|
|
58
58
|
EOS
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
after do
|
|
63
|
-
@tmp_config.close
|
|
59
|
+
config_from_contents(contents)
|
|
64
60
|
end
|
|
65
61
|
|
|
66
62
|
context "and force_default_config is on" do
|
|
67
63
|
before do
|
|
68
64
|
config_opts = {
|
|
69
|
-
:directory => @tmp_config.path,
|
|
70
65
|
:force_default_config => true
|
|
71
66
|
}
|
|
72
67
|
@config = Brightbox::BBConfig.new(config_opts)
|
|
73
68
|
end
|
|
74
69
|
|
|
75
|
-
it "
|
|
76
|
-
expect
|
|
77
|
-
@config.client_name
|
|
78
|
-
end.to raise_error(Brightbox::BBConfigError, "You must specify a default client using brightbox config client_default")
|
|
70
|
+
it "returns nil" do
|
|
71
|
+
expect(@config.client_name).to be_nil
|
|
79
72
|
end
|
|
80
73
|
end
|
|
81
74
|
|
|
82
75
|
context "and force_default_config is off" do
|
|
83
76
|
before do
|
|
84
77
|
config_opts = {
|
|
85
|
-
:directory => @tmp_config.path,
|
|
86
78
|
:force_default_config => false
|
|
87
79
|
}
|
|
88
80
|
@config = Brightbox::BBConfig.new(config_opts)
|
|
89
81
|
end
|
|
90
82
|
|
|
91
|
-
it "returns
|
|
83
|
+
it "returns nil" do
|
|
92
84
|
expect(@config.client_name).to be_nil
|
|
93
85
|
end
|
|
94
86
|
end
|
|
@@ -26,8 +26,11 @@ describe Brightbox::BBConfig do
|
|
|
26
26
|
|
|
27
27
|
context "when directory does not exist" do
|
|
28
28
|
it "returns false" do
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
# Create a tmpdir and delete it so we are sure it should not exist
|
|
30
|
+
Dir.mktmpdir { |dir| @dir = dir }
|
|
31
|
+
expect(config.config_directory).to eq(@dir)
|
|
32
|
+
Dir.rmdir(@dir) if Dir.exist?(@dir)
|
|
33
|
+
expect(config.config_directory_exists?).to eq(false)
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
end
|
|
@@ -13,13 +13,15 @@ describe Brightbox::BBConfig do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
context "when absolute custom location is set" do
|
|
16
|
+
let(:custom_dir) { Dir.mktmpdir("custom") }
|
|
17
|
+
|
|
16
18
|
it "returns a String of the expanded directory" do
|
|
17
19
|
config_options = {
|
|
18
|
-
:directory =>
|
|
20
|
+
:directory => custom_dir
|
|
19
21
|
}
|
|
20
22
|
config = Brightbox::BBConfig.new(config_options)
|
|
21
23
|
|
|
22
|
-
expect(config.config_directory).to eql(
|
|
24
|
+
expect(config.config_directory).to eql(custom_dir)
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
|
|
@@ -10,7 +10,6 @@ describe Brightbox::BBConfig do
|
|
|
10
10
|
Dir.mktmpdir do |tmp_dir|
|
|
11
11
|
target_dir = File.join(tmp_dir, "config")
|
|
12
12
|
@config = Brightbox::BBConfig.new :directory => target_dir
|
|
13
|
-
expect(@config.config_directory_exists?).to be false
|
|
14
13
|
example.run
|
|
15
14
|
end
|
|
16
15
|
end
|
|
@@ -62,21 +61,18 @@ describe Brightbox::BBConfig do
|
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
context "when config file can not be parsed" do
|
|
65
|
-
|
|
64
|
+
it "raises an error" do
|
|
66
65
|
Dir.mktmpdir do |target_dir|
|
|
67
66
|
test_config_filename = File.join(target_dir, "config")
|
|
68
67
|
File.open(test_config_filename, "w") do |f|
|
|
69
68
|
f.puts "not:ini"
|
|
70
69
|
end
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
expect {
|
|
72
|
+
@config = Brightbox::BBConfig.new :directory => target_dir
|
|
73
|
+
}.to raise_error(Brightbox::BBConfigError)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
-
|
|
77
|
-
it "raises an error" do
|
|
78
|
-
expect { @config.config }.to raise_error(Brightbox::BBConfigError)
|
|
79
|
-
end
|
|
80
76
|
end
|
|
81
77
|
end
|
|
82
78
|
end
|
|
@@ -43,13 +43,17 @@ describe Brightbox::BBConfig do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context "when set in config" do
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
let(:account_name) { "acc-ghj32" }
|
|
47
|
+
let(:client_name) { "app-b3n5b" }
|
|
48
|
+
|
|
49
|
+
let(:contents) do
|
|
50
|
+
<<-EOS
|
|
51
|
+
[#{client_name}]
|
|
52
|
+
default_account = #{account_name}
|
|
52
53
|
EOS
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
before do
|
|
53
57
|
@config = config_from_contents(contents)
|
|
54
58
|
end
|
|
55
59
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Brightbox::BBConfig, "#section_names" do
|
|
4
|
+
subject(:config) { config_from_contents(ini) }
|
|
5
|
+
|
|
6
|
+
context "when no sections exist" do
|
|
7
|
+
let(:ini) { "" }
|
|
8
|
+
it { expect(config.section_names).to be_empty }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "when only a 'core' section exists" do
|
|
12
|
+
let(:ini) do
|
|
13
|
+
<<-EOS
|
|
14
|
+
[core]
|
|
15
|
+
setting = value
|
|
16
|
+
EOS
|
|
17
|
+
end
|
|
18
|
+
it { expect(config.section_names).to be_empty }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "when only an 'alias' section exists" do
|
|
22
|
+
let(:ini) do
|
|
23
|
+
<<-EOS
|
|
24
|
+
[alias]
|
|
25
|
+
setting = value
|
|
26
|
+
EOS
|
|
27
|
+
end
|
|
28
|
+
it { expect(config.section_names).to be_empty }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when multiple sections exist" do
|
|
32
|
+
let(:ini) do
|
|
33
|
+
<<-EOS
|
|
34
|
+
[core]
|
|
35
|
+
setting = value
|
|
36
|
+
|
|
37
|
+
[cli-12345]
|
|
38
|
+
setting = value
|
|
39
|
+
|
|
40
|
+
[app-12345]
|
|
41
|
+
setting = value
|
|
42
|
+
EOS
|
|
43
|
+
end
|
|
44
|
+
it { expect(config.section_names).to eq(%w(cli-12345 app-12345)) }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -2,20 +2,20 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Brightbox::BBConfig do
|
|
4
4
|
let(:api_client_id) { "cli-12345" }
|
|
5
|
-
let(:
|
|
6
|
-
let(:
|
|
5
|
+
let(:custom_app) { "app-54321" }
|
|
6
|
+
let(:username) { "jason.null@brightbox.com" }
|
|
7
7
|
|
|
8
8
|
let(:contents) do
|
|
9
9
|
<<-EOS
|
|
10
10
|
[#{api_client_id}]
|
|
11
11
|
client_id = #{api_client_id}
|
|
12
12
|
secret = #{random_token}
|
|
13
|
-
[#{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
client_id = #{user_app_two}
|
|
13
|
+
[#{username}]
|
|
14
|
+
username = #{username}
|
|
15
|
+
[#{custom_app}]
|
|
16
|
+
client_id = #{custom_app}
|
|
18
17
|
secret = #{random_token}
|
|
18
|
+
username = #{username}
|
|
19
19
|
EOS
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -36,7 +36,7 @@ describe Brightbox::BBConfig do
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context "when selected config is for a user application" do
|
|
39
|
-
let(:client_name) {
|
|
39
|
+
let(:client_name) { username }
|
|
40
40
|
|
|
41
41
|
it "returns true" do
|
|
42
42
|
config.client_name = client_name
|
|
@@ -54,7 +54,7 @@ describe Brightbox::BBConfig do
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
context "when selected config is for a user application with generic key" do
|
|
57
|
-
let(:client_name) {
|
|
57
|
+
let(:client_name) { custom_app }
|
|
58
58
|
|
|
59
59
|
it "returns true" do
|
|
60
60
|
config.client_name = client_name
|
|
@@ -69,7 +69,7 @@ describe Brightbox::BBConfig do
|
|
|
69
69
|
remove_config
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
it "
|
|
72
|
+
it "raises an error" do
|
|
73
73
|
expect do
|
|
74
74
|
Brightbox::BBConfig.new.using_api_client?
|
|
75
75
|
end.to raise_error(Brightbox::NoSelectedClientError, error_message)
|
|
@@ -77,7 +77,7 @@ describe Brightbox::BBConfig do
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
context "when selected config is for a user application" do
|
|
80
|
-
let(:client_name) {
|
|
80
|
+
let(:client_name) { username }
|
|
81
81
|
|
|
82
82
|
it "returns false" do
|
|
83
83
|
config.client_name = client_name
|
|
@@ -95,7 +95,7 @@ describe Brightbox::BBConfig do
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
context "when selected config is for a user application with generic key" do
|
|
98
|
-
let(:client_name) {
|
|
98
|
+
let(:client_name) { custom_app }
|
|
99
99
|
|
|
100
100
|
it "returns false" do
|
|
101
101
|
config.client_name = client_name
|
|
@@ -9,7 +9,6 @@ describe Brightbox::BBConfig do
|
|
|
9
9
|
it { expect(config).to respond_to(:config_directory) }
|
|
10
10
|
it { expect(config).to respond_to(:config_filename) }
|
|
11
11
|
it { expect(config).to respond_to(:delete_section) }
|
|
12
|
-
it { expect(config).to respond_to(:clients) }
|
|
13
12
|
it { expect(config).to respond_to(:client_name) }
|
|
14
13
|
it { expect(config).to respond_to(:access_token_filename) }
|
|
15
14
|
it { expect(config).to respond_to(:refresh_token_filename) }
|
|
@@ -11,13 +11,11 @@ describe Brightbox::Config::UserApplication do
|
|
|
11
11
|
subject(:for_fog) { section.to_fog }
|
|
12
12
|
|
|
13
13
|
describe "#to_fog" do
|
|
14
|
-
context "when config is
|
|
14
|
+
context "when config is using embedded client" do
|
|
15
15
|
let(:contents) do
|
|
16
16
|
<<-EOS
|
|
17
17
|
[#{client_name}]
|
|
18
18
|
api_url = http://api.brightbox.dev
|
|
19
|
-
client_id = #{client_name}
|
|
20
|
-
secret = #{secret}
|
|
21
19
|
username = user@example.com
|
|
22
20
|
EOS
|
|
23
21
|
end
|
|
@@ -35,11 +33,11 @@ describe Brightbox::Config::UserApplication do
|
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
it "sets client_id correctly" do
|
|
38
|
-
expect(for_fog[:brightbox_client_id]).to eql(
|
|
36
|
+
expect(for_fog[:brightbox_client_id]).to eql(Brightbox::EMBEDDED_APP_ID)
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
it "sets secret correctly" do
|
|
42
|
-
expect(for_fog[:brightbox_secret]).to eql(
|
|
40
|
+
expect(for_fog[:brightbox_secret]).to eql(Brightbox::EMBEDDED_APP_SECRET)
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
it "sets persistent correctly" do
|
|
@@ -47,86 +45,92 @@ describe Brightbox::Config::UserApplication do
|
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
context "when config
|
|
48
|
+
context "when config is using custom client" do
|
|
51
49
|
let(:contents) do
|
|
52
50
|
<<-EOS
|
|
53
51
|
[#{client_name}]
|
|
54
52
|
api_url = http://api.brightbox.dev
|
|
55
|
-
auth_url = http://auth.dev.brightbox.com
|
|
56
53
|
client_id = #{client_name}
|
|
57
54
|
secret = #{secret}
|
|
58
55
|
username = user@example.com
|
|
59
56
|
EOS
|
|
60
57
|
end
|
|
61
58
|
|
|
59
|
+
it "sets provider as 'Brightbox'" do
|
|
60
|
+
expect(for_fog[:provider]).to eql("Brightbox")
|
|
61
|
+
end
|
|
62
|
+
|
|
62
63
|
it "sets API endpoint correctly" do
|
|
63
64
|
expect(for_fog[:brightbox_api_url]).to eql("http://api.brightbox.dev")
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
it "copies API endpoint for auth endpoint correctly" do
|
|
67
|
-
expect(for_fog[:brightbox_auth_url]).to eql("http://
|
|
68
|
+
expect(for_fog[:brightbox_auth_url]).to eql("http://api.brightbox.dev")
|
|
68
69
|
end
|
|
69
|
-
end
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
secret = #{secret}
|
|
78
|
-
username = user@example.com
|
|
79
|
-
persistent = false
|
|
80
|
-
EOS
|
|
71
|
+
it "sets client_id correctly" do
|
|
72
|
+
expect(for_fog[:brightbox_client_id]).to eql(client_name)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "sets secret correctly" do
|
|
76
|
+
expect(for_fog[:brightbox_secret]).to eql(secret)
|
|
81
77
|
end
|
|
82
78
|
|
|
83
79
|
it "sets persistent correctly" do
|
|
84
|
-
expect(for_fog[:persistent]).to be
|
|
80
|
+
expect(for_fog[:persistent]).to be true
|
|
85
81
|
end
|
|
86
82
|
end
|
|
87
83
|
|
|
88
|
-
context "when config
|
|
84
|
+
context "when config has alternative auth endpoint" do
|
|
89
85
|
let(:contents) do
|
|
90
86
|
<<-EOS
|
|
91
87
|
[#{client_name}]
|
|
88
|
+
api_url = http://api.brightbox.dev
|
|
89
|
+
auth_url = http://auth.dev.brightbox.com
|
|
92
90
|
client_id = #{client_name}
|
|
93
91
|
secret = #{secret}
|
|
94
92
|
username = user@example.com
|
|
95
93
|
EOS
|
|
96
94
|
end
|
|
97
95
|
|
|
98
|
-
it "
|
|
99
|
-
expect
|
|
96
|
+
it "sets API endpoint correctly" do
|
|
97
|
+
expect(for_fog[:brightbox_api_url]).to eql("http://api.brightbox.dev")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "copies API endpoint for auth endpoint correctly" do
|
|
101
|
+
expect(for_fog[:brightbox_auth_url]).to eql("http://auth.dev.brightbox.com")
|
|
100
102
|
end
|
|
101
103
|
end
|
|
102
104
|
|
|
103
|
-
context "when config
|
|
105
|
+
context "when config has persistence setting" do
|
|
104
106
|
let(:contents) do
|
|
105
107
|
<<-EOS
|
|
106
108
|
[#{client_name}]
|
|
107
109
|
api_url = http://api.brightbox.dev
|
|
110
|
+
client_id = #{client_name}
|
|
108
111
|
secret = #{secret}
|
|
109
112
|
username = user@example.com
|
|
113
|
+
persistent = false
|
|
110
114
|
EOS
|
|
111
115
|
end
|
|
112
116
|
|
|
113
|
-
it "
|
|
114
|
-
expect
|
|
117
|
+
it "sets persistent correctly" do
|
|
118
|
+
expect(for_fog[:persistent]).to be false
|
|
115
119
|
end
|
|
116
120
|
end
|
|
117
121
|
|
|
118
|
-
context "when config is missing
|
|
122
|
+
context "when config is missing api_url" do
|
|
119
123
|
let(:contents) do
|
|
120
124
|
<<-EOS
|
|
121
125
|
[#{client_name}]
|
|
122
|
-
api_url = http://api.brightbox.dev
|
|
123
126
|
client_id = #{client_name}
|
|
127
|
+
secret = #{secret}
|
|
124
128
|
username = user@example.com
|
|
125
129
|
EOS
|
|
126
130
|
end
|
|
127
131
|
|
|
128
132
|
it "raises error" do
|
|
129
|
-
expect { section.to_fog }.to raise_error(Brightbox::BBConfigError, "
|
|
133
|
+
expect { section.to_fog }.to raise_error(Brightbox::BBConfigError, "api_url option missing from config in section app-12345")
|
|
130
134
|
end
|
|
131
135
|
end
|
|
132
136
|
|