gitlab-fog-azure-rm 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +12 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/gitlab-fog-azure-rm.gemspec +3 -2
  5. data/lib/fog/azurerm/docs/storage.md +1 -1
  6. data/lib/fog/azurerm/identity_encoding_filter.rb +12 -0
  7. data/lib/fog/azurerm/models/storage/directories.rb +6 -6
  8. data/lib/fog/azurerm/models/storage/directory.rb +4 -4
  9. data/lib/fog/azurerm/models/storage/file.rb +6 -3
  10. data/lib/fog/azurerm/models/storage/files.rb +8 -8
  11. data/lib/fog/azurerm/models/storage/storage_account.rb +4 -4
  12. data/lib/fog/azurerm/models/storage/storage_accounts.rb +6 -6
  13. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +2 -2
  14. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +2 -2
  15. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +2 -2
  16. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +2 -2
  17. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +2 -2
  18. data/lib/fog/azurerm/requests/storage/copy_blob.rb +2 -2
  19. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +2 -2
  20. data/lib/fog/azurerm/requests/storage/copy_object.rb +2 -2
  21. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +2 -2
  22. data/lib/fog/azurerm/requests/storage/create_container.rb +2 -2
  23. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +2 -2
  24. data/lib/fog/azurerm/requests/storage/delete_blob.rb +2 -2
  25. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +4 -4
  26. data/lib/fog/azurerm/requests/storage/delete_container.rb +2 -2
  27. data/lib/fog/azurerm/requests/storage/delete_object.rb +2 -2
  28. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +2 -2
  29. data/lib/fog/azurerm/requests/storage/get_blob.rb +2 -2
  30. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +5 -5
  31. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +6 -5
  32. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +2 -2
  33. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +4 -4
  34. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +2 -2
  35. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +2 -2
  36. data/lib/fog/azurerm/requests/storage/get_container_url.rb +4 -4
  37. data/lib/fog/azurerm/requests/storage/get_object.rb +2 -2
  38. data/lib/fog/azurerm/requests/storage/get_object_url.rb +2 -2
  39. data/lib/fog/azurerm/requests/storage/list_blobs.rb +2 -2
  40. data/lib/fog/azurerm/requests/storage/list_containers.rb +2 -2
  41. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +2 -2
  42. data/lib/fog/azurerm/requests/storage/put_blob_http_url.rb +39 -0
  43. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +4 -4
  44. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +2 -2
  45. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +2 -2
  46. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +2 -2
  47. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +2 -2
  48. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +2 -2
  49. data/lib/fog/azurerm/requests/storage/put_object_url.rb +2 -2
  50. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +2 -2
  51. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +2 -2
  52. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +2 -2
  53. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +2 -2
  54. data/lib/fog/azurerm/storage.rb +62 -9
  55. data/lib/fog/azurerm/utilities/general.rb +0 -5
  56. data/lib/fog/azurerm/version.rb +1 -1
  57. data/lib/fog/azurerm.rb +4 -5
  58. data/rakefile +4 -5
  59. data/test/api_stub/models/storage/directory.rb +1 -1
  60. data/test/api_stub/models/storage/file.rb +1 -1
  61. data/test/api_stub/requests/storage/directory.rb +1 -1
  62. data/test/api_stub/requests/storage/file.rb +4 -4
  63. data/test/integration/README.md +5 -7
  64. data/test/integration/blob.rb +28 -36
  65. data/test/integration/container.rb +8 -39
  66. data/test/integration/credentials/azure.yml +4 -5
  67. data/test/models/storage/test_directories.rb +5 -5
  68. data/test/models/storage/test_directory.rb +2 -2
  69. data/test/models/storage/test_file.rb +16 -4
  70. data/test/models/storage/test_files.rb +8 -8
  71. data/test/requests/storage/test_acquire_blob_lease.rb +2 -2
  72. data/test/requests/storage/test_acquire_container_lease.rb +2 -2
  73. data/test/requests/storage/test_check_container_exists.rb +1 -1
  74. data/test/requests/storage/test_commit_blob_blocks.rb +2 -2
  75. data/test/requests/storage/test_compare_container_blobs.rb +2 -2
  76. data/test/requests/storage/test_copy_blob.rb +2 -2
  77. data/test/requests/storage/test_copy_blob_from_uri.rb +2 -2
  78. data/test/requests/storage/test_create_block_blob.rb +2 -2
  79. data/test/requests/storage/test_create_container.rb +2 -2
  80. data/test/requests/storage/test_create_page_blob.rb +2 -2
  81. data/test/requests/storage/test_delete_blob.rb +2 -2
  82. data/test/requests/storage/test_delete_blob_https_url.rb +7 -10
  83. data/test/requests/storage/test_delete_container.rb +2 -2
  84. data/test/requests/storage/test_delete_object.rb +2 -2
  85. data/test/requests/storage/test_get_blob.rb +2 -2
  86. data/test/requests/storage/test_get_blob_encoding.rb +45 -0
  87. data/test/requests/storage/test_get_blob_http_url.rb +13 -9
  88. data/test/requests/storage/test_get_blob_https_url.rb +95 -13
  89. data/test/requests/storage/test_get_blob_properties.rb +2 -2
  90. data/test/requests/storage/test_get_blob_url.rb +15 -24
  91. data/test/requests/storage/test_get_container_acl.rb +2 -2
  92. data/test/requests/storage/test_get_container_properties.rb +2 -2
  93. data/test/requests/storage/test_get_container_url.rb +5 -8
  94. data/test/requests/storage/test_get_object.rb +2 -2
  95. data/test/requests/storage/test_list_blobs.rb +2 -2
  96. data/test/requests/storage/test_list_containers.rb +2 -2
  97. data/test/requests/storage/test_put_blob_block.rb +2 -2
  98. data/test/requests/storage/test_put_blob_http_url.rb +33 -0
  99. data/test/requests/storage/test_put_blob_https_url.rb +8 -11
  100. data/test/requests/storage/test_put_blob_metadata.rb +2 -2
  101. data/test/requests/storage/test_put_blob_pages.rb +2 -2
  102. data/test/requests/storage/test_put_blob_properties.rb +2 -2
  103. data/test/requests/storage/test_put_container_acl.rb +2 -2
  104. data/test/requests/storage/test_put_container_metadata.rb +2 -2
  105. data/test/requests/storage/test_release_blob_lease.rb +2 -2
  106. data/test/requests/storage/test_release_container_lease.rb +2 -2
  107. data/test/requests/storage/test_save_page_blob.rb +2 -2
  108. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +15 -6
  109. data/test/test_helper.rb +38 -690
  110. metadata +27 -20
  111. data/lib/fog/azurerm/models/resources/azure_resource.rb +0 -25
  112. data/lib/fog/azurerm/models/resources/azure_resources.rb +0 -40
  113. data/lib/fog/azurerm/models/resources/dependency.rb +0 -27
  114. data/lib/fog/azurerm/models/resources/deployment.rb +0 -65
  115. data/lib/fog/azurerm/models/resources/deployments.rb +0 -30
  116. data/lib/fog/azurerm/models/resources/provider.rb +0 -27
  117. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +0 -22
  118. data/lib/fog/azurerm/models/resources/resource_group.rb +0 -34
  119. data/lib/fog/azurerm/models/resources/resource_groups.rb +0 -29
  120. data/test/integration/storage_account.rb +0 -135
  121. data/test/smoke_tests/compute/test_resource_group_smoke.rb +0 -37
