azure-signature 0.2.3 → 0.3.0

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
- SHA1:
3
- metadata.gz: 67998efc651f21fe011dff305c335e58ab630ce3
4
- data.tar.gz: 34f0ff58db45b64f69f577a6c4aa2edb13a5c836
2
+ SHA256:
3
+ metadata.gz: a1d7b17a77af5f1a76b3b5d1b9fbeb46f6754998523b57f6d4124e665f3f495c
4
+ data.tar.gz: c0a6be0e98f9ec3337446e5d0cb992033969ff8f3f196bf55971beac27ea1028
5
5
  SHA512:
6
- metadata.gz: 1b6d5fb5159bdc93a5e1f1555fad7548cac8eb49d4139ea714cee0b6d12c26ddd6f3586cf8f2cb96fc22ad822a1a652ce2375dbd0f2a552206e83b5625c5a3e1
7
- data.tar.gz: 046b15029d5559079502cf1f4c50eeb19c88c897d080f6c5afec2350cb00953dd471abe83b01f4fdf98c834f4eebc486e3c41d88c723274c6b8d1b57041b09e7
6
+ metadata.gz: 500ecbcfacceddb006b1d0e0d69e749bbdc2777ebfbe3fbcd38b7b3e46eb3a796943e766f6d0396fdcdad79192713a62d65c18cedf061ba0d00efa98e92e753e
7
+ data.tar.gz: '079ecc0b95f1356a4e70af62ec6918b031b3994531a65c4d333ee49b12c7ffec30c0032737f580a0615bec42420fcd9e00c7f7e3a2d5ff785a4ef10087dcabf6'
@@ -0,0 +1,28 @@
1
+ ## Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## 0.3.0 - 19-Mar-2020
6
+ - Fix license name in gemspec (was missing hyphen).
7
+ - Include a LICENSE file with the distribution as mandated by the Apache-2.0 license.
8
+ - Use markdown format for CHANGELOG and MANIFEST, and add .md extension.
9
+ - Added activesupport as a dependency.
10
+
11
+ ## 0.2.3 - 19-Jul-2016
12
+ - Removed the cgi dependency.
13
+
14
+ ## 0.2.2 - 17-Jun-2016
15
+ - The resource argument to the constructor is now automatically escaped.
16
+
17
+ ## 0.2.1 - 13-Jun-2016
18
+ - The signature methods now accept standard header strings as key arguments
19
+ as well as symbols, e.g. `'auth-type'` vs `:auth_type`.
20
+ - Replaced URI with Addressable::URI since it's more robust.
21
+
22
+ ## 0.2.0 - 13-Oct-2015
23
+ - Added support for other types of signatures (blobs, queues, files).
24
+ - The `:auth_string` argument no longer returns the word "Authorization".
25
+ - Added an azure-signature file for convenience.
26
+
27
+ ## 0.1.0 - 25-Sep-2015
28
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
File without changes
@@ -0,0 +1,48 @@
1
+ ## Description
2
+
3
+ A Ruby library for generating an authentication signature for Azure storage services.
4
+
5
+ ## Installation
6
+
7
+ `gem install azure-signature`
8
+
9
+ ## Synopis
10
+
11
+ ```ruby
12
+ require 'azure/signature'
13
+
14
+ key = "SGVsbG8gV29ybGQ="
15
+ url = "http://testsnapshots.blob.core.windows.net/Tables"
16
+
17
+ sig = Azure::Signature.new(url, key)
18
+
19
+ # Look at canonical URL
20
+ p sig.canonical_url # => "/testsnapshots/Tables"
21
+
22
+ # Get a signature with the defaults
23
+ p sig.signature(:table)
24
+
25
+ # Or pass some options
26
+ p sig.signature(:table, :auth_string => true, :date => some_date, :verb => 'PUT')
27
+ ```
28
+
29
+ ## Acknowledgements
30
+
31
+ I borrowed the code to canonicalize resources and headers from the
32
+ azure-sdk-for-ruby project.
33
+
34
+ ## License
35
+
36
+ Apache-2.0
37
+
38
+ http://www.apache.org/licenses/LICENSE-2.0
39
+
40
+ ## Warranty
41
+
42
+ This package is provided "as is" and without any express or
43
+ implied warranties, including, without limitation, the implied
44
+ warranties of merchantability and fitness for a particular purpose.
45
+
46
+ ## Author
47
+
48
+ Daniel Berger
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
4
6
 
