brightbox-cli 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/Gemfile.lock +5 -2
  4. data/brightbox-cli.gemspec +1 -1
  5. data/lib/brightbox/cli/config.rb +19 -0
  6. data/lib/brightbox-cli/accounts.rb +2 -2
  7. data/lib/brightbox-cli/api.rb +4 -4
  8. data/lib/brightbox-cli/commands/accounts/default.rb +1 -1
  9. data/lib/brightbox-cli/commands/accounts/list.rb +1 -1
  10. data/lib/brightbox-cli/commands/config/client-add.rb +2 -2
  11. data/lib/brightbox-cli/commands/config/client-default.rb +3 -3
  12. data/lib/brightbox-cli/commands/config/client-list.rb +6 -6
  13. data/lib/brightbox-cli/commands/config/client-remove.rb +4 -4
  14. data/lib/brightbox-cli/commands/config/user-add.rb +2 -2
  15. data/lib/brightbox-cli/commands/login.rb +53 -0
  16. data/lib/brightbox-cli/config/accounts.rb +5 -0
  17. data/lib/brightbox-cli/config/authentication_tokens.rb +10 -3
  18. data/lib/brightbox-cli/config/cache.rb +8 -12
  19. data/lib/brightbox-cli/config/clients.rb +14 -38
  20. data/lib/brightbox-cli/config/sections.rb +70 -13
  21. data/lib/brightbox-cli/config/user_application.rb +13 -5
  22. data/lib/brightbox-cli/config.rb +22 -14
  23. data/lib/brightbox-cli/connection_manager.rb +2 -2
  24. data/lib/brightbox-cli/gli_global_hooks.rb +25 -28
  25. data/lib/brightbox-cli/version.rb +1 -1
  26. data/lib/brightbox_cli.rb +4 -0
  27. data/spec/cassettes/Brightbox_BBConfig/_add_section/when_config_exists_and_overwrite_duplicates_is_false/does_not_update_the_config_file.yml +199 -0
  28. data/spec/cassettes/Brightbox_BBConfig/_add_section/when_config_exists_and_overwrite_duplicates_is_true/does_not_update_the_config_file.yml +199 -0
  29. data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/does_not_alter_the_configuration.yml +99 -0
  30. data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/updates_access_token.yml +99 -0
  31. data/spec/cassettes/Brightbox_BBConfig_add_login/when_altering_a_custom_option/updates_refresh_token.yml +99 -0
  32. data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/does_not_alter_the_configuration.yml +99 -0
  33. data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/updates_access_token.yml +99 -0
  34. data/spec/cassettes/Brightbox_BBConfig_add_login/when_configured_with_custom_options/updates_refresh_token.yml +99 -0
  35. data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/does_not_alter_the_configuration.yml +149 -0
  36. data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/updates_access_token.yml +149 -0
  37. data/spec/cassettes/Brightbox_BBConfig_add_login/when_logged_in_previously/updates_refresh_token.yml +149 -0
  38. data/spec/cassettes/Brightbox_BBConfig_add_login/when_no_config_exists/creates_the_configuration.yml +101 -0
  39. data/spec/cassettes/Brightbox_BBConfig_add_login/when_no_config_exists/refreshed_tokens.yml +101 -0
  40. data/spec/cassettes/Brightbox_BBConfig_add_login/when_using_an_email_and_suffix/creates_the_configuration.yml +101 -0
  41. data/spec/cassettes/Brightbox_BBConfig_add_login/when_using_an_email_and_suffix/refreshed_tokens.yml +101 -0
  42. data/spec/cassettes/brightbox_accounts/list/_when_access_token_expired_/does_not_report_invalid_token_errors.yml +64 -18
  43. data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_/does_not_report_invalid_token_errors.yml +62 -16
  44. data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_error.yml +101 -0
  45. data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_prompt_to_rerun_the_command.yml +101 -0
  46. data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/prompts_for_the_password.yml +101 -0
  47. data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/requests_access_tokens.yml +101 -0
  48. data/spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/sets_up_the_config.yml +101 -0
  49. data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/does_not_error.yml +101 -0
  50. data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/does_not_prompt_to_rerun_the_command.yml +101 -0
  51. data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/prompts_for_the_password.yml +101 -0
  52. data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/requests_access_tokens.yml +101 -0
  53. data/spec/cassettes/brightbox_login/when_custom_api/auth_URLs_are_given/sets_up_the_config.yml +101 -0
  54. data/spec/cassettes/brightbox_login/when_default_account_is_passed/does_not_error.yml +51 -0
  55. data/spec/cassettes/brightbox_login/when_default_account_is_passed/does_not_prompt_to_rerun_the_command.yml +51 -0
  56. data/spec/cassettes/brightbox_login/when_default_account_is_passed/prompts_for_the_password.yml +51 -0
  57. data/spec/cassettes/brightbox_login/when_default_account_is_passed/requests_access_tokens.yml +51 -0
  58. data/spec/cassettes/brightbox_login/when_default_account_is_passed/sets_up_the_config.yml +51 -0
  59. data/spec/cassettes/brightbox_login/when_no_config_is_present/does_not_error.yml +101 -0
  60. data/spec/cassettes/brightbox_login/when_no_config_is_present/does_not_prompt_to_rerun_the_command.yml +101 -0
  61. data/spec/cassettes/brightbox_login/when_no_config_is_present/requests_access_tokens.yml +101 -0
  62. data/spec/cassettes/brightbox_login/when_no_config_is_present/sets_up_the_config.yml +101 -0
  63. data/spec/cassettes/brightbox_login/when_no_password_is_given/does_not_error.yml +101 -0
  64. data/spec/cassettes/brightbox_login/when_no_password_is_given/does_not_prompt_to_rerun_the_command.yml +101 -0
  65. data/spec/cassettes/brightbox_login/when_no_password_is_given/prompts_for_the_password.yml +101 -0
  66. data/spec/cassettes/brightbox_login/when_no_password_is_given/requests_access_tokens.yml +101 -0
  67. data/spec/cassettes/brightbox_login/when_no_password_is_given/sets_up_the_config.yml +101 -0
  68. data/spec/commands/accounts/list_spec.rb +1 -0
  69. data/spec/commands/login_spec.rb +239 -0
  70. data/spec/configs/user_app.ini +0 -2
  71. data/spec/spec_helper.rb +1 -0
  72. data/spec/support/config_helpers.rb +5 -0
  73. data/spec/unit/brightbox/account/all_spec.rb +1 -3
  74. data/spec/unit/brightbox/api/conn_spec.rb +3 -0
  75. data/spec/unit/brightbox/api/find_spec.rb +3 -0
  76. data/spec/unit/brightbox/bb_config/account_spec.rb +2 -0
  77. data/spec/unit/brightbox/bb_config/add_login_spec.rb +222 -0
  78. data/spec/unit/brightbox/bb_config/client_name_spec.rb +4 -12
  79. data/spec/unit/brightbox/bb_config/client_named_spec.rb +1 -1
  80. data/spec/unit/brightbox/bb_config/config_directory_exists_spec.rb +5 -2
  81. data/spec/unit/brightbox/bb_config/config_directory_spec.rb +4 -2
  82. data/spec/unit/brightbox/bb_config/config_spec.rb +4 -8
  83. data/spec/unit/brightbox/bb_config/default_account_spec.rb +10 -6
  84. data/spec/unit/brightbox/bb_config/find_or_set_default_account_spec.rb +2 -0
  85. data/spec/unit/brightbox/bb_config/renew_tokens_spec.rb +3 -0
  86. data/spec/unit/brightbox/bb_config/section_names_spec.rb +46 -0
  87. data/spec/unit/brightbox/bb_config/using_client_spec.rb +12 -12
  88. data/spec/unit/brightbox/bb_config_spec.rb +0 -1
  89. data/spec/unit/brightbox/cloud_ip/find_spec.rb +3 -0
  90. data/spec/unit/brightbox/config/user_application/to_fog_spec.rb +33 -29
  91. data/spec/unit/brightbox/config/user_application/valid_spec.rb +0 -32
  92. data/spec/unit/brightbox/connection_manager/fetch_connection_spec.rb +7 -3
  93. data/spec/unit/brightbox/firewall_policy/apply_to_spec.rb +3 -0
  94. data/spec/unit/brightbox/firewall_policy/create_spec.rb +3 -0
  95. data/spec/unit/brightbox/firewall_policy/destroy_spec.rb +3 -0
  96. data/spec/unit/brightbox/firewall_policy/find_or_call_spec.rb +3 -0
  97. data/spec/unit/brightbox/firewall_policy/find_spec.rb +3 -0
  98. data/spec/unit/brightbox/firewall_rule/create_spec.rb +3 -0
  99. data/spec/unit/brightbox/firewall_rule/destroy_spec.rb +3 -0
  100. data/spec/unit/brightbox/firewall_rule/find_spec.rb +3 -0
  101. data/spec/unit/brightbox/firewall_rule/from_policy_spec.rb +3 -0
  102. data/spec/unit/brightbox/server/destroy_spec.rb +4 -0
  103. data/spec/unit/brightbox/server/find_or_call_spec.rb +3 -0
  104. data/spec/unit/brightbox/server/find_spec.rb +4 -0
  105. data/spec/unit/brightbox/server/shutdown_spec.rb +4 -0
  106. data/spec/unit/brightbox/server/start_spec.rb +4 -0
  107. data/spec/unit/brightbox/server/stop_spec.rb +4 -0
  108. data/spec/unit/brightbox/server/update_spec.rb +4 -0
  109. data/spec/unit/brightbox/server_group/find_spec.rb +3 -0
  110. data/spec/unit/brightbox/user_collaboration/get_for_account_spec.rb +3 -0
  111. metadata +90 -3
