fog-brightbox 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf3d66886dcbcc3b322d8d7cbc9d2d1b44e170b0
4
- data.tar.gz: 6b077cbd2c3247965692c8fa65da922d4d611817
3
+ metadata.gz: 8e284d72c08bde3b84dde44cd5eddf1cf54da198
4
+ data.tar.gz: 668a97efaef6e604174b3178eb3857fdd8e3d240
5
5
  SHA512:
6
- metadata.gz: 1adfefa1c678d7c4916d171a813c7b6de86e25bfcaf0c05e989de5994415ad60bf14f1fef8edd51e52867b4256d9302637a86e65e7f817af5c504b82002ded29
7
- data.tar.gz: 0d6033997d99c661ff1cdb81f147c2e32d5d883c0b794ec4f631dab4250be57717e066145d58ac2db5a2ce776f5b4a712a0287777488f2357241ca5c32770fb0
6
+ metadata.gz: f86b3f5e1f72d0f621e594b0eea69184b263cefde28891ccb12de854a2c634c9bbbd6e35b94438750f89ac3d174ad1af5c8fede4807699e4532abf346d4d7e8f
7
+ data.tar.gz: 0c4d0996fb3d7eb4670e8cdd01800dea3d81ee7472bb7f9992a98e0cda7a0f0ac2aba3e8a6071d806f6c218be3d4f0a70856ca4c74eba9ba77753b3c8ed0fac5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.5.1 / 2014-09-15
2
+
3
+ Bug fixes:
4
+
5
+ * Fix a possible authentication loop when bad credentials or expired tokens
6
+ would trigger repeated attempts to authenticate with no changes to the
7
+ bad credentials.
8
+
1
9
  ### 0.5.0 / 2014-09-01
2
10
 
3
11
  Enhancements:
@@ -15,8 +15,8 @@ module Fog
15
15
  self.access_token = response.headers["X-Auth-Token"]
16
16
  self.management_url = response.headers["X-Server-Management-Url"] || response.headers["X-Storage-Url"]
17
17
  self
18
- rescue Excon::Errors::Error
19
- nil
18
+ rescue Excon::Errors::Unauthorized => error
19
+ raise Fog::Brightbox::Storage::AuthenticationRequired.slurp(error)
20
20
  end
21
21
 
22
22
  private
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Brightbox
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@ require "webmock/minitest"
3
3
  require "fog/brightbox"
4
4
 
5
5
  describe Fog::Brightbox::Storage::AuthenticationRequest do
6
+ include StockStorageResponses
7
+
6
8
  describe "when initialised with blank config" do
7
9
  before do
8
10
  stub_request(:get, "https://orbit.brightbox.com/v1").
@@ -10,14 +12,14 @@ describe Fog::Brightbox::Storage::AuthenticationRequest do
10
12
  "Host" => "orbit.brightbox.com:443",
11
13
  "X-Auth-User" => "",
12
14
  "X-Auth-Key" => ""
13
- }).to_return(:status => 412, :body => "Bad URL", :headers => {})
15
+ }).to_return(bad_url_response)
14
16
  end
15
17
 
16
- it "fails" do
18
+ it "raises error" do
17
19
  settings = {}
18
20
  @config = Fog::Brightbox::Config.new(settings)
19
21
  @request = Fog::Brightbox::Storage::AuthenticationRequest.new(@config)
20
- refute @request.authenticate
22
+ assert_raises(Excon::Errors::PreconditionFailed) { @request.authenticate }
21
23
  end
22
24
  end
23
25
 
@@ -28,12 +30,7 @@ describe Fog::Brightbox::Storage::AuthenticationRequest do
28
30
  "Host" => "orbit.brightbox.com:443",
29
31
  "X-Auth-User" => "cli-12345",
30
32
  "X-Auth-Key" => "12345"
31
- }).to_return(:status => 200, :body => "Authenticated", :headers => {
32
- "X-Storage-Url" => "https://orbit.brightbox.com/v1/acc-12345",
33
- "X-Storage-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
34
- "X-Auth-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
35
- "Content-Type" => "text/plain"
36
- })
33
+ }).to_return(authorized_response)
37
34
  end
38
35
 
39
36
  it "authenticates correctly" do
@@ -54,12 +51,7 @@ describe Fog::Brightbox::Storage::AuthenticationRequest do
54
51
  "Host" => "orbit.brightbox.com:443",
55
52
  "X-Auth-User" => "user@example.com",
56
53
  "X-Auth-Key" => "abcde"
57
- }).to_return(:status => 200, :body => "Authenticated", :headers => {
58
- "X-Storage-Url" => "https://orbit.brightbox.com/v1/acc-12345",
59
- "X-Storage-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
60
- "X-Auth-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
61
- "Content-Type" => "text/plain"
62
- })
54
+ }).to_return(authorized_response)
63
55
  end
64
56
 
65
57
  it "authenticates correctly" do
@@ -74,4 +66,27 @@ describe Fog::Brightbox::Storage::AuthenticationRequest do
74
66
  assert @request.authenticate