@@ -2,15 +2,19 @@ require File.expand_path '../../test_helper', __dir__
2
2
 
3
3
  # Storage Blob Class
4
4
  class TestGetBlobHttpsUrl < Minitest::Test
5
+ HOUR = 3600
6
+ DAY = 24 * HOUR
7
+ WEEK = 7 * DAY
8
+
5
9
  # This class posesses the test cases for the requests of Blob service.
6
10
  def setup
7
11
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
13
  Fog.unmock!
10
14
 
11
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
15
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
12
16
  @blob_client = @service.instance_variable_get(:@blob_client)
13
- @signature_client = @service.instance_variable_get(:@signature_client)
17
+ @signature_client = @service.send(:signature_client, Minitest::Mock.new)
14
18
 
15
19
  @url = ApiStub::Requests::Storage::File.blob_https_url
16
20
  @token = ApiStub::Requests::Storage::File.blob_url_token
@@ -20,7 +24,7 @@ class TestGetBlobHttpsUrl < Minitest::Test
20
24
  mock_generate_uri = Minitest::Mock.new
21
25
 
22
26
  2.times do
23
- mock_generate_uri.expect(:call, @url, ['test_container/test_blob', {}, { encode: true }])
27
+ mock_generate_uri.expect(:call, URI.parse(@url), ['test_container/test_blob', {}, { encode: true }])
24
28
  end