@@ -0,0 +1,101 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.brightbox.dev/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"grant_type":"password","username":"jason.null@brightbox.com","password":"N:B3e%7Cmh"}'
9
+ headers:
10
+ User-Agent:
11
+ - fog-core/1.32.1
12
+ Authorization:
13
+ - Basic YXBwLTEyMzQ1Om1vY2J1aXBiaWFhNms2Yw==
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ Cache-Control:
24
+ - no-store
25
+ X-Oauth-Scopes:
26
+ - infrastructure, orbit
27
+ Content-Length:
28
+ - '190'
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Ua-Compatible:
32
+ - IE=Edge
33
+ Etag:
34
+ - '"03a2f5ef6ee075450f1823c2eb312874"'
35
+ X-Request-Id:
36
+ - c18a04b5e0ecf421a517d40e66a7cf39
37
+ X-Runtime:
38
+ - '0.090494'
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/1.9.3/2014-11-13)
41
+ Date:
42
+ - Mon, 12 Oct 2015 14:53:51 GMT
43
+ Connection:
44
+ - Keep-Alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"access_token":"0e2b6ecb38dc7edeecd010fdbb130dc81eed3244","token_type":"Bearer","refresh_token":"84e7fbdaee8490c190fcadb0d6e514bb0dd28f7b","scope":"infrastructure,
48
+ orbit","expires_in":7200}'
49
+ http_version:
50
+ recorded_at: Mon, 12 Oct 2015 14:53:51 GMT
51
+ - request:
52
+ method: get
53
+ uri: http://api.brightbox.dev/1.0/accounts
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ User-Agent:
59
+ - fog-core/1.32.1
60
+ Authorization:
61
+ - Bearer 0e2b6ecb38dc7edeecd010fdbb130dc81eed3244
62
+ Content-Type:
63
+ - application/json
64
+ response:
65
+ status:
66
+ code: 200
67
+ message:
68
+ headers:
69
+ X-Oauth-Scopes:
70
+ - infrastructure, orbit
71
+ Content-Type:
72
+ - application/json; charset=utf-8
73
+ X-Ua-Compatible:
74
+ - IE=Edge
75
+ Etag:
76
+ - '"c9a269456e92ca15ff834e08ba6414ad"'
77
+ Cache-Control:
78
+ - max-age=0, private, must-revalidate
79
+ X-Request-Id:
80
+ - b4645084926cf99f30046e0441fbcf6f
81
+ X-Runtime:
82
+ - '0.048355'
83
+ Server:
84
+ - WEBrick/1.3.1 (Ruby/1.9.3/2014-11-13)
85
+ Date:
86
+ - Mon, 12 Oct 2015 14:53:51 GMT
87
+ Content-Length:
88
+ - '1611'
89
+ Connection:
90
+ - Keep-Alive
91
+ body:
92
+ encoding: UTF-8
93
+ string: '[{"id":"acc-12345","resource_type":"account","url":"https://api.gb1.brightbox.com/1.0/accounts/acc-12345","name":"CLI
94
+ test account","status":"active","ram_limit":3200000,"ram_used":0,"dbs_ram_limit":32768,"dbs_ram_used":0,"cloud_ips_limit":32,"cloud_ips_used":0,"load_balancers_limit":5,"load_balancers_used":0,"clients":[{"id":"cli-12345","resource_type":"api_client","url":"https://api.gb1.brightbox.com/1.0/api_clients/cli-12345","name":"CLI
95
+ test API client","description":"","revoked_at":null,"permissions_group":"full"}],"images":[],"servers":[],"load_balancers":[],"database_servers":[],"database_snapshots":[],"cloud_ips":[],"server_groups":[{"id":"grp-12345","resource_type":"server_group","url":"https://api.gb1.brightbox.com/1.0/server_groups/grp-12345","name":"default","description":"All
96
+ new servers are added to this group unless specified otherwise.","created_at":"2015-10-12T09:23:03Z","default":true}],"firewall_policies":[{"id":"fwp-12345","resource_type":"firewall_policy","url":"https://api.gb1.brightbox.com/1.0/firewall_policies/fwp-12345","default":true,"name":"default","created_at":"2015-10-12T09:23:03Z","description":"Applied
97
+ to the default server group."}],"owner":{"id":"usr-12345","resource_type":"user","url":"https://api.gb1.brightbox.com/1.0/users/usr-12345","name":"Jason
98
+ Null","email_address":"jason.null@brightbox.com"},"users":[],"zones":[{"id":"zon-12345","resource_type":"zone","url":"https://api.gb1.brightbox.com/1.0/zones/zon-12345","handle":"gb1-a"},{"id":"zon-12345","resource_type":"zone","url":"https://api.gb1.brightbox.com/1.0/zones/zon-12345","handle":"gb1-b"}]}]'
99
+ http_version:
100
+ recorded_at: Mon, 12 Oct 2015 14:53:51 GMT
101
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,101 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.brightbox.dev/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"grant_type":"password","username":"jason.null@brightbox.com","password":"N:B3e%7Cmh"}'
9
+ headers:
10
+ User-Agent:
11
+ - fog-core/1.32.1
12
+ Authorization:
13
+ - Basic YXBwLTEyMzQ1Om1vY2J1aXBiaWFhNms2Yw==
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ Cache-Control:
24
+ - no-store
25
+ X-Oauth-Scopes:
26
+ - infrastructure, orbit
27
+ Content-Length:
28
+ - '190'
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ X-Ua-Compatible:
32
+ - IE=Edge
33
+ Etag:
34
+ - '"d942cf5e51cc86fde5b2a75984557ca9"'
35
+ X-Request-Id:
36
+ - 41f8efe24820a636ee030168b905eb90
37
+ X-Runtime:
38
+ - '0.087310'
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/1.9.3/2014-11-13)
41
+ Date:
42
+ - Mon, 12 Oct 2015 14:53:51 GMT
43
+ Connection:
44
+ - Keep-Alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"access_token":"b07faf14eafa2fd510bb7ef94aff0acfaaa3c70f","token_type":"Bearer","refresh_token":"83aa5702840aba673845a9b9bd35421065eb4d8f","scope":"infrastructure,
48
+ orbit","expires_in":7200}'
49
+ http_version:
50
+ recorded_at: Mon, 12 Oct 2015 14:53:51 GMT
51
+ - request:
52
+ method: get
53
+ uri: http://api.brightbox.dev/1.0/accounts
54
+ body:
55
+ encoding: US-ASCII
56
+ string: ''
57
+ headers:
58
+ User-Agent:
59
+ - fog-core/1.32.1
60
+ Authorization:
61
+ - Bearer b07faf14eafa2fd510bb7ef94aff0acfaaa3c70f
62
+ Content-Type:
63
+ - application/json
64
+ response:
65
+ status:
66
+ code: 200
67
+ message:
68
+ headers:
69
+ X-Oauth-Scopes:
70
+ - infrastructure, orbit
71
+ Content-Type:
72
+ - application/json; charset=utf-8
73
+ X-Ua-Compatible:
74
+ - IE=Edge
75
+ Etag:
76
+ - '"c9a269456e92ca15ff834e08ba6414ad"'
77
+ Cache-Control:
78
+ - max-age=0, private, must-revalidate
79
+ X-Request-Id:
80
+ - b168c47f4374123523356a9760242b31
81
+ X-Runtime:
82
+ - '0.127805'
83
+ Server:
84
+ - WEBrick/1.3.1 (Ruby/1.9.3/2014-11-13)
85
+ Date:
86
+ - Mon, 12 Oct 2015 14:53:51 GMT
87
+ Content-Length:
88
+ - '1611'
89
+ Connection:
90
+ - Keep-Alive
91
+ body:
92
+ encoding: UTF-8
93
+ string: '[{"id":"acc-12345","resource_type":"account","url":"https://api.gb1.brightbox.com/1.0/accounts/acc-12345","name":"CLI
94
+ test account","status":"active","ram_limit":3200000,"ram_used":0,"dbs_ram_limit":32768,"dbs_ram_used":0,"cloud_ips_limit":32,"cloud_ips_used":0,"load_balancers_limit":5,"load_balancers_used":0,"clients":[{"id":"cli-12345","resource_type":"api_client","url":"https://api.gb1.brightbox.com/1.0/api_clients/cli-12345","name":"CLI
95
+ test API client","description":"","revoked_at":null,"permissions_group":"full"}],"images":[],"servers":[],"load_balancers":[],"database_servers":[],"database_snapshots":[],"cloud_ips":[],"server_groups":[{"id":"grp-12345","resource_type":"server_group","url":"https://api.gb1.brightbox.com/1.0/server_groups/grp-12345","name":"default","description":"All
96
+ new servers are added to this group unless specified otherwise.","created_at":"2015-10-12T09:23:03Z","default":true}],"firewall_policies":[{"id":"fwp-12345","resource_type":"firewall_policy","url":"https://api.gb1.brightbox.com/1.0/firewall_policies/fwp-12345","default":true,"name":"default","created_at":"2015-10-12T09:23:03Z","description":"Applied
97
+ to the default server group."}],"owner":{"id":"usr-12345","resource_type":"user","url":"https://api.gb1.brightbox.com/1.0/users/usr-12345","name":"Jason
98
+ Null","email_address":"jason.null@brightbox.com"},"users":[],"zones":[{"id":"zon-12345","resource_type":"zone","url":"https://api.gb1.brightbox.com/1.0/zones/zon-12345","handle":"gb1-a"},{"id":"zon-12345","resource_type":"zone","url":"https://api.gb1.brightbox.com/1.0/zones/zon-12345","handle":"gb1-b"}]}]'
99
+ http_version:
100
+ recorded_at: Mon, 12 Oct 2015 14:53:51 GMT
101
+ recorded_with: VCR 2.5.0
@@ -60,6 +60,7 @@ describe "brightbox accounts" do
60
60
 
