azure 0.7.0.pre → 0.7.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +3 -1
  3. data/.gitignore +15 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +322 -248
  6. data/Rakefile +3 -1
  7. data/azure.gemspec +18 -14
  8. data/lib/azure.rb +124 -38
  9. data/lib/azure/base_management/base_management_service.rb +57 -69
  10. data/lib/azure/base_management/location.rb +1 -1
  11. data/lib/azure/base_management/management_http_request.rb +55 -58
  12. data/lib/azure/base_management/serialization.rb +5 -0
  13. data/lib/azure/base_management/sql_management_http_request.rb +10 -20
  14. data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
  15. data/lib/azure/blob/blob_service.rb +196 -171
  16. data/lib/azure/client.rb +31 -0
  17. data/lib/azure/client_services.rb +98 -0
  18. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
  19. data/lib/azure/configurable.rb +290 -0
  20. data/lib/azure/core/auth/authorizer.rb +1 -1
  21. data/lib/azure/core/auth/shared_key.rb +48 -40
  22. data/lib/azure/core/auth/shared_key_lite.rb +9 -9
  23. data/lib/azure/core/auth/signer.rb +15 -12
  24. data/lib/azure/core/error.rb +2 -3
  25. data/lib/azure/core/filtered_service.rb +4 -3
  26. data/lib/azure/core/http/http_error.rb +10 -12
  27. data/lib/azure/core/http/http_request.rb +82 -69
  28. data/lib/azure/core/http/http_response.rb +12 -56
  29. data/lib/azure/core/http/signer_filter.rb +3 -4
  30. data/lib/azure/core/service.rb +8 -25
  31. data/lib/azure/core/signed_service.rb +7 -5
  32. data/lib/azure/core/utility.rb +45 -6
  33. data/lib/azure/default.rb +126 -0
  34. data/lib/azure/http_client.rb +85 -0
  35. data/lib/azure/queue/queue.rb +0 -1
  36. data/lib/azure/queue/queue_service.rb +6 -4
  37. data/lib/azure/queue/serialization.rb +0 -1
  38. data/lib/azure/service/storage_service.rb +9 -6
  39. data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
  40. data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
  41. data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
  42. data/lib/azure/service_bus/service_bus_service.rb +34 -30
  43. data/lib/azure/sql_database_management/errors.rb +11 -0
  44. data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
  45. data/lib/azure/sql_database_management/serialization.rb +40 -53
  46. data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
  47. data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
  48. data/lib/azure/storage_management/storage_management_service.rb +9 -10
  49. data/lib/azure/table/auth/shared_key.rb +17 -50
  50. data/lib/azure/table/auth/shared_key_lite.rb +3 -3
  51. data/lib/azure/table/serialization.rb +24 -24
  52. data/lib/azure/table/table_service.rb +21 -18
  53. data/lib/azure/version.rb +1 -1
  54. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
  55. data/lib/azure/virtual_machine_management/serialization.rb +4 -1
  56. data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
  57. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
  58. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
  59. data/test/fixtures/list_locations.xml +150 -0
  60. data/test/fixtures/list_sql_database.xml +6 -18
  61. data/test/fixtures/list_sql_server_firewall.xml +18 -18
  62. data/test/fixtures/management_certificate.pfx +0 -0
  63. data/test/fixtures/virtual_machine.xml +1 -0
  64. data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
  65. data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
  66. data/test/integration/blob/blob_gb18030_test.rb +29 -29
  67. data/test/integration/blob/blob_pages_test.rb +16 -16
  68. data/test/integration/blob/container/create_container_test.rb +6 -6
  69. data/test/integration/blob/container/root_container_test.rb +2 -1
  70. data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
  71. data/test/integration/database/create_sql_server_test.rb +6 -6
  72. data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
  73. data/test/integration/database/delete_sql_server_test.rb +9 -22
  74. data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
  75. data/test/integration/database/list_sql_servers_test.rb +4 -4
  76. data/test/integration/database/reset_password_sql_server_test.rb +9 -11
  77. data/test/integration/location/RoleSize_List_test.rb +35 -0
  78. data/test/integration/queue/list_queues_test.rb +0 -1
  79. data/test/integration/service_bus/queues_scenario_test.rb +11 -11
  80. data/test/integration/service_bus/queues_test.rb +2 -2
  81. data/test/integration/service_bus/subscriptions_test.rb +25 -25
  82. data/test/integration/service_bus/topics_scenario_test.rb +6 -6
  83. data/test/integration/service_bus/topics_test.rb +15 -15
  84. data/test/integration/table/query_entities_test.rb +1 -0
  85. data/test/integration/table/table_acl_test.rb +9 -9
  86. data/test/integration/test_helper.rb +11 -9
  87. data/test/integration/vm/VM_Create_test.rb +23 -20
  88. data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
  89. data/test/test_helper.rb +5 -0
  90. data/test/unit/affinity_group/affinity_group_test.rb +4 -4
  91. data/test/unit/base_management/base_management_service_test.rb +19 -0
  92. data/test/unit/base_management/location_test.rb +6 -6
  93. data/test/unit/base_management/role_size_test.rb +50 -0
  94. data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
  95. data/test/unit/blob/blob_service_test.rb +583 -582
  96. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
  97. data/test/unit/config/azure_test.rb +112 -0
  98. data/test/unit/config/client_test.rb +37 -0
  99. data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
  100. data/test/unit/core/auth/shared_key_test.rb +26 -26
  101. data/test/unit/core/http/http_error_test.rb +13 -14
  102. data/test/unit/core/http/http_request_test.rb +78 -53
  103. data/test/unit/core/http/http_response_test.rb +2 -27
  104. data/test/unit/core/http/retry_policy_test.rb +3 -3
  105. data/test/unit/core/utility_test.rb +122 -0
  106. data/test/unit/database/serialization_test.rb +17 -20
  107. data/test/unit/database/sql_database_server_service_test.rb +97 -40
  108. data/test/unit/http_client_test.rb +74 -0
  109. data/test/unit/service/storage_service_test.rb +105 -101
  110. data/test/unit/storage_management/storage_management_service_test.rb +28 -28
  111. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
  112. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
  113. data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
  114. metadata +91 -20
  115. data/lib/azure/core.rb +0 -41
  116. data/lib/azure/core/configuration.rb +0 -218