25
29
 
26
30
  @blob_client.stub :generate_uri, mock_generate_uri do
@@ -37,11 +41,12 @@ class TestGetBlobHttpsUrl < Minitest::Test
37
41
  url_params = { content_disposition: 'attachment' }
38
42
 
39
43
  2.times do
40
- mock_generate_uri.expect(:call, @url, ['test_container/test_blob', {}, { encode: true }])
44
+ mock_generate_uri.expect(:call, URI.parse(@url), ['test_container/test_blob', {}, { encode: true }])
41
45
  mock_generate_service_token.expect(:call, @token) do |_relative_path, params|
42
46
  params[:service] == 'b' &&
43
47
  params[:resource] == 'b' &&
44
48
  params[:permissions] == 'r' &&
49
+ params[:protocol] == 'https' &&
45
50
  params[:content_disposition] == url_params[:content_disposition]
46
51
  end
47
52
  end
@@ -59,7 +64,7 @@ class TestGetBlobHttpsUrl < Minitest::Test
59
64
  mock_generate_service_token = Minitest::Mock.new
60
65
 
61
66
  2.times do
62
- mock_generate_uri.expect(:call, @url, ['.test0/..test1/...test2', {}, { encode: true }])
67
+ mock_generate_uri.expect(:call, URI.parse(@url), ['.test0/..test1/...test2', {}, { encode: true }])
63
68
  mock_generate_service_token.expect(:call, @token) do |relative_path, _|
64
69
  relative_path == '.test0/..test1/...test2'
65
70
  end
@@ -73,20 +78,97 @@ class TestGetBlobHttpsUrl < Minitest::Test
73
78
  end
74
79
  end
75
80
 
81
+ def test_get_blob_https_url_with_endpoint_success
82
+ service = Fog::AzureRM::Storage.new(storage_account_credentials_with_endpoint)
83
+ signature_client = service.send(:signature_client, Minitest::Mock.new)
84
+
85
+ url = 'http://localhost:10000/mockaccount/test_container/test_blob'
86
+ token = ApiStub::Requests::Storage::File.blob_url_token
87
+
88
+ signature_client.stub :generate_service_sas_token, token do
89
+ assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
90
+ assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
91
+ end
92
+ end
93
+
76
94
  def test_get_blob_https_url_with_domain_success
77
- service = Fog::Storage::AzureRM.new(storage_account_credentials_with_domain)
78
- blob_client = service.instance_variable_get(:@blob_client)
79
- signature_client = service.instance_variable_get(:@signature_client)
95
+ service = Fog::AzureRM::Storage.new(storage_account_credentials_with_domain)
96
+ signature_client = service.send(:signature_client, Minitest::Mock.new)
80
97
 
81
98
  url = 'https://mockaccount.test.example.com/test_container/test_blob'