61
61
  before do
62
62
  config = config_from_contents(USER_APP_CONFIG_CONTENTS)
63
+ #mock_password_entry(password)
63
64
 
64
65
  # Setup in the VCR recordings as the access token is expired
65
66
  cache_access_token(config, "08f204123bb2fc400521577445df9d1d212da42e")
@@ -0,0 +1,239 @@
1
+ require "spec_helper"
2
+
3
+ describe "brightbox login" do
4
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
5
+ let(:stdout) { output.stdout }
6
+ let(:stderr) { output.stderr }
7
+
8
+ let(:email) { "jason.null@brightbox.com" }
9
+ let(:password) { "N:B3e%7Cmh" }
10
+ let(:client_id) { "app-12345" }
11
+ let(:secret) { "mocbuipbiaa6k6c" }
12
+ let(:api_url) { "http://api.brightbox.dev" }
13
+
14
+ let(:default_account) { "acc-12345" }
15
+ let(:client_alias) { email }
16
+
17
+ context "when no arguments are given" do
18
+ let(:argv) { %w(login) }
19
+
20
+ it "errors prompting for the email address" do
21
+ remove_config
22
+ expect(stderr).to include("You must specify your email address")
23
+ end
24
+ end
25
+
26
+ context "when no config is present", vcr: true do
27
+ let(:argv) { ["login", "-p", password, email] }
28
+
29
+ before do
30
+ remove_config
31
+ end
32
+
33
+ it "does not error" do
34
+ expect { output }.to_not raise_error
35
+ expect(stderr).to_not include("ERROR")
36
+ end
37
+
38
+ it "sets up the config" do
39
+ expect { output }.to_not raise_error
40
+
41
+ @config = Brightbox::BBConfig.new
42
+ @client_section = @config.config[email]
43
+
44
+ expect(@client_section["api_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
45
+ expect(@client_section["username"]).to eql(email)
46
+ expect(@client_section["default_account"]).to eql(default_account)
47
+ end
48
+
49
+ it "requests access tokens" do
50
+ expect { output }.to_not raise_error
51
+
52
+ @config = Brightbox::BBConfig.new :client_name => email
53
+
54
+ expect(cached_access_token(@config)).to eql(@config.access_token)
55
+ expect(cached_refresh_token(@config)).to eql(@config.refresh_token)
56
+ end
57
+
58
+ it "does not prompt to rerun the command" do
59
+ expect(stderr).to_not include("please re-run your command")
60
+ end
61
+ end
62
+
63
+ context "when no password is given", vcr: true do
64
+ let(:argv) { ["login", email] }
65
+
66
+ before do
67
+ remove_config
68
+ mock_password_entry(password)
69
+ end
70
+
71
+ it "prompts for the password" do
72
+ expect { output }.not_to raise_error
73
+ end
74
+
75
+ it "does not error" do
76
+ expect { output }.to_not raise_error
77
+ expect(stderr).to_not include("ERROR")
78
+ end
79
+
80
+ it "sets up the config" do
81
+ expect { output }.to_not raise_error
82
+
83
+ @config = Brightbox::BBConfig.new
84
+ @client_section = @config.config[email]
85
+
86
+ expect(@client_section["api_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
87
+ expect(@client_section["username"]).to eql(email)
88
+ expect(@client_section["default_account"]).to eql(default_account)
89
+ end
90
+
91
+ it "requests access tokens" do
92
+ expect { output }.to_not raise_error
93
+
94
+ @config = Brightbox::BBConfig.new :client_name => email
95
+
96
+ expect(cached_access_token(@config)).to eql(@config.access_token)
97
+ expect(cached_refresh_token(@config)).to eql(@config.refresh_token)
98
+ end
99
+
100
+ it "does not prompt to rerun the command" do
101
+ expect(stderr).to_not include("please re-run your command")
102
+ end
103
+ end
104
+
105
+ context "when custom api/auth URLs are given", vcr: true do
106
+ # FIXME: These need to be the "real" defaults to record the token interchange
107
+ # May allow a regression that the defaults are used, not the passed argument
108
+ # Need to use something better that VCR.
109
+ let(:api_url) { Brightbox::DEFAULT_API_ENDPOINT }
110
+ let(:auth_url) { Brightbox::DEFAULT_API_ENDPOINT }
111
+ let(:argv) { ["login", "--api-url", api_url, "--auth-url", auth_url, email] }
112
+
113
+ before do
114
+ remove_config
115
+ mock_password_entry(password)
116
+ end
117
+
118
+ it "prompts for the password" do
119
+ expect { output }.not_to raise_error
120
+ end
121
+
122
+ it "does not error" do
123
+ expect { output }.to_not raise_error
124
+ expect(stderr).to_not include("ERROR")
125
+ end
126
+
127
+ it "sets up the config" do
128
+ expect { output }.to_not raise_error
129
+
130
+ @config = Brightbox::BBConfig.new
131
+ @client_section = @config.config[email]
132
+
133
+ expect(@client_section["api_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
134
+ expect(@client_section["auth_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
135
+ expect(@client_section["username"]).to eql(email)
136
+ expect(@client_section["default_account"]).to eql(default_account)
137
+ end
138
+
139
+ it "requests access tokens" do
140
+ expect { output }.to_not raise_error
141
+
142
+ @config = Brightbox::BBConfig.new :client_name => email
143
+
144
+ expect(cached_access_token(@config)).to eql(@config.access_token)
145
+ expect(cached_refresh_token(@config)).to eql(@config.refresh_token)
146
+ end
147
+
148
+ it "does not prompt to rerun the command" do
149
+ expect(stderr).to_not include("please re-run your command")
150
+ end
151
+ end
152
+
153
+ context "when default account is passed", vcr: true do
154
+ let(:account) { "acc-23456" }
155
+ let(:argv) { ["login", "--default-account", account, email] }
156
+
157
+ before do
158
+ remove_config
159
+ mock_password_entry(password)
160
+ end
161
+
162
+ it "prompts for the password" do
163
+ expect { output }.not_to raise_error
164
+ end
165
+
166
+ it "does not error" do
167
+ expect { output }.to_not raise_error
168
+ expect(stderr).to_not include("ERROR")
169
+ end
170
+
171
+ it "sets up the config" do
172
+ expect { output }.to_not raise_error
173
+
174
+ @config = Brightbox::BBConfig.new
175
+ @client_section = @config.config[email]
176
+
177
+ expect(@client_section["api_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
178
+ expect(@client_section["auth_url"]).to eql(Brightbox::DEFAULT_API_ENDPOINT)
179
+ expect(@client_section["username"]).to eql(email)
180
+ expect(@client_section["default_account"]).to eql(account)
181
+ end
182
+
183
+ it "requests access tokens" do
184
+ expect { output }.to_not raise_error
185
+
186
+ @config = Brightbox::BBConfig.new :client_name => email
187
+
188
+ expect(cached_access_token(@config)).to eql(@config.access_token)
189
+ expect(cached_refresh_token(@config)).to eql(@config.refresh_token)
190
+ end
191
+
192
+ it "does not prompt to rerun the command" do
193
+ expect(stderr).to_not include("please re-run your command")
194
+ end
195
+ end
196
+
197
+ context "when alternative client credentials are given", vcr: true do
198
+ let(:other_client_identifier) { "app-23456" }
199
+ let(:other_client_secret) { "ho04hondtzjjdf4" }
200
+ let(:argv) { ["login", "--application-id", other_client_identifier, "--application-secret", other_client_secret, email] }
201
+
202
+ before do
203
+ remove_config
204
+ mock_password_entry(password)
205
+ end
206
+
207
+ it "prompts for the password" do
208
+ expect { output }.not_to raise_error
209
+ end
210
+
211
+ it "does not error" do
212
+ expect { output }.to_not raise_error
213
+ expect(stderr).to_not include("ERROR")
214
+ end
215
+
216
+ it "sets up the config" do
217
+ expect { output }.to_not raise_error
218
+
219
+ @config = Brightbox::BBConfig.new
220
+ @client_section = @config.config[email]
221
+
222
+ expect(@client_section["client_id"]).to eql(other_client_identifier)
223
+ expect(@client_section["secret"]).to eql(other_client_secret)
224
+ end
225
+
226
+ it "requests access tokens" do
227
+ expect { output }.to_not raise_error
228
+
229
+ @config = Brightbox::BBConfig.new :client_name => email
230
+
231
+ expect(cached_access_token(@config)).to eql(@config.access_token)
232
+ expect(cached_refresh_token(@config)).to eql(@config.refresh_token)
233
+ end
234
+
235
+ it "does not prompt to rerun the command" do
236
+ expect(stderr).to_not include("please re-run your command")
237
+ end
238
+ end
239
+ end
@@ -3,8 +3,6 @@ default_client = testing
3
3
 
4
4
  [testing]
5
5
  alias = testing
6
- client_id = app-12345
7
- secret = mocbuipbiaa6k6c
8
6
  username = jason.null@brightbox.com
9
7
  api_url = http://api.brightbox.dev
10
8
  auth_url = http://api.brightbox.dev
data/spec/spec_helper.rb CHANGED
@@ -38,6 +38,7 @@ RSpec.configure do |config|
38
38
  config.around(:each) do |example|
39
39
  Dir.mktmpdir do |tmp_home|
40
40
  ENV["HOME"] = tmp_home
41
+ Brightbox.config = nil
41
42
  example.run
42
43
  ENV["HOME"] = TEST_RUNNER_HOME
43
44
  end
@@ -16,6 +16,11 @@ module ConfigHelpers
16
16
  f.write contents
17
17
  end
18
18
 
19
+ config = Brightbox::BBConfig.new
20
+
21
+ # Subvert the global
22
+ Brightbox.config = config
23
+
19
24
  config
20
25
  end
21
26
 
@@ -2,9 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Brightbox::Account do
4
4
  before do
5
- # Unfortunately need to change $config for Api.conn to work until we can
6
- # eliminate the global class method
7
- $config = config_from_contents(contents)
5
+ Brightbox.config = config_from_contents(contents)
8
6
  end
9
7
 
10
8
  describe ".all" do
@@ -1,6 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Brightbox::Api, ".conn" do
4
+ before do
5
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
6
+ end
4
7
 
5
8
  context "when account is not required", vcr: true do
6
9
  it "returns a 'real' fog compute instance" do
@@ -1,6 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Brightbox::Api, ".find" do
4
+ before do
5
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
6
+ end
4
7
 
5
8
  context "when passed nil" do
6
9
  it "raises an error" do
@@ -35,6 +35,8 @@ describe Brightbox::BBConfig do
35
35
  @account_name = "acc-ghj32"
36
36
  @client_name = "app-b3n5b"
37
37
  contents = <<-EOS
38
+ [core]
39
+ default_client = #{@client_name}
38
40
  [#{@client_name}]
39
41
  default_account = #{@account_name}
40
42
  EOS