@@ -34,7 +34,7 @@ describe Azure::CloudServiceManagementService do
34
34
 
35
35
  describe "#list_cloud_services" do
36
36
  before do
37
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, nil).returns(mock_request)
37
+ Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, anything).returns(mock_request)
38
38
  mock_request.expects(:call).returns(response_body)
39
39
  end
40
40
 
@@ -57,7 +57,7 @@ describe Azure::CloudServiceManagementService do
57
57
 
58
58
  describe "#get_cloud_service" do
59
59
  before do
60
- Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, nil).returns(mock_request)
60
+ Azure::BaseManagement::ManagementHttpRequest.stubs(:new).with(verb, request_path, anything).returns(mock_request)
61
61
  mock_request.expects(:call).returns(response_body)
62
62
  end
63
63
 
@@ -0,0 +1,112 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'test_helper'
16
+
17
+ describe Azure do
18
+
19
+ describe 'default configuration for the azure module' do
20
+ subject { Azure }
21
+
22
+ it 'should provide itself as the base configuration through the config method' do
23
+ subject.config.must_equal Azure
24
+ end
25
+
26
+ it 'should provide access to the configuration through the config method' do
27
+ subject.config.management_endpoint.must_equal Azure.management_endpoint
28
+ end
29
+
30
+ it 'should start with the default management endpoint' do
31
+ Azure.management_endpoint.must_equal Azure::Default.management_endpoint
32
+ end
33
+
34
+ describe 'configuration of management certificates with files and strings' do
35
+ let(:private_key) {Azure.http_private_key}
36
+ let(:public_key) {Azure.http_certificate_key}
37
+
38
+ describe 'using a pfx' do
39
+
40
+ describe 'loaded as a string' do
41
+ before do
42
+ Azure.management_certificate = File.binread(Fixtures['management_certificate.pfx'])
43
+ end
44
+
45
+ it 'should populate the private key' do
46
+ refute_nil(private_key)
47
+ private_key.must_be_kind_of(OpenSSL::PKey::RSA)
48
+ end
49
+
50
+ it 'should populate the public key' do
51
+ refute_nil(public_key)
52
+ public_key.must_be_kind_of(OpenSSL::X509::Certificate)
53
+ end
54
+
55
+ end
56
+
57
+ describe 'loaded as a file' do
58
+ before do
59
+ Azure.management_certificate = Fixtures['management_certificate.pfx']
60
+ end
61
+
62
+ it 'should populate the private key' do
63
+ refute_nil(private_key)
64
+ private_key.must_be_kind_of(OpenSSL::PKey::RSA)
65
+ end
66
+
67
+ it 'should populate the public key' do
68
+ refute_nil(public_key)
69
+ public_key.must_be_kind_of(OpenSSL::X509::Certificate)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'using a pem' do
75
+
76
+ describe 'loaded as a string' do
77
+ before do
78
+ Azure.management_certificate = File.read(Fixtures['management_certificate.pem'])
79
+ end
80
+
81
+ it 'should populate the private key' do
82
+ refute_nil(private_key)
83
+ private_key.must_be_kind_of(OpenSSL::PKey::RSA)
84
+ end
85
+
86
+ it 'should populate the public key' do
87
+ refute_nil(public_key)
88
+ public_key.must_be_kind_of(OpenSSL::X509::Certificate)
89
+ end
90
+
91
+ end
92
+
93
+ describe 'loaded as a file' do
94
+ before do
95
+ Azure.management_certificate = Fixtures['management_certificate.pem']
96
+ end
97
+
98
+ it 'should populate the private key' do
99
+ refute_nil(private_key)
100
+ private_key.must_be_kind_of(OpenSSL::PKey::RSA)
101
+ end
102
+
103
+ it 'should populate the public key' do
104
+ refute_nil(public_key)
105
+ public_key.must_be_kind_of(OpenSSL::X509::Certificate)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,37 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'test_helper'
16
+
17
+ describe Azure::Client do
18
+
19
+ describe 'default configuration for a client instance' do
20
+ subject { Azure.client }
21
+
22
+ Azure::Configurable.keys.each do |key|
23
+ it "should have the same value as its parent for #{key}" do
24
+ subject.send(key.to_sym).must_equal Azure.send(key.to_sym)
25
+ end
26
+
27
+ unless key == :management_certificate ## TODO: generate another pem and pfx for file / string tests then remove this
28
+ it "should have a different value as its parent after changing the client for #{key}" do
29
+ subject.send("#{key}=".to_sym, 'blah')
30
+ subject.send(key.to_sym).wont_equal Azure.send(key.to_sym)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -12,37 +12,37 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "test_helper"
16
- require "azure/core/auth/shared_key_lite"
15
+ require 'test_helper'
16
+ require 'azure/core/auth/shared_key_lite'
17
17
 