82
99
  token = ApiStub::Requests::Storage::File.blob_url_token
83
100
 
84
- blob_client.stub :generate_uri, url do
85
- signature_client.stub :generate_service_sas_token, token do
86
- assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
87
- assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
101
+ signature_client.stub :generate_service_sas_token, token do
102
+ assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
103
+ assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
104
+ end
105
+ end
106
+
107
+ def test_get_blob_https_url_with_token_signer_success
108
+ service = Fog::AzureRM::Storage.new(storage_account_credentials_with_token_signer)
109
+ blob_client = service.instance_variable_get(:@blob_client)
110
+
111
+ ref_time = Time.now
112
+
113
+ stubbed_times = []
114
+ requested_expiries = []
115
+ expected_user_delegation_key_starts = []
116
+
117
+ # initial request
118
+ stubbed_times << ref_time
119
+ requested_expiries << stubbed_times.last + 1 * HOUR
120
+ expected_user_delegation_key_starts << stubbed_times.last
121
+
122
+ # second request during expiry window
123
+ stubbed_times << ref_time + 5.5 * DAY
124
+ requested_expiries << stubbed_times.last + 1 * DAY
125
+ # no additonal expected_user_delegation_key_starts
126
+
127
+ # request extending past current expiry
128
+ stubbed_times << ref_time + 6.5 * DAY
129
+ requested_expiries << stubbed_times.last + 1 * DAY
130
+ expected_user_delegation_key_starts << stubbed_times.last
131
+
132
+ # second request within new expiry
133
+ stubbed_times << ref_time + 10.5 * DAY
134
+ requested_expiries << stubbed_times.last + 1 * DAY
135
+ # no additonal expected_user_delegation_key_starts
136
+
137
+ user_delegation_key_starts = []
138
+ mock_user_delegation_key = lambda do |start, expiry|
139
+ user_delegation_key_starts << start
140
+ assert_equal 1 * WEEK, expiry - start
141
+
142
+ key = Azure::Storage::Common::Service::UserDelegationKey.new
143
+ key.signed_start = "start-#{start.to_i}"
144
+ key.signed_expiry = 'test-expiry'
145
+ key.value = 'delegation-key'
146
+ key
147
+ end
148
+
149
+ mock_new_signer = lambda do |token|
150
+ assert_equal 'delegation-key', token
151
+ mock_token_signer
152
+ end
153
+
154
+ requested_expiries.each do
155
+ mock_token_signer.expect(:sign, 'test-signature', [/\Ar\n.+test_blob\n.+\nstart-\d+\ntest-expiry/m])
156
+ end
157
+
158
+ Time.stub :now, -> { stubbed_times.first } do
159
+ blob_client.stub :get_user_delegation_key, mock_user_delegation_key do
160
+ Azure::Core::Auth::Signer.stub :new, mock_new_signer do
161
+ while (requested_expiry = requested_expiries.shift)
162
+ url = service.get_blob_https_url('test_container', 'test_blob', requested_expiry)
163
+ assert_match(/^#{Regexp.escape @url}.+&skt=start-#{user_delegation_key_starts.last.to_i}&.+&sig=test-signature/, url)
164
+
165
+ stubbed_times.shift
166
+ end
167
+ end
88
168
  end
89
169
  end
170
+
171
+ assert_equal expected_user_delegation_key_starts, user_delegation_key_starts
90
172
  end
91
173
 
92
174
  def test_get_blob_https_url_mock
@@ -5,11 +5,11 @@ class TestGetBlobProperties < Minitest::Test
5
5
  # This class posesses the test cases for the requests of getting storage blob properties.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @blob = ApiStub::Requests::Storage::File.blob
@@ -5,18 +5,18 @@ class TestGetBlobUrl < Minitest::Test
5
5
  # This class posesses the test cases for the requests of Blob service.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  end
11
11
 
12
12
  def test_get_blob_url_success
13
- service = Fog::Storage::AzureRM.new(storage_account_credentials)
13
+ service = Fog::AzureRM::Storage.new(storage_account_credentials)
14
14
  blob_client = service.instance_variable_get(:@blob_client)
15
15
 
16
16
  mock_generate_uri = Minitest::Mock.new
17
17
  url = ApiStub::Requests::Storage::File.blob_https_url
18
18
  2.times do
19
- mock_generate_uri.expect(:call, url, ['test_container/test_blob', {}, { encode: true }])
19
+ mock_generate_uri.expect(:call, URI.parse(url), ['test_container/test_blob', {}, { encode: true }])
20
20
  end
21
21
 
22
22
  blob_client.stub :generate_uri, mock_generate_uri do
@@ -29,44 +29,35 @@ class TestGetBlobUrl < Minitest::Test
29
29
 
30
30
  def test_get_blob_url_for_china_success
31
31
  china_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD)