5
7
  CLEAN.include("**/*.gem", "**/*.rbc")
6
8
 
@@ -19,9 +21,4 @@ namespace :gem do
19
21
  end
20
22
  end
21
23
 
22
- Rake::TestTask.new do |t|
23
- t.warning = true
24
- t.verbose = true
25
- end
26
-
27
- task :default => :test
24
+ task :default => :spec
@@ -1,24 +1,34 @@
1
1
  require 'rubygems'
2
2
 
3
- Gem::Specification.new do |gem|
4
- gem.name = 'azure-signature'
5
- gem.version = '0.2.3'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Apache 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://github.com/djberg96/azure-signature'
10
- gem.summary = 'Generate authentication signatures for Azure'
11
- gem.test_file = 'test/test_signature.rb'
12
- gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'azure-signature'
5
+ spec.version = '0.3.0'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Apache-2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/azure-signature'
10
+ spec.summary = 'Generate authentication signatures for Azure'
11
+ spec.test_file = 'spec/azure_signature_spec.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
 
14
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
+ spec.extra_rdoc_files = ['README.md', 'CHANGELOG.md', 'MANIFEST.md']
15
15
 
16
- gem.add_dependency('addressable')
17
- gem.add_development_dependency('test-unit')
16
+ spec.add_dependency('addressable', '~> 2')
17
+ spec.add_dependency('activesupport', '>= 4.2.2')
18
+ spec.add_development_dependency('rspec', '~> 3')
18
19
 
19
- gem.description = <<-EOF
20
+ spec.description = <<-EOF
20
21
  The azure-signature library generates storage signatures for
21
22
  Microsoft Azure's cloud platform. You can use this to access
22
23
  Azure storage services - tables, blobs, queues and files.
23
24
  EOF
25
+
26
+ spec.metadata = {
27
+ 'homepage_uri' => 'https://github.com/ManageIQ/azure-signature',
28
+ 'bug_tracker_uri' => 'https://github.com/ManageIQ/azure-signature/issues',
29
+ 'changelog_uri' => 'https://github.com/ManageIQ/azure-signature/blob/master/CHANGELOG.md',
30
+ 'documentation_uri' => 'https://github.com/ManageIQ/azure-signature/wiki',
31
+ 'source_code_uri' => 'https://github.com/ManageIQ/azure-signature',
32
+ 'wiki_uri' => 'https://github.com/ManageIQ/azure-signature/wiki'
33
+ }
24
34
  end
@@ -2,13 +2,14 @@ require 'addressable'
2
2
  require 'openssl'
3
3
  require 'base64'
4
4
  require 'time'
5
+ require 'active_support/core_ext/hash/conversions'
5
6
 
6
7
  # The Azure module serves as a namespace.
7
8
  module Azure
8
9
  # The Signature class encapsulates an canonicalized resource string.
9
10
  class Signature
10
11
  # The version of the azure-signature library.
11
- VERSION = '0.2.3'
12
+ VERSION = '0.3.0'.freeze
12
13
 
13
14
  # The resource (URL) passed to the constructor.
14
15
  attr_reader :resource
@@ -25,6 +26,8 @@ module Azure
25
26
  # A URI object that encapsulates the resource.
26
27
  attr_reader :uri
27
28
 
29
+ attr_accessor :storage_services_version
30
+
28
31
  alias url resource
29
32
  alias canonical_url canonical_resource
30
33
 
@@ -42,6 +45,7 @@ module Azure
42
45
  @account_name = @uri.host.split(".").first.split("-").first
43
46
  @key = Base64.strict_decode64(key)
44
47
  @canonical_resource = canonicalize_resource(@uri)
48
+ @storage_services_version = '2016-05-31'
45
49
  end
46
50
 
47
51
  # Generate a signature for use with the table service. Use the +options+
@@ -62,11 +66,11 @@ module Azure
62
66
  # for future http requests to (presumably) Azure storage endpoints.
63
67
  #
64
68
  def table_signature(options = {})
65
- options.clone.each{ |k,v| options[k.to_s.downcase.tr('_', '-')] = v }
69
+ options = options.transform_keys { |key| key.to_s.downcase.tr('_', '-') }
66
70
 
67
71
  auth_type = options['auth-type'] || 'SharedKey'