18
18
  describe Azure::Core::Auth::SharedKeyLite do
19
- subject { Azure::Core::Auth::SharedKeyLite.new "account-name", "YWNjZXNzLWtleQ==" }
19
+ subject { Azure::Core::Auth::SharedKeyLite.new 'account-name', 'YWNjZXNzLWtleQ==' }
20
20
 
21
- let(:verb) { "POST" }
22
- let(:uri) { URI.parse "http://dummy.uri/resource" }
21
+ let(:verb) { 'POST' }
22
+ let(:uri) { URI.parse 'http://dummy.uri/resource' }
23
23
  let(:headers) do
24
24
  {
25
- "Content-MD5"=> "foo",
26
- "Content-Type"=> "foo",
27
- "Date"=> "foo"
25
+ 'Content-MD5' => 'foo',
26
+ 'Content-Type' => 'foo',
27
+ 'Date' => 'foo'
28
28
  }
29
29
  end
30
30
  let(:headers_without_date) {
31
31
  headers_without_date = headers.clone
32
- headers_without_date.delete "Date"
32
+ headers_without_date.delete 'Date'
33
33
  headers_without_date
34
34
  }
35
35
 
36
- describe "sign" do
37
- it "creates a signature from the provided HTTP method, uri, and reduced set of standard headers" do
38
- subject.sign(verb, uri, headers).must_equal "account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE="
36
+ describe 'sign' do
37
+ it 'creates a signature from the provided HTTP method, uri, and reduced set of standard headers' do
38
+ subject.sign(verb, uri, headers).must_equal 'account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE='
39
39
  end
40
40
 
41
- it "ignores standard headers other than Content-MD5, Content-Type, and Date" do
42
- subject.sign(verb, uri, headers.merge({"Content-Encoding"=> "foo"})).must_equal "account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE="
41
+ it 'ignores standard headers other than Content-MD5, Content-Type, and Date' do
42
+ subject.sign(verb, uri, headers.merge({'Content-Encoding' => 'foo'})).must_equal 'account-name:vVFnj/+27JFABZgpt5H8g/JVU2HuWFnjv5aeUIxQvBE='
43
43
  end
44
44
 