32
- service = Fog::Storage::AzureRM.new(china_storage_account_credentials)
33
- blob_client = service.instance_variable_get(:@blob_client)
32
+ service = Fog::AzureRM::Storage.new(china_storage_account_credentials)
34
33
  url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD)
35
34
 
36
- blob_client.stub :generate_uri, url do
37
- assert_equal url, service.get_blob_url('test_container', 'test_blob')
35
+ assert_equal url, service.get_blob_url('test_container', 'test_blob')
38
36
 
39
- options = { scheme: 'http' }
40
- assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
41
- end
37
+ options = { scheme: 'http' }
38
+ assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
42
39
  end
43
40
 
44
41
  def test_get_blob_url_for_us_success
45
42
  us_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT)
46
- service = Fog::Storage::AzureRM.new(us_storage_account_credentials)
47
- blob_client = service.instance_variable_get(:@blob_client)
43
+ service = Fog::AzureRM::Storage.new(us_storage_account_credentials)
48
44
  url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT)
49
45
 
50
- blob_client.stub :generate_uri, url do
51
- assert_equal url, service.get_blob_url('test_container', 'test_blob')
46
+ assert_equal url, service.get_blob_url('test_container', 'test_blob')
52
47
 
53
- options = { scheme: 'http' }
54
- assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
55
- end
48
+ options = { scheme: 'http' }
49
+ assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
56
50
  end
57
51
 
58
52
  def test_get_blob_url_for_german_success
59
53
  german_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD)
60
- service = Fog::Storage::AzureRM.new(german_storage_account_credentials)
61
- blob_client = service.instance_variable_get(:@blob_client)
54
+ service = Fog::AzureRM::Storage.new(german_storage_account_credentials)
62
55
  url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD)
63
56
 
64
- blob_client.stub :generate_uri, url do
65
- assert_equal url, service.get_blob_url('test_container', 'test_blob')
57
+ assert_equal url, service.get_blob_url('test_container', 'test_blob')
66
58
 
67
- options = { scheme: 'http' }
68
- assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
69
- end
59
+ options = { scheme: 'http' }
60
+ assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
70
61
  end
71
62
 
72
63
  def test_get_blob_url_mock
@@ -5,11 +5,11 @@ class TestGetContainerAcl < Minitest::Test
5
5
  # This class posesses the test cases for the requests of getting storage container acl.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @raw_container_acl = ApiStub::Requests::Storage::Directory.raw_container_acl
@@ -5,11 +5,11 @@ class TestGetContainerProperties < Minitest::Test
5
5
  # This class posesses the test cases for the requests of getting storage container properties.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @container = ApiStub::Requests::Storage::Directory.container
@@ -5,22 +5,19 @@ class TestGetContainerUrl < Minitest::Test
5
5
  # This class posesses the test cases for the requests of getting storage container url.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
 
11
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
- @blob_client = @service.instance_variable_get(:@blob_client)
11
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
12
 