68
72
  verb = options['verb'] || 'GET'
69
- date = options['date'] || Time.now.httpdate
73
+ date = options['date'] || options['x-ms-date'] || Time.now.httpdate
70
74
  auth_string = options['auth-string'] || false
71
75
  content_md5 = options['content-md5']
72
76
  content_type = options['content-type']
@@ -95,7 +99,7 @@ module Azure
95
99
  # - :auth_type. Either 'SharedKey' (the default) or 'SharedKeyLight'.
96
100
  # - :verb. The http verb used for SharedKey auth. The default is 'GET'.
97
101
  # - :x_ms_date. The x-ms-date used. The default is Time.now.httpdate.
98
- # - :x_ms_version. The x-ms-version used. The default is '2015-02-21'.
102
+ # - :x_ms_version. The x-ms-version used. The default is '2016-05-31'.
99
103
  # - :auth_string. If true, prepends the auth_type + account name to the
100
104
  # result and returns a string. The default is false.
101
105
  #
@@ -130,7 +134,7 @@ module Azure
130
134
  #
131
135
  # sig = Signature.new(url, key)
132
136
  # date = Time.now.httpdate
133
- # vers = '2015-02-21'
137
+ # vers = '2016-05-31'
134
138
  #
135
139
  # headers = {
136
140
  # 'x-ms-date' => date,
@@ -152,18 +156,19 @@ module Azure
152
156
  # p response.body
153
157
  #
154
158
  def blob_signature(headers = {})
155
- headers.clone.each{ |k,v| headers[k.to_s.downcase.tr('_', '-')] = v }
159
+ headers = headers.transform_keys { |key| key.to_s.downcase.tr('_', '-') }
156
160
 
161
+ # These are not actually headers, but internally used options
157
162
  auth_string = headers.delete('auth-string') || false
158
- auth_type = headers.delete('auth_type') || 'SharedKey'
163
+ auth_type = headers.delete('auth-type') || 'SharedKey'
159
164
  verb = headers.delete('verb') || 'GET'
160
165
 
161
166
  unless ['SharedKey', 'SharedKeyLight'].include?(auth_type)
162
- raise ArgumentError, "auth type must be SharedKey or SharedKeyLight"
167
+ raise ArgumentError, "auth type must be 'SharedKey' or 'SharedKeyLight'"
163
168
  end
164
169
 
165
- headers['x-ms-date'] ||= Time.now.httpdate
166
- headers['x-ms-version'] ||= '2015-02-21'
170
+ headers['x-ms-date'] ||= headers['date'] || Time.now.httpdate
171
+ headers['x-ms-version'] ||= headers['version'] || storage_services_version
167
172
 
168
173
  if auth_type == 'SharedKeyLight'
169
174
  headers['date'] ||= headers['x-ms-date'] || Time.now.httpdate
@@ -198,7 +203,7 @@ module Azure
198
203
  private
199
204
 
200
205
  def generate_string(verb, headers, auth_type)
201
- headers.clone.keys.each{ |k| headers[k.to_s.downcase] = headers[k] }
206
+ headers = headers.transform_keys { |key| key.to_s.downcase.tr('_', '-') }
202
207
  canonical_headers = canonicalize_headers(headers)
203
208
 
204
209
  if auth_type == 'SharedKeyLight'