45
- it "throws IndexError when there is no Date header" do
45
+ it 'throws IndexError when there is no Date header' do
46
46
  assert_raises IndexError do
47
47
  subject.sign(verb, uri, headers_without_date)
48
48
  end
@@ -12,47 +12,47 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "test_helper"
16
- require "azure/core/auth/shared_key"
15
+ require 'test_helper'
16
+ require 'azure/core/auth/shared_key'
17
17
 
18
18
  describe Azure::Core::Auth::SharedKey do
19
- subject { Azure::Core::Auth::SharedKey.new "account-name", "YWNjZXNzLWtleQ==" }
19
+ subject { Azure::Core::Auth::SharedKey.new 'account-name', 'YWNjZXNzLWtleQ==' }
20
20
 
21
- let(:verb) { "POST" }
22
- let(:uri) { URI.parse "http://dummy.uri/resource" }
21
+ let(:verb) { 'POST' }
22
+ let(:uri) { URI.parse 'http://dummy.uri/resource' }
23
23
  let(:headers) do
24
24
  {
25
- "Content-Encoding"=> "foo",
26
- "Content-Language"=> "foo",
27
- "Content-Length"=> "foo",
28
- "Content-MD5"=> "foo",
29
- "Content-Type"=> "foo",
30
- "Date"=> "foo",
31
- "If-Modified-Since"=> "foo",
32
- "If-Match"=> "foo",
33
- "If-None-Match"=> "foo",
34
- "If-Unmodified-Since"=> "foo",
35
- "Range"=> "foo",
36
- "x-ms-ImATeapot"=> "teapot",
37
- "x-ms-ShortAndStout"=>"True"
25
+ 'Content-Encoding' => 'foo',
26
+ 'Content-Language' => 'foo',
27
+ 'Content-Length' => 'foo',
28
+ 'Content-MD5' => 'foo',
29
+ 'Content-Type' => 'foo',
30
+ 'Date' => 'foo',
31
+ 'If-Modified-Since' => 'foo',
32
+ 'If-Match' => 'foo',
33
+ 'If-None-Match' => 'foo',
34
+ 'If-Unmodified-Since' => 'foo',
35
+ 'Range' => 'foo',
36
+ 'x-ms-ImATeapot' => 'teapot',
37
+ 'x-ms-ShortAndStout' => 'True'
38
38
  }
39
39
  end
40
40
 
41
- describe "sign" do
42
- it "creates a signature from the provided HTTP method, uri, and a specific set of standard headers" do
43
- subject.sign(verb, uri, headers).must_equal "account-name:vcdxlDVoE1QvJerkg0ci3Wlnj2Qq8yzlsrkRf5dEU/I="
41
+ describe 'sign' do
42
+ it 'creates a signature from the provided HTTP method, uri, and a specific set of standard headers' do
43
+ subject.sign(verb, uri, headers).must_equal 'account-name:vcdxlDVoE1QvJerkg0ci3Wlnj2Qq8yzlsrkRf5dEU/I='
44
44
  end
45
45
  end
46
46
 
47
- describe "canonicalized_headers" do
48
- it "creates a canonicalized header string" do
47
+ describe 'canonicalized_headers' do
48
+ it 'creates a canonicalized header string' do
49
49
  subject.canonicalized_headers(headers).must_equal "x-ms-imateapot:teapot\nx-ms-shortandstout:True"
50
50
  end
51
51
  end
52
52
 
53
- describe "canonicalized_resource" do
54
- it "creates a canonicalized resource string" do
55
- subject.canonicalized_resource(uri).must_equal "/account-name/resource"
53
+ describe 'canonicalized_resource' do
54
+ it 'creates a canonicalized resource string' do
55
+ subject.canonicalized_resource(uri).must_equal '/account-name/resource'
56
56
  end
57
57
  end
58
58
  end
@@ -12,23 +12,23 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "test_helper"
16
- require "azure/core/http/http_error"
15
+ require 'test_helper'
16
+ require 'azure/core/http/http_error'
17
17
 
18
18
  describe Azure::Core::Http::HTTPError do
19
19
  let :http_response do
20
- stub(:body => Fixtures[:http_error], :status_code => 409, :uri => 'http://dummy.uri')
20
+ stub(body: Fixtures[:http_error], status_code: 409, uri: 'http://dummy.uri', headers: {})
21
21
  end
22
22
 
23
23
  subject do
24
24
  Azure::Core::Http::HTTPError.new(http_response)
