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.
- checksums.yaml +4 -4
- data/.env_sample +3 -1
- data/.gitignore +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +322 -248
- data/Rakefile +3 -1
- data/azure.gemspec +18 -14
- data/lib/azure.rb +124 -38
- data/lib/azure/base_management/base_management_service.rb +57 -69
- data/lib/azure/base_management/location.rb +1 -1
- data/lib/azure/base_management/management_http_request.rb +55 -58
- data/lib/azure/base_management/serialization.rb +5 -0
- data/lib/azure/base_management/sql_management_http_request.rb +10 -20
- data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
- data/lib/azure/blob/blob_service.rb +196 -171
- data/lib/azure/client.rb +31 -0
- data/lib/azure/client_services.rb +98 -0
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
- data/lib/azure/configurable.rb +290 -0
- data/lib/azure/core/auth/authorizer.rb +1 -1
- data/lib/azure/core/auth/shared_key.rb +48 -40
- data/lib/azure/core/auth/shared_key_lite.rb +9 -9
- data/lib/azure/core/auth/signer.rb +15 -12
- data/lib/azure/core/error.rb +2 -3
- data/lib/azure/core/filtered_service.rb +4 -3
- data/lib/azure/core/http/http_error.rb +10 -12
- data/lib/azure/core/http/http_request.rb +82 -69
- data/lib/azure/core/http/http_response.rb +12 -56
- data/lib/azure/core/http/signer_filter.rb +3 -4
- data/lib/azure/core/service.rb +8 -25
- data/lib/azure/core/signed_service.rb +7 -5
- data/lib/azure/core/utility.rb +45 -6
- data/lib/azure/default.rb +126 -0
- data/lib/azure/http_client.rb +85 -0
- data/lib/azure/queue/queue.rb +0 -1
- data/lib/azure/queue/queue_service.rb +6 -4
- data/lib/azure/queue/serialization.rb +0 -1
- data/lib/azure/service/storage_service.rb +9 -6
- data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
- data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
- data/lib/azure/service_bus/service_bus_service.rb +34 -30
- data/lib/azure/sql_database_management/errors.rb +11 -0
- data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
- data/lib/azure/sql_database_management/serialization.rb +40 -53
- data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
- data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
- data/lib/azure/storage_management/storage_management_service.rb +9 -10
- data/lib/azure/table/auth/shared_key.rb +17 -50
- data/lib/azure/table/auth/shared_key_lite.rb +3 -3
- data/lib/azure/table/serialization.rb +24 -24
- data/lib/azure/table/table_service.rb +21 -18
- data/lib/azure/version.rb +1 -1
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
- data/lib/azure/virtual_machine_management/serialization.rb +4 -1
- data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
- data/test/fixtures/list_locations.xml +150 -0
- data/test/fixtures/list_sql_database.xml +6 -18
- data/test/fixtures/list_sql_server_firewall.xml +18 -18
- data/test/fixtures/management_certificate.pfx +0 -0
- data/test/fixtures/virtual_machine.xml +1 -0
- data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
- data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
- data/test/integration/blob/blob_gb18030_test.rb +29 -29
- data/test/integration/blob/blob_pages_test.rb +16 -16
- data/test/integration/blob/container/create_container_test.rb +6 -6
- data/test/integration/blob/container/root_container_test.rb +2 -1
- data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
- data/test/integration/database/create_sql_server_test.rb +6 -6
- data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
- data/test/integration/database/delete_sql_server_test.rb +9 -22
- data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
- data/test/integration/database/list_sql_servers_test.rb +4 -4
- data/test/integration/database/reset_password_sql_server_test.rb +9 -11
- data/test/integration/location/RoleSize_List_test.rb +35 -0
- data/test/integration/queue/list_queues_test.rb +0 -1
- data/test/integration/service_bus/queues_scenario_test.rb +11 -11
- data/test/integration/service_bus/queues_test.rb +2 -2
- data/test/integration/service_bus/subscriptions_test.rb +25 -25
- data/test/integration/service_bus/topics_scenario_test.rb +6 -6
- data/test/integration/service_bus/topics_test.rb +15 -15
- data/test/integration/table/query_entities_test.rb +1 -0
- data/test/integration/table/table_acl_test.rb +9 -9
- data/test/integration/test_helper.rb +11 -9
- data/test/integration/vm/VM_Create_test.rb +23 -20
- data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
- data/test/test_helper.rb +5 -0
- data/test/unit/affinity_group/affinity_group_test.rb +4 -4
- data/test/unit/base_management/base_management_service_test.rb +19 -0
- data/test/unit/base_management/location_test.rb +6 -6
- data/test/unit/base_management/role_size_test.rb +50 -0
- data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
- data/test/unit/blob/blob_service_test.rb +583 -582
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
- data/test/unit/config/azure_test.rb +112 -0
- data/test/unit/config/client_test.rb +37 -0
- data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
- data/test/unit/core/auth/shared_key_test.rb +26 -26
- data/test/unit/core/http/http_error_test.rb +13 -14
- data/test/unit/core/http/http_request_test.rb +78 -53
- data/test/unit/core/http/http_response_test.rb +2 -27
- data/test/unit/core/http/retry_policy_test.rb +3 -3
- data/test/unit/core/utility_test.rb +122 -0
- data/test/unit/database/serialization_test.rb +17 -20
- data/test/unit/database/sql_database_server_service_test.rb +97 -40
- data/test/unit/http_client_test.rb +74 -0
- data/test/unit/service/storage_service_test.rb +105 -101
- data/test/unit/storage_management/storage_management_service_test.rb +28 -28
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
- data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
- metadata +91 -20
- data/lib/azure/core.rb +0 -41
- 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,
|
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,
|
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
|
16
|
-
require
|
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
|
19
|
+
subject { Azure::Core::Auth::SharedKeyLite.new 'account-name', 'YWNjZXNzLWtleQ==' }
|
20
20
|
|
21
|
-
let(:verb) {
|
22
|
-
let(:uri) { URI.parse
|
21
|
+
let(:verb) { 'POST' }
|
22
|
+
let(:uri) { URI.parse 'http://dummy.uri/resource' }
|
23
23
|
let(:headers) do
|
24
24
|
{
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
32
|
+
headers_without_date.delete 'Date'
|
33
33
|
headers_without_date
|
34
34
|
}
|
35
35
|
|
36
|
-
describe
|
37
|
-
it
|
38
|
-
subject.sign(verb, uri, headers).must_equal
|
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
|
42
|
-
subject.sign(verb, uri, headers.merge({
|
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
|
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
|
16
|
-
require
|
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
|
19
|
+
subject { Azure::Core::Auth::SharedKey.new 'account-name', 'YWNjZXNzLWtleQ==' }
|
20
20
|
|
21
|
-
let(:verb) {
|
22
|
-
let(:uri) { URI.parse
|
21
|
+
let(:verb) { 'POST' }
|
22
|
+
let(:uri) { URI.parse 'http://dummy.uri/resource' }
|
23
23
|
let(:headers) do
|
24
24
|
{
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
42
|
-
it
|
43
|
-
subject.sign(verb, uri, headers).must_equal
|
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
|
48
|
-
it
|
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
|
54
|
-
it
|
55
|
-
subject.canonicalized_resource(uri).must_equal
|
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
|
16
|
-
require
|
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(:
|
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
|
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
|
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
|
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
|
44
|
+
subject.description.must_equal 'The table specified already exists.'
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
subject.message.must_equal
|
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
|
58
|
-
subject.type.must_equal
|
59
|
-
subject.description.must_equal
|
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,
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
49
|
-
subject
|
50
|
-
|
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
|
-
|
54
|
-
|
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
|
-
|
62
|
-
before do
|
63
|
-
Azure.config.ca_file = './blah.pem'
|
64
|
-
end
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
73
|
+
it 'sets the Content-Length header' do
|
74
|
+
subject.headers['Content-Length'].must_equal '7'
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
88
|
-
subject
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
97
|
-
|
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 '
|
101
|
-
subject.
|
117
|
+
it 'should return a response' do
|
118
|
+
subject.call.body.must_equal(body)
|
102
119
|
end
|
103
120
|
end
|
104
121
|
|
105
|
-
describe '
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|