@@ -0,0 +1,112 @@
1
+ require 'rspec'
2
+ require 'azure/signature'
3
+
4
+ RSpec.describe Azure::Signature do
5
+ before do
6
+ @key = 'SGVsbG8gV29ybGQ='
7
+ @url = 'http://testsnapshots.blob.core.windows.net/?comp=list'
8
+ @sig = described_class.new(@url, @key)
9
+ end
10
+
11
+ context 'version constant' do
12
+ example 'version constant is set to expected value' do
13
+ expect(Azure::Signature::VERSION).to eql('0.3.0')
14
+ end
15
+
16
+ example "version constant is frozen" do
17
+ expect(Azure::Signature::VERSION).to be_frozen
18
+ end
19
+ end
20
+
21
+ context 'instance methods' do
22
+ example 'key method basic functionality' do
23
+ expect(@sig).to respond_to(:key)
24
+ expect(@sig.key).to be_kind_of(String)
25
+ end
26
+
27
+ example 'account_name basic functionality' do
28
+ expect(@sig).to respond_to(:account_name)
29
+ expect(@sig.account_name).to eq('testsnapshots')
30
+ end
31
+
32
+ example 'resource method basic functionality' do
33
+ expect(@sig).to respond_to(:resource)
34
+ expect(@sig.resource).to eq(@url)
35
+ end
36
+
37
+ example 'uri method basic functionality' do
38
+ expect(@sig).to respond_to(:uri)
39
+ expect(@sig.uri).to be_kind_of(Addressable::URI)
40
+ end
41
+
42
+ example 'url is an alias for the resource method' do
43
+ expect(@sig).to respond_to(:url)
44
+ expect(@sig.method(:url)).to eq(@sig.method(:resource))
45
+ end
46
+ end
47
+
48
+ context 'canonical resource' do
49
+ example 'canonical_resource method basic functionality' do
50
+ expect(@sig).to respond_to(:canonical_resource)
51
+ expect(@sig.canonical_resource).to be_kind_of(String)
52
+ end
53
+
54
+ example "canonical_url is an alias for the canonical_resource method" do
55
+ expect(@sig).to respond_to(:canonical_url)
56
+ expect(@sig.method(:canonical_url)).to eq(@sig.method(:canonical_resource))
57
+ end
58
+
59
+ example "canonical_resource returns the expected value for basic url" do
60
+ url = "http://myaccount.blob.core.windows.net/Tables"
61
+ sig = Azure::Signature.new(url, @key)
62
+ expect(sig.canonical_resource).to eq("/myaccount/Tables")
63
+ end
64
+
65
+ example "canonical_resource returns the expected value for url with query" do
66
+ url = "http://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=metadata"
67
+ sig = Azure::Signature.new(url, @key)
68
+ expect(sig.canonical_resource).to eq("/myaccount/mycontainer\ncomp:metadata\nrestype:container")
69
+ end
70
+
71
+ example "canonical_resource returns the expected value for url with multiple, identical query params" do
72
+ url = "http://myaccount.blob.core.windows.net/mycontainer?restype=container"
73
+ url << "&comp=list&include=snapshots&include=metadata&include=uncommittedblobs"
74
+ sig = Azure::Signature.new(url, @key)
75
+ expected = "/myaccount/mycontainer\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container"
76
+ expect(sig.canonical_resource).to eq(expected)
77
+ end
78
+
79
+ example "canonical_resource returns the expected value for secondary account" do
80
+ url = "https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob"
81
+ sig = Azure::Signature.new(url, @key)
82
+ expect(sig.canonical_resource).to eq("/myaccount/mycontainer/myblob")
83
+ end
84
+ end
85
+
86
+ context "constructor" do
87
+ example "constructor automatically escapes resource argument" do
88
+ url = "https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob-{12345}"
89
+ sig = Azure::Signature.new(url, @key)
90
+ expect(sig.canonical_resource).to eq("/myaccount/mycontainer/myblob-%7B12345%7D")
91
+ expect(sig.resource).to eq("https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob-%7B12345%7D")
92
+ end
93
+
94
+ example "constructor requires two arguments" do
95
+ expect{ Azure::Signature.new }.to raise_error(ArgumentError)
96
+ expect{ Azure::Signature.new('http://foo/bar') }.to raise_error(ArgumentError)
97
+ end
98
+
99
+ example "table_signature basic functionality" do
100
+ expect(@sig).to respond_to(:table_signature)
101
+ end
102
+
103
+ example "blob_signature basic functionality" do
104
+ expect(@sig).to respond_to(:blob_signature)
105
+ end
106
+
107
+ example "file_signature and queue_signature are aliases for blob_signature" do
108
+ expect(@sig.method(:blob_signature)).to eq(@sig.method(:file_signature))
109
+ expect(@sig.method(:blob_signature)).to eq(@sig.method(:queue_signature))
110
+ end
111
+ end
112
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-signature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2020-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: 4.2.2
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: 4.2.2
27
41
  - !ruby/object:Gem::Dependency
28
- name: test-unit
42
+ name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '3'
41
55
  description: |2
42
56
  The azure-signature library generates storage signatures for
43
57
  Microsoft Azure's cloud platform. You can use this to access
@@ -46,22 +60,29 @@ email: djberg96@gmail.com
46
60
  executables: []
47
61
  extensions: []
48
62
  extra_rdoc_files:
49
- - README
50
- - CHANGES
51
- - MANIFEST
63
+ - README.md
64
+ - CHANGELOG.md
65
+ - MANIFEST.md
52
66
  files:
53
- - CHANGES
54
- - MANIFEST
55
- - README
67
+ - CHANGELOG.md
68
+ - LICENSE
69
+ - MANIFEST.md
70
+ - README.md
56
71
  - Rakefile
57
72
  - azure-signature.gemspec
58
73
  - lib/azure-signature.rb
59
74
  - lib/azure/signature.rb
60
- - test/test_signature.rb
75
+ - spec/azure_signature_spec.rb
61
76
  homepage: http://github.com/djberg96/azure-signature
62
77
  licenses:
63
- - Apache 2.0
64
- metadata: {}
78
+ - Apache-2.0
79
+ metadata:
80
+ homepage_uri: https://github.com/ManageIQ/azure-signature
81
+ bug_tracker_uri: https://github.com/ManageIQ/azure-signature/issues
82
+ changelog_uri: https://github.com/ManageIQ/azure-signature/blob/master/CHANGELOG.md
83
+ documentation_uri: https://github.com/ManageIQ/azure-signature/wiki
84
+ source_code_uri: https://github.com/ManageIQ/azure-signature
85
+ wiki_uri: https://github.com/ManageIQ/azure-signature/wiki
65
86
  post_install_message:
66
87
  rdoc_options: []
67
88
  require_paths:
@@ -77,10 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
98
  - !ruby/object:Gem::Version
78
99
  version: '0'
79
100
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.6.4
101
+ rubygems_version: 3.0.6
82
102
  signing_key:
83
103
  specification_version: 4
84
104
  summary: Generate authentication signatures for Azure
85
105
  test_files:
86
- - test/test_signature.rb
106
+ - spec/azure_signature_spec.rb
data/CHANGES DELETED
@@ -1,18 +0,0 @@
1
- = 0.2.3 - 19-Jul-2016
2
- * Removed the cgi dependency.
3
-
4
- = 0.2.2 - 17-Jun-2016
5
- * The resource argument to the constructor is now automatically escaped.
6
-
7
- = 0.2.1 - 13-Jun-2016
8
- * The signature methods now accept standard header strings as key arguments
9
- as well as symbols, e.g. 'auth-type' vs :auth_type.
10
- * Replaced URI with Addressable::URI since it's more robust.
11
-
12
- = 0.2.0 - 13-Oct-2015
13
- * Added support for other types of signatures (blobs, queues, files).
14
- * The :auth_string argument no longer returns the word "Authorization".
15
- * Added an azure-signature file for convenience.
16
-
17
- = 0.1.0 - 25-Sep-2015
18
- * Initial release
data/README DELETED
@@ -1,38 +0,0 @@
1
- = Description
2
- A Ruby library for generating an authentication signature for Azure storage services.
3
-
4
- = Installation
5
- gem install azure-signature
6
-
7
- = Synopis
8
- require 'azure/signature'
9
-
10
- key = "SGVsbG8gV29ybGQ="
11
- url = "http://testsnapshots.blob.core.windows.net/Tables"
12
-
13
- sig = Azure::Signature.new(url, key)
14
-
15
- # Look at canonical URL
16
- p sig.canonical_url # => "/testsnapshots/Tables"
17
-
18
- # Get a signature with the defaults
19
- p sig.signature(:table)
20
-
21
- # Or pass some options
22
- p sig.signature(:table, :auth_string => true, :date => some_date, :verb => 'PUT')
23
-
24
- = Acknowledgements
25
- I borrowed the code to canonicalize resources and headers from the
26
- azure-sdk-for-ruby project.
27
-
28
- = License
29
- Apache 2.0
30
- http://www.apache.org/licenses/LICENSE-2.0
31
-
32
- = Warranty
33
- This package is provided "as is" and without any express or
34
- implied warranties, including, without limitation, the implied
35
- warranties of merchantability and fitness for a particular purpose.
36
-
37
- = Author
38
- Daniel Berger
@@ -1,110 +0,0 @@
1
- require 'test-unit'
2
- require 'azure/signature'
3
-
4
- class TC_Azure_Signature < Test::Unit::TestCase
5
- def setup
6
- @key = "SGVsbG8gV29ybGQ="
7
- @url = 'http://testsnapshots.blob.core.windows.net/?comp=list'
8
- @sig = Azure::Signature.new(@url, @key)
9
- end
10
-
11
- test "version constant is set to expected value" do
12
- assert_equal("0.2.3", Azure::Signature::VERSION)
13
- end
14
-
15
- test "key method basic functionality" do
16
- assert_respond_to(@sig, :key)
17
- assert_kind_of(String, @sig.key)
18
- end
19
-
20
- test "account_name basic functionality" do
21
- assert_respond_to(@sig, :account_name)
22
- assert_equal('testsnapshots', @sig.account_name)
23
- end
24
-
25
- test "resource method basic functionality" do
26
- assert_respond_to(@sig, :resource)
27
- assert_equal(@url, @sig.resource)
28
- end
29
-
30
- test "url is an alias for the resource method" do
31
- assert_respond_to(@sig, :url)
32
- assert_alias_method(@sig, :url, :resource)
33
- end
34
-
35
- test "uri method basic functionality" do
36
- assert_respond_to(@sig, :uri)
37
- assert_kind_of(Addressable::URI, @sig.uri)
38
- end
39
-
40
- test "canonical_resource method basic functionality" do
41
- assert_respond_to(@sig, :canonical_resource)
42
- assert_kind_of(String, @sig.canonical_resource)
43
- end
44
-
45
- test "canonical_url is an alias for the canonical_resource method" do
46
- assert_respond_to(@sig, :canonical_url)
47
- assert_alias_method(@sig, :canonical_url, :canonical_resource)
48
- end
49
-
50
- test "canonical_resource returns the expected value for basic url" do
51
- @url = "http://myaccount.blob.core.windows.net/Tables"
52
- @sig = Azure::Signature.new(@url, @key)
53
- expected = "/myaccount/Tables"
54
- assert_equal(expected, @sig.canonical_resource)
55
- end
56
-
57
- test "canonical_resource returns the expected value for url with query" do
58
- @url = "http://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=metadata"
59
- @sig = Azure::Signature.new(@url, @key)
60
- expected = "/myaccount/mycontainer\ncomp:metadata\nrestype:container"
61
- assert_equal(expected, @sig.canonical_resource)
62
- end
63
-
64
- test "canonical_resource returns the expected value for url with multiple, identical query params" do
65
- @url = "http://myaccount.blob.core.windows.net/mycontainer?restype=container"
66
- @url << "&comp=list&include=snapshots&include=metadata&include=uncommittedblobs"
67
- @sig = Azure::Signature.new(@url, @key)
68
- expected = "/myaccount/mycontainer\ncomp:list\ninclude:metadata,snapshots,"
69
- expected << "uncommittedblobs\nrestype:container"
70
- assert_equal(expected, @sig.canonical_resource)
71
- end
72
-
73
- test "canonical_resource returns the expected value for secondary account" do
74
- @url = "https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob"
75
- @sig = Azure::Signature.new(@url, @key)
76
- expected = "/myaccount/mycontainer/myblob"
77
- assert_equal(expected, @sig.canonical_resource)
78
- end
79
-
80
- test "constructor automatically escapes resource argument" do
81
- @url = "https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob-{12345}"
82
- @sig = Azure::Signature.new(@url, @key)
83
- assert_equal("/myaccount/mycontainer/myblob-%7B12345%7D", @sig.canonical_resource)
84
- assert_equal("https://myaccount-secondary.blob.core.windows.net/mycontainer/myblob-%7B12345%7D", @sig.resource)
85
- end
86
-
87
- test "constructor requires two arguments" do
88
- assert_raise(ArgumentError){ Azure::Signature.new }
89
- assert_raise(ArgumentError){ Azure::Signature.new('http://foo/bar') }
90
- end
91
-
92
- test "table_signature basic functionality" do
93
- assert_respond_to(@sig, :table_signature)
94
- end
95
-
96
- test "blob_signature basic functionality" do
97
- assert_respond_to(@sig, :blob_signature)
98
- end
99
-
100
- test "file_signature and queue_signature are aliases for blob_signature" do
101
- assert_alias_method(@sig, :blob_signature, :file_signature)
102
- assert_alias_method(@sig, :blob_signature, :queue_signature)
103
- end
104
-
105
- def teardown
106
- @key = nil
107
- @url = nil
108
- @sig = nil
109
- end
110
- end