25
25
  end
26
26
 
27
- it "is an instance of Azure::Core::Error" do
27
+ it 'is an instance of Azure::Core::Error' do
28
28
  subject.must_be_kind_of Azure::Core::Error
29
29
  end
30
30
 
31
- it "lets us see the original uri" do
31
+ it 'lets us see the original uri' do
32
32
  subject.uri.must_equal 'http://dummy.uri'
33
33
  end
34
34
 
@@ -37,26 +37,25 @@ describe Azure::Core::Http::HTTPError do
37
37
  end
38
38
 
39
39
  it "lets us see the error's type" do
40
- subject.type.must_equal "TableAlreadyExists"
40
+ subject.type.must_equal 'TableAlreadyExists'
41
41
  end
42
42
 
43
43
  it "lets us see the error's description" do
44
- subject.description.must_equal "The table specified already exists."
44
+ subject.description.must_equal 'The table specified already exists.'
45
45
  end
46
46
 
47
- it "generates an error message that wraps both the type and description" do
48
- subject.message.must_equal "TableAlreadyExists (409): The table specified already exists."
47
+ it 'generates an error message that wraps both the type and description' do
48
+ subject.message.must_equal 'TableAlreadyExists (409): The table specified already exists.'
49
49
  end
50
50
 
51
51
  describe 'with invalid http_response body' do
52
-
53
52
  let :http_response do
54
- stub(:body => "\r\nInvalid request\r\n", :status_code => 409, :uri => 'http://dummy.uri')
53
+ stub(:body => "\r\nInvalid request\r\n", :status_code => 409, :uri => 'http://dummy.uri', headers: {})
55
54
  end
56
55
 
57
- it "sets the type to unknown if the response body is not an XML" do
58
- subject.type.must_equal "Unknown"
59
- subject.description.must_equal "Invalid request"
56
+ it 'sets the type to unknown if the response body is not an XML' do
57
+ subject.type.must_equal 'Unknown'
58
+ subject.description.must_equal 'Invalid request'
60
59
  end
61
60
  end
62
61
  end
@@ -16,9 +16,11 @@ require 'test_helper'
16
16
  require 'azure/core/http/http_request'
17
17
 
18
18
  describe Azure::Core::Http::HttpRequest do
19
+ let(:uri) { URI('http://example.com') }
20
+
19
21
  describe ' default_headers ' do
20
- subject do
21
- Azure::Core::Http::HttpRequest.new(:get, URI('/'), nil, 'Thu, 04 Oct 2012 06:38:27 GMT')
22
+ subject do
23
+ Azure::Core::Http::HttpRequest.new(:get, uri, body: nil, current_time: 'Thu, 04 Oct 2012 06:38:27 GMT')
22
24
  end
23
25
 
24
26
  it 'sets the x-ms-date header to the current_time' do
@@ -36,77 +38,100 @@ describe Azure::Core::Http::HttpRequest do
36
38
  it 'sets the MaxDataServiceVersion header to the current max` API version' do
37
39
  subject.headers['MaxDataServiceVersion'] = '2.0;NetFx'
38
40
  end
41
+ end
39
42
 
40
- let :http do
41
- mock = Minitest::Mock.new
42
- mock.expect(:use_ssl=, true, [true])
43
- mock.expect(:verify_mode=, OpenSSL::SSL::VERIFY_PEER, [1])
44
- mock.expect(:request, Net::HTTPResponse.new(1.1, 200, '<body/>'), [Net::HTTP::Get])
45
- mock
43
+ describe 'when passed custom headers' do
44
+ subject do
45
+ Azure::Core::Http::HttpRequest.new(:get,
46
+ uri,
47
+ body: nil,
48
+ headers: {
49
+ 'blah' => 'something',
50
+ 'x-ms-version' => '123'
51
+ })
46
52
  end
47
53
 
48
- describe 'when not using a ca_file' do
49
- subject do
50
- Azure::Core::Http::HttpRequest.new(:get, URI('https://manage.windowsazure.com'), nil, 'Thu, 04 Oct 2012 06:38:27 GMT')
51
- end
54
+ it 'should have overridden the value of x-ms-version' do
55
+ subject.headers['x-ms-version'].must_equal '123'
56
+ end
52
57
 
53
- it 'should set the ca_file on the http request' do
54
- Net::HTTP.stub(:new, http) do
55
- subject.call
56
- end
57
- http.verify
58
- end
58
+ it 'should have added in the blah = something header' do
59
+ subject.headers['blah'].must_equal 'something'
59
60
  end