75
67
  end
76
68
  end
69
+
70
+ describe "when initialised with bad user details" do
71
+ before do
72
+ stub_request(:get, "https://orbit.brightbox.com/v1").
73
+ with(:headers => {
74
+ "Host" => "orbit.brightbox.com:443",
75
+ "X-Auth-User" => "user@example.com",
76
+ "X-Auth-Key" => "abcde"
77
+ }).to_return(unauthorized_response)
78
+ end
79
+
80
+ it "raises error" do
81
+ settings = {
82
+ :brightbox_client_id => "app-12345",
83
+ :brightbox_secret => "12345",
84
+ :brightbox_username => "user@example.com",
85
+ :brightbox_password => "abcde"
86
+ }
87
+ @config = Fog::Brightbox::Config.new(settings)
88
+ @request = Fog::Brightbox::Storage::AuthenticationRequest.new(@config)
89
+ assert_raises(Fog::Brightbox::Storage::AuthenticationRequired) { @request.authenticate }
90
+ end
91
+ end
77
92
  end
@@ -3,21 +3,8 @@ require "webmock/minitest"
3
3
  require "fog/brightbox"
4
4
 
5
5
  describe Fog::Storage::Brightbox do
6
- let(:valid_auth_response) do
7
- {
8
- :status => 200,
9
- :body => "Authenticated",
10
- :headers => {
11
- "X-Storage-Url"=>"https://orbit.brightbox.com:443/v1/acc-12345",
12
- "Content-Length"=>"13",
13
- "X-Storage-Token"=>"c1236c8c34d668df497c06075d8a76a79c6fdd0d",
14
- "Content-Type"=>"text/plain",
15
- "X-Auth-Token"=>"c1236c8c34d668df497c06075d8a76a79c6fdd0d",
16
- "X-Trans-Id"=>"txcb228b8b9bfe4d5184828-0053568313",
17
- "Date"=>"Tue, 22 Apr 2014 14:56:20 GMT"
18
- }
19
- }
20
- end
6
+ include StockStorageResponses
7
+
21
8
  let(:config) { Fog::Brightbox::Config.new(settings) }
22
9
  let(:service) { Fog::Storage::Brightbox.new(config) }
23
10
 
@@ -64,7 +51,8 @@ describe Fog::Storage::Brightbox do
64
51
  end
65
52
 
66
53
  before do
67
- stub_request(:get, "https://orbit.brightbox.com/v1").to_return(valid_auth_response)
54
+ stub_request(:get, "https://orbit.brightbox.com/v1").
55
+ to_return(authorized_response)
68
56
  end
69
57
 
70
58
  it "requires a call to authenticate" do
@@ -90,18 +78,10 @@ describe Fog::Storage::Brightbox do
90
78
  end
91
79
 
92
80
  it "fails to authenticate" do
93
- response = {
94
- :body=>"Bad URL",
95
- :headers=>
96
- {"Content-Length"=>"7",
97
- "Content-Type"=>"text/html; charset=UTF-8",
98
- "X-Trans-Id"=>"txab03ff4864ff42989f4a1-0053568282",
99
- "Date"=>"Tue, 22 Apr 2014 14:53:54 GMT"},
100
- :status=>412
101
- }
102
- stub_request(:get, "https://orbit.brightbox.com/v1").to_return(response)
81
+ stub_request(:get, "https://orbit.brightbox.com/v1").
82
+ to_return(unauthorized_response)
103
83
 
104
- service.authenticate
84
+ assert_raises(Fog::Brightbox::Storage::AuthenticationRequired) { service.authenticate }
105
85
  assert_nil service.management_url
106
86
  end
107
87
  end
@@ -118,7 +98,8 @@ describe Fog::Storage::Brightbox do
118
98
  end
119
99
 
120
100
  before do
121
- stub_request(:get, "https://orbit.brightbox.com/v1").to_return(valid_auth_response)
101
+ stub_request(:get, "https://orbit.brightbox.com/v1").
102
+ to_return(authorized_response)
122
103
  end
123
104
 
124
105
  it "uses the configured account" do
@@ -138,7 +119,8 @@ describe Fog::Storage::Brightbox do
138
119
  end
139
120
 
140
121
  before do
141
- stub_request(:get, "https://orbit.brightbox.com/v1").to_return(valid_auth_response)
122
+ stub_request(:get, "https://orbit.brightbox.com/v1").
123
+ to_return(authorized_response)
142
124
  end
143
125
 
144
126
  it "extracts the account from the management URL" do
@@ -186,7 +168,8 @@ describe Fog::Storage::Brightbox do
186
168
  end
187
169
 
188
170
  it "keeps setting after authentication" do
189
- stub_request(:get, "https://orbit.brightbox.com/v1").to_return(valid_auth_response)
171
+ stub_request(:get, "https://orbit.brightbox.com/v1").
172
+ to_return(authorized_response)
190
173
  config.expire_tokens!
191
174
  service.authenticate
192
175
  assert_equal "https://files.gb2.brightbox.com/v1/acc-12345", service.management_url.to_s
@@ -208,9 +191,7 @@ describe Fog::Storage::Brightbox do
208
191
  before do
209
192
  # Ongoing request but tokens are expired
210
193
  stub_request(:get, "https://files.gb2.brightbox.com/v1/acc-12345/fnord").
211
- to_return(:status => 401,
212
- :body => "Authentication required",
213
- :headers => { "Content-Type" => "text/plain" })
194
+ to_return(unauthorized_response)
214
195
  end
215
196
 
216
197
  let(:params) { { :expects => [200], :path => "fnord" } }
@@ -238,18 +219,16 @@ describe Fog::Storage::Brightbox do
238
219
  # Ongoing request but tokens are expired
239
220
  stub_request(:get, "https://files.gb2.brightbox.com/v1/acc-12345/fnord").
240
221
  with(:headers => { "X-Auth-Token" => "1234567890abcdefghijklmnopqrstuvwxyz" }).
241
- to_return(:status => 401,
242
- :body => "Authentication required",
243
- :headers => { "Content-Type" => "text/plain" })
222
+ to_return(unauthorized_response)
244
223
 
245
224
  # The reauthentication
246
225
  stub_request(:get, "https://files.gb2.brightbox.com/v1").
247
226
  with(:headers => { "X-Auth-User" => "user@example.com", "X-Auth-Key" => "12345" }).
248
- to_return(valid_auth_response)
227
+ to_return(authorized_response)
249
228
 
250
229
  # Repeated request
251
230
  stub_request(:get, "https://files.gb2.brightbox.com/v1/acc-12345/fnord").
252
- with(:headers => { "X-Auth-Token" => "c1236c8c34d668df497c06075d8a76a79c6fdd0d" }).
231
+ with(:headers => { "X-Auth-Token" => "abcdefghijklmnopqrstuvwxyz1234567890" }).
253
232
  to_return(:status => 200)
254
233
  end
255
234
 
@@ -272,11 +251,11 @@ describe Fog::Storage::Brightbox do
272
251
  before do
273
252
  # Initial authentication
274
253
  stub_request(:get, "https://orbit.brightbox.com/v1").
275
- with(:headers => {"X-Auth-Key" => "12345", "X-Auth-User" => "cli-12345"}).
276
- to_return(valid_auth_response)
254
+ with(:headers => { "X-Auth-Key" => "12345", "X-Auth-User" => "cli-12345" }).
255
+ to_return(authorized_response)
277
256
 
278
257
  stub_request(:get, "https://orbit.brightbox.com/v1/acc-12345/fnord").
279
- with(:headers => { "X-Auth-Token" => "c1236c8c34d668df497c06075d8a76a79c6fdd0d" }).
258
+ with(:headers => { "X-Auth-Token" => "abcdefghijklmnopqrstuvwxyz1234567890" }).
280
259
  to_return(:status => 200)
281
260
  end
282
261
 
data/spec/spec_helper.rb CHANGED
@@ -2,3 +2,4 @@ require "minitest/autorun"
2
2
  require "fog/brightbox"
3
3
  require "model_helper"
4
4
  require "supports_resource_locking"
5
+ require "stock_storage_responses"
@@ -0,0 +1,36 @@
1
+ module StockStorageResponses
2
+ def authorized_response
3
+ {
4
+ :status => 200,
5
+ :body => "Authenticated",
6
+ :headers => {
7
+ "X-Storage-Url" => "https://orbit.brightbox.com/v1/acc-12345",
8
+ "X-Storage-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
9
+ "X-Auth-Token" => "abcdefghijklmnopqrstuvwxyz1234567890",
10
+ "Content-Type" => "text/plain"
11
+ }
12
+ }
13
+ end
14
+
15
+ def unauthorized_response
16
+ {
17
+ :status => 401,
18
+ :body => "<html><h1>Unauthorized</h1><p>This server could not verify that you are authorized to access the document you requested.</p></html>",
19
+ :headers => {
20
+ "Content-Length" => 131,
21
+ "Content-Type" => "text/html; charset=UTF-8"
22
+ }
23
+ }
24
+ end
25
+
26
+ def bad_url_response
27
+ {
28
+ :status => 412,
29
+ :body => "Bad URL",
30
+ :headers => {
31
+ "Content-Length" => 7,
32
+ "Content-Type" => "text/html; charset=UTF-8"
33
+ }
34
+ }
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-brightbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Thornthwaite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-01 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -359,6 +359,7 @@ files:
359
359
  - spec/model_helper.rb
360
360
  - spec/model_setup.rb
361
361
  - spec/spec_helper.rb
362
+ - spec/stock_storage_responses.rb
362
363
  - spec/supports_resource_locking.rb
363
364
  homepage: ''
364
365
  licenses:
@@ -415,4 +416,5 @@ test_files:
415
416
  - spec/model_helper.rb
416
417
  - spec/model_setup.rb
417
418
  - spec/spec_helper.rb
419
+ - spec/stock_storage_responses.rb
418
420
  - spec/supports_resource_locking.rb