14
13
  @url = ApiStub::Requests::Storage::Directory.container_https_url
15
14
  end
16
15
 
17
16
  def test_get_container_url_success
18
- @blob_client.stub :generate_uri, @url do
19
- assert_equal @url, @service.get_container_url('test_container')
17
+ assert_equal @url, @service.get_container_url('test_container')
20
18
 
21
- options = { scheme: 'http' }
22
- assert_equal @url.gsub('https:', 'http:'), @service.get_container_url('test_container', options)
23
- end
19
+ options = { scheme: 'http' }
20
+ assert_equal @url.gsub('https:', 'http:'), @service.get_container_url('test_container', options)
24
21
  end
25
22
 
26
23
  def test_get_container_url_mock
@@ -5,11 +5,11 @@ class TestGetObject < Minitest::Test
5
5
  # This class posesses the test cases for the requests of getting storage blob.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @raw_cloud_blob = storage_blob
@@ -5,11 +5,11 @@ class TestListBlobs < Minitest::Test
5
5
  # This class posesses the test cases for the requests of listing blobs in storage containers.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @blob_list = ApiStub::Requests::Storage::File.blob_list
@@ -5,11 +5,11 @@ class TestListContainers < Minitest::Test
5
5
  # This class posesses the test cases for the requests of listing storage containers.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @containers = ApiStub::Requests::Storage::Directory.container_list
@@ -5,11 +5,11 @@ class TestPutBlobBlock < Minitest::Test
5
5
  # This class posesses the test cases for the requests of putting blob block.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
  end
15
15
 
@@ -0,0 +1,33 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestPutBlobHttpUrl < Minitest::Test
5
+ # This class posesses the test cases for the requests of Blob service.
6
+ def setup
7
+ Fog.mock!
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
+ Fog.unmock!
10
+
11
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
12
+ @signature_client = @service.send(:signature_client, Minitest::Mock.new)
13
+
14
+ @url = ApiStub::Requests::Storage::File.blob_https_url.gsub('https:', 'http:')
15
+ @token = ApiStub::Requests::Storage::File.blob_url_token
16
+ end
17
+
18
+ def test_put_blob_http_urls_success
19
+ @signature_client.stub :generate_service_sas_token, @token do
20
+ assert_equal "#{@url}?#{@token}", @service.put_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600)
21
+ end
22
+ end
23
+
24
+ def test_put_url_https_in_container_and_blob_names
25
+ uri = URI.parse(@service.put_blob_http_url('https://container', 'https://blob', Time.now.utc + 3600))
26
+ assert_equal 'http', uri.scheme
27
+ assert_equal '/https://container/https://blob', CGI.unescape(uri.path)
28
+ end
29
+
30
+ def test_put_blob_http_url_mock
31
+ assert_equal "#{@url}?#{@token}", @mock_service.put_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600)
32
+ end
33
+ end
@@ -1,27 +1,24 @@
1
1
  require File.expand_path '../../test_helper', __dir__
2
2
 
3
3
  # Storage Blob Class
4
- class TestPutBlobHttpUrl < Minitest::Test
4
+ class TestPutBlobHttpsUrl < Minitest::Test
5
5
  # This class posesses the test cases for the requests of Blob service.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
 
11
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
- @blob_client = @service.instance_variable_get(:@blob_client)
13
- @signature_client = @service.instance_variable_get(:@signature_client)
11
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
12
+ @signature_client = @service.send(:signature_client, Minitest::Mock.new)
14
13
 
15
14
  @url = ApiStub::Requests::Storage::File.blob_https_url
16
15
  @token = ApiStub::Requests::Storage::File.blob_url_token
17
16
  end
18
17
 
19
- def test_put_blob_http_urls_success
20
- @blob_client.stub :generate_uri, @url do
21
- @signature_client.stub :generate_service_sas_token, @token do
22
- assert_equal "#{@url}?#{@token}", @service.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
23
- assert_equal "#{@url}?#{@token}", @service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {})
24
- end
18
+ def test_put_blob_https_urls_success
19
+ @signature_client.stub :generate_service_sas_token, @token do
20
+ assert_equal "#{@url}?#{@token}", @service.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
21
+ assert_equal "#{@url}?#{@token}", @service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {})
25
22
  end
26
23
  end
27
24
 
@@ -5,11 +5,11 @@ class TestPutBlobMetadata < Minitest::Test
5
5
  # This class posesses the test cases for the requests of setting blob metadata.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @metadata = ApiStub::Requests::Storage::File.blob_metadata
@@ -5,11 +5,11 @@ class TestPutBlobPages < Minitest::Test
5
5
  # This class posesses the test cases for the requests of putting blob page.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
  end
15
15
 
@@ -5,11 +5,11 @@ class TestPutBlobProperties < Minitest::Test
5
5
  # This class posesses the test cases for the requests of setting blob properties.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @properties = {
@@ -5,11 +5,11 @@ class TestPutContainerACL < Minitest::Test
5
5
  # This class posesses the test cases for the requests of setting storage container acl.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
  end
15
15
 
@@ -5,11 +5,11 @@ class TestPutContainerMetadata < Minitest::Test
5
5
  # This class posesses the test cases for the requests of container service.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
 
15
15
  @metadata = ApiStub::Requests::Storage::Directory.container_metadata
@@ -5,11 +5,11 @@ class TestReleaseBlobLease < Minitest::Test
5
5
  # This class posesses the test cases for the requests of releasing blob lease.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
  end
15
15
 
@@ -5,11 +5,11 @@ class TestReleaseContainerLease < Minitest::Test
5
5
  # This class posesses the test cases for the requests of releasing container lease.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  @blob_client = @service.instance_variable_get(:@blob_client)
14
14
  end
15
15
 
@@ -5,11 +5,11 @@ class TestSavePageBlob < Minitest::Test
5
5
  # This class posesses the test cases for the requests of saving storage page blob.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
 
12
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
12
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
13
13
  end
14
14
 
15
15
  def test_save_page_blob_success
@@ -5,12 +5,12 @@ class TestWaitBlobCopyOperationToFinish < Minitest::Test
5
5
  # This class posesses the test cases for the requests of waiting storage blob copy operation to finish.
6
6
  def setup
7
7
  Fog.mock!
8
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
9
9
  Fog.unmock!
10
10
  @mocked_response = mocked_storage_http_error
11
11
  @blob = storage_blob
12
12
 
13
- @service = Fog::Storage::AzureRM.new(storage_account_credentials)
13
+ @service = Fog::AzureRM::Storage.new(storage_account_credentials)
14
14
  @blob_client = @service.instance_variable_get(:@blob_client)
15
15
  end
16
16
 
@@ -49,7 +49,9 @@ class TestWaitBlobCopyOperationToFinish < Minitest::Test
49
49
  end
50
50
 
51
51
  @service.stub :get_blob_properties, multiple_values do
52
- assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
52
+ @service.stub :sleep, ->(delay) {} do
53
+ assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
54
+ end
53
55
  end
54
56
  end
55
57
 
@@ -104,10 +106,17 @@ class TestWaitBlobCopyOperationToFinish < Minitest::Test
104
106
  @blob
105
107
  end
106
108
 
109
+ stubbed_times = [
110
+ Time.now,
111
+ Time.now + 5
112
+ ]
113
+
107
114
  @service.stub :get_blob_properties, multiple_values do
108
- @service.stub :delete_blob, true do
109
- assert_raises(Timeout::Error) do
110
- @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status, 2)
115
+ Time.stub :new, -> { stubbed_times.shift } do
116
+ @service.stub :delete_blob, true do
117
+ assert_raises(Timeout::Error) do
118
+ @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status, 2)
119
+ end
111
120
  end
112
121
  end
113
122
  end