60
61
 
61
- describe 'when using a ca_file' do
62
- before do
63
- Azure.config.ca_file = './blah.pem'
64
- end
62
+ end
65
63
 
66
- after do
67
- Azure.config.ca_file = nil
68
- end
64
+ describe ' when passed a body ' do
65
+ subject do
66
+ Azure::Core::Http::HttpRequest.new(:post, uri, body: '<body/>')
67
+ end
69
68
 
70
- subject do
71
- Azure::Core::Http::HttpRequest.new(:get, URI('https://manage.windowsazure.com'), nil, 'Thu, 04 Oct 2012 06:38:27 GMT')
72
- end
69
+ it 'sets the default Content-Type header' do
70
+ subject.headers['Content-Type'].must_equal 'application/atom+xml; charset=utf-8'
71
+ end
73
72
 
74
- let :ca_http do
75
- http.expect(:ca_file=, Azure.config.ca_file, [String])
76
- end
73
+ it 'sets the Content-Length header' do
74
+ subject.headers['Content-Length'].must_equal '7'
75
+ end
77
76
 
78
- it 'should set the ca_file on the http request' do
79
- Net::HTTP.stub(:new, ca_http) do
80
- subject.call
81
- end
82
- ca_http.verify
83
- end
77
+ it 'sets the Content-MD5 header to a Base64 encoded representation of the MD5 hash of the body' do
78
+ subject.headers['Content-MD5'].must_equal 'PNeJy7qyzV4XUoBBHkVu0g=='
79
+ end
80
+ end
84
81
 
82
+ describe ' when the body is nil ' do
83
+ subject do
84
+ Azure::Core::Http::HttpRequest.new(:get, uri)
85
85
  end
86
86
 
87
- describe ' when passed a body ' do
88
- subject do
89
- Azure::Core::Http::HttpRequest.new(:get, URI('/'), '<body/>')
90
- end
87
+ it 'leaves the Content-Type, Content-Length, and Content-MD5 headers blank' do
88
+ subject.headers['Content-Length'].must_equal '0'
89
+ subject.headers['Content-MD5'].must_be_nil
90
+ end
91
+ end
91
92
 
92
- it 'sets the default Content-Type header' do
93
- subject.headers['Content-Type'].must_equal 'application/atom+xml; charset=utf-8'
94
- end
93
+ describe '#call' do
94
+
95
+ let(:mock_conn) do
96
+ conn = mock
97
+ conn.expects(:run_request, [uri, nil, nil]).returns(mock_res)
98
+ conn
99
+ end
100
+
101
+ subject do
102
+ sub = Azure::Core::Http::HttpRequest.new(:get, uri)
103
+ sub.expects(:http_setup).returns(mock_conn)
104
+ sub
105
+ end
106
+
107
+ describe 'on success' do
108
+ let(:body) { '</body>' }
95
109
 
96
- it 'sets the Content-Length header' do
97
- subject.headers['Content-Length'].must_equal '7'
110
+ let(:mock_res) do
111
+ res = mock
112
+ res.expects(:success?).returns(true)
113
+ res.expects(:body).returns(body)
114
+ res
98
115
  end
99
116
 
100
- it 'sets the Content-MD5 header to a Base64 encoded representation of the MD5 hash of the body' do
101
- subject.headers['Content-MD5'].must_equal 'PNeJy7qyzV4XUoBBHkVu0g=='
117
+ it 'should return a response' do
118
+ subject.call.body.must_equal(body)
102
119
  end
103
120
  end
104
121
 
105
- describe ' when the body is nil ' do
106
- it 'leaves the Content-Type, Content-Length, and Content-MD5 headers blank' do
107
- subject.headers['Content-Type'].must_equal ''
108
- subject.headers['Content-Length'].must_equal '0'
109
- subject.headers['Content-MD5'].must_be_nil
122
+ describe 'on failure' do
123
+ let(:body) { 'OH NO!!' }
124
+
125
+ let(:mock_res) do
126
+ res = mock
127
+ res.expects(:success?).returns(false).at_least_once
128
+ res.expects(:status).returns(401).at_least_once
129
+ res.expects(:body).returns(body).at_least_once
130
+ res
131
+ end
132
+
133
+ it 'should return a response' do
134
+ -> { subject.call }.must_raise(Azure::Core::Http::HTTPError)
110
135
  end
111
136
  end
112
137
  end