fog-brightbox 1.7.0 → 1.7.3

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
  SHA256:
3
- metadata.gz: 930c37c33d46857b7fa6f4e9880bd11068f9b4cc3a90aad25d1db39904ae6601
4
- data.tar.gz: e9bfaa815ea41d8a0fc5afc094b4e7626d8dfa3fb7b35ddb58f9fa0c60aaf945
3
+ metadata.gz: 92ebad94e1526398b760b8a104898cdb2600d3a624e6f77af9b9a2bf24011279
4
+ data.tar.gz: 913cf9025ebd5dda7b47b4c2511da1b3f03eea54de7db58a30b1ca15423d592e
5
5
  SHA512:
6
- metadata.gz: e7d00dbc24b5d7b9c2e292bf7caa4797d93ed6d94d28622ea5beb9f29af6c29d6098d17ab495d3707f9e7a847694f9a331e5de5268000bddb1e4f884d80566c6
7
- data.tar.gz: 4164e7796800011e460411dccc08efb780362b61afd2790b5af8e724151c86e50e315fba45f785ad8cf5fb44f9016e1aac36d7093436f07670332afff66c1aec
6
+ metadata.gz: 7d7d77edd59fb85d9d5ae125896a6d9f2f572ea7161a1da1eb4f183567f6fbf9682d18b55e648560cfa1ea179006aaa764b15a0fe11502d727038f2d97571cf2
7
+ data.tar.gz: 24359f5541ce79e0f658bdd86c039e1b90358e5b1a3defa2b52bc7fd391fbf87f783cdd33f96d4caaffccaa48fefb2b5438f90ff979462cd1b1a8f3c0536150b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ### 1.7.3 / 2022-08-17
2
+
3
+ Bug fixes:
4
+
5
+ * Fix to deduplicate forward slashes in `Storage::File#public_url` when object keys are prefixed with "/"
6
+
7
+ ### 1.7.2 / 2022-08-17
8
+
9
+ Bug fixes:
10
+
11
+ * Fix in `Storage.escape` regexp which failed to handle dashes correctly and broke generated URLs.
12
+
13
+ ### 1.7.1 / 2022-08-17
14
+
15
+ Bug fixes:
16
+
17
+ * Implement `Storage::Directory#public_url` to allow generation of `File` public URLs correctly.
18
+
1
19
  ### 1.7.0 / 2022-07-28
2
20
 
3
21
  Changes:
@@ -31,8 +31,9 @@ module Fog
31
31
  attr_writer :public
32
32
 
33
33
  def public_url
34
- # raise NotImplementedError
35
- ""
34
+ requires :key
35
+ @public_url ||= ::File.join(service.management_url.to_s,
36
+ Fog::Brightbox::Storage.escape(key, "/"))
36
37
  end
37
38
 
38
39
  def save
@@ -63,9 +63,9 @@ module Fog
63
63
 
64
64
  def get_url(key)
65
65
  requires :directory
66
- if directory.public_url
67
- "#{directory.public_url}/#{Fog::Brightbox::Storage.escape(key, "/")}"
68
- end
66
+ return unless directory.public_url
67
+
68
+ ::File.join(directory.public_url, Fog::Brightbox::Storage.escape(key, "/"))
69
69
  end
70
70
 
71
71
  def get_http_url(key, expires, options = {})
@@ -215,7 +215,8 @@ module Fog
215
215
 
216
216
  # CGI.escape, but without special treatment on spaces
217
217
  def self.escape(str, extra_exclude_chars = "")
218
- str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
218
+ # Includes fix to Regexp so "-" is correctly handled by placing last
219
+ str.gsub(/([^a-zA-Z0-9_.#{extra_exclude_chars}-]+)/) do
219
220
  "%" + Regexp.last_match[1].unpack("H2" * Regexp.last_match[1].bytesize).join("%").upcase
220
221
  end
221
222
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Brightbox
3
- VERSION = "1.7.0"
3
+ VERSION = "1.7.3"
4
4
  end
5
5
  end
@@ -0,0 +1,62 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+
4
+ describe Fog::Brightbox::Storage, ".escape" do
5
+ describe "when only excluded characters are used" do
6
+ it "escapes no letters" do
7
+ str = ("A".."Z").to_a.join
8
+ escaped = Fog::Brightbox::Storage.escape(str)
9
+ assert_equal str, escaped
10
+
11
+ str = ("a".."z").to_a.join
12
+ escaped = Fog::Brightbox::Storage.escape(str)
13
+ assert_equal str, escaped
14
+ end
15
+
16
+ it "escapes no numbers" do
17
+ str = ("0".."9").to_a.join
18
+ escaped = Fog::Brightbox::Storage.escape(str)
19
+ assert_equal str, escaped
20
+ end
21
+
22
+ it "does not escape dashes" do
23
+ str = "test-pattern123"
24
+ escaped = Fog::Brightbox::Storage.escape(str)
25
+ assert_equal str, escaped
26
+ end
27
+
28
+ it "does not escape dots" do
29
+ str = "sample.demo"
30
+ escaped = Fog::Brightbox::Storage.escape(str)
31
+ assert_equal str, escaped
32
+ end
33
+
34
+ it "does not escape underscores" do
35
+ str = "file_name"
36
+ escaped = Fog::Brightbox::Storage.escape(str)
37
+ assert_equal str, escaped
38
+ end
39
+ end
40
+
41
+ describe "when escaped characters are included" do
42
+ it "escapes those forward slashes" do
43
+ str = "test/pattern/123.txt"
44
+ escaped = Fog::Brightbox::Storage.escape(str)
45
+ assert_equal "test%2Fpattern%2F123.txt", escaped
46
+ end
47
+
48
+ it "escapes those backslashes" do
49
+ str = "test\\pattern\\123.txt"
50
+ escaped = Fog::Brightbox::Storage.escape(str)
51
+ assert_equal "test%5Cpattern%5C123.txt", escaped
52
+ end
53
+ end
54
+
55
+ describe "when additional characters are excluded" do
56
+ it "escapes those characters" do
57
+ str = "test/pattern/123.txt"
58
+ escaped = Fog::Brightbox::Storage.escape(str, "/")
59
+ assert_equal "test/pattern/123.txt", escaped
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,88 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+ require "fog/brightbox/models/storage/directory"
4
+ require "fog/brightbox/models/storage/files"
5
+
6
+ describe Fog::Brightbox::Storage::Files do
7
+ describe "#get_url" do
8
+ before do
9
+ @options = {
10
+ :brightbox_client_id => "cli-12345",
11
+ :brightbox_secret => "1234567890",
12
+ :brightbox_storage_management_url => "https://management.url/v1/acc-12345"
13
+ }
14
+ @service = Fog::Brightbox::Storage.new(@options)
15
+ end
16
+
17
+ describe "when directory can generate URL" do
18
+ describe "with object prefixed by forward slash" do
19
+ it do
20
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
21
+
22
+ directory = Fog::Brightbox::Storage::Directory.new(
23
+ service: @service,
24
+ key: "container-name"
25
+ )
26
+ assert_equal "https://management.url/v1/acc-12345/container-name", directory.public_url
27
+
28
+ files = Fog::Brightbox::Storage::Files.new(
29
+ service: @service,
30
+ directory: directory
31
+ )
32
+
33
+ expected = "https://management.url/v1/acc-12345/container-name/object"
34
+
35
+ assert_equal expected, files.get_url("/object")
36
+ end
37
+ end
38
+
39
+ describe "when object is correctly named" do
40
+ it do
41
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
42
+
43
+ directory = Fog::Brightbox::Storage::Directory.new(
44
+ service: @service,
45
+ key: "container-name"
46
+ )
47
+ assert_equal "https://management.url/v1/acc-12345/container-name", directory.public_url
48
+
49
+ files = Fog::Brightbox::Storage::Files.new(
50
+ service: @service,
51
+ directory: directory
52
+ )
53
+
54
+ expected = "https://management.url/v1/acc-12345/container-name/object"
55
+
56
+ assert_equal expected, files.get_url("object")
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "when no management URL" do
62
+ before do
63
+ @options = {
64
+ :brightbox_client_id => "cli-12345",
65
+ :brightbox_secret => "1234567890"
66
+ }
67
+ @service = Fog::Brightbox::Storage.new(@options)
68
+ end
69
+
70
+ it do
71
+ assert_equal "", @service.management_url.to_s
72
+
73
+ directory = Fog::Brightbox::Storage::Directory.new(
74
+ service: @service,
75
+ key: "container-name"
76
+ )
77
+ assert_equal "/container-name", directory.public_url
78
+
79
+ files = Fog::Brightbox::Storage::Files.new(
80
+ service: @service,
81
+ directory: directory
82
+ )
83
+
84
+ assert_equal "/container-name/object", files.get_url("/object")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,34 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+
4
+ describe Fog::Brightbox::Storage do
5
+ describe "when passed in configuration" do
6
+ before do
7
+ @options = {
8
+ :brightbox_client_id => "cli-12345",
9
+ :brightbox_secret => "1234567890",
10
+ :brightbox_storage_management_url => "https://management.url/v1/acc-12345"
11
+ }
12
+ @service = Fog::Brightbox::Storage.new(@options)
13
+ end
14
+
15
+ it "returns a URI matching config option" do
16
+ assert_kind_of URI, @service.management_url
17
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
18
+ end
19
+ end
20
+
21
+ describe "when unavailable" do
22
+ before do
23
+ @options = {
24
+ :brightbox_client_id => "cli-12345",
25
+ :brightbox_secret => "1234567890"
26
+ }
27
+ @service = Fog::Brightbox::Storage.new(@options)
28
+ end
29
+
30
+ it "returns nil" do
31
+ assert_nil @service.management_url
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-brightbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Thornthwaite
@@ -403,6 +403,9 @@ files:
403
403
  - spec/fog/brightbox/storage/config_spec.rb
404
404
  - spec/fog/brightbox/storage/connection_errors_spec.rb
405
405
  - spec/fog/brightbox/storage/connection_spec.rb
406
+ - spec/fog/brightbox/storage/escape_spec.rb
407
+ - spec/fog/brightbox/storage/files_spec.rb
408
+ - spec/fog/brightbox/storage_spec.rb
406
409
  - spec/fog/compute/brightbox/account_spec.rb
407
410
  - spec/fog/compute/brightbox/api_client_spec.rb
408
411
  - spec/fog/compute/brightbox/application_spec.rb
@@ -513,6 +516,9 @@ test_files:
513
516
  - spec/fog/brightbox/storage/config_spec.rb
514
517
  - spec/fog/brightbox/storage/connection_errors_spec.rb
515
518
  - spec/fog/brightbox/storage/connection_spec.rb
519
+ - spec/fog/brightbox/storage/escape_spec.rb
520
+ - spec/fog/brightbox/storage/files_spec.rb
521
+ - spec/fog/brightbox/storage_spec.rb
516
522
  - spec/fog/compute/brightbox/account_spec.rb
517
523
  - spec/fog/compute/brightbox/api_client_spec.rb
518
524
  - spec/fog/compute/brightbox/application_spec.rb