pandexio 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +1,37 @@
1
- module Pandexio
2
-
3
- class SigningAlgorithms
4
-
5
- PDX_HMAC_MD5 = "PDX-HMAC-MD5"
6
- PDX_HMAC_SHA1 = "PDX-HMAC-SHA1"
7
- PDX_HMAC_SHA256 = "PDX-HMAC-SHA256"
8
- PDX_HMAC_SHA384 = "PDX-HMAC-SHA384"
9
- PDX_HMAC_SHA512 = "PDX-HMAC-SHA512"
10
-
11
- def self.is_v(a)
12
-
13
- return !a.nil? && a.is_a?(String) &&
14
- (a == PDX_HMAC_MD5 ||
15
- a == PDX_HMAC_SHA1 ||
16
- a == PDX_HMAC_SHA256 ||
17
- a == PDX_HMAC_SHA384 ||
18
- a == PDX_HMAC_SHA512)
19
-
20
- end
21
-
22
- def self.to_d(a)
23
-
24
- return case a
25
- when SigningAlgorithms::PDX_HMAC_MD5; OpenSSL::Digest::MD5.new
26
- when SigningAlgorithms::PDX_HMAC_SHA1; OpenSSL::Digest::SHA1.new
27
- when SigningAlgorithms::PDX_HMAC_SHA256; OpenSSL::Digest::SHA256.new
28
- when SigningAlgorithms::PDX_HMAC_SHA384; OpenSSL::Digest::SHA384.new
29
- when SigningAlgorithms::PDX_HMAC_SHA512; OpenSSL::Digest::SHA512.new
30
- else raise 'Invalid signing algorithm'
31
- end
32
-
33
- end
34
-
35
- end
36
-
1
+ module Pandexio
2
+
3
+ class SigningAlgorithms
4
+
5
+ PDX_HMAC_MD5 = "PDX-HMAC-MD5"
6
+ PDX_HMAC_SHA1 = "PDX-HMAC-SHA1"
7
+ PDX_HMAC_SHA256 = "PDX-HMAC-SHA256"
8
+ PDX_HMAC_SHA384 = "PDX-HMAC-SHA384"
9
+ PDX_HMAC_SHA512 = "PDX-HMAC-SHA512"
10
+
11
+ def self.is_v(a)
12
+
13
+ return !a.nil? && a.is_a?(String) &&
14
+ (a == PDX_HMAC_MD5 ||
15
+ a == PDX_HMAC_SHA1 ||
16
+ a == PDX_HMAC_SHA256 ||
17
+ a == PDX_HMAC_SHA384 ||
18
+ a == PDX_HMAC_SHA512)
19
+
20
+ end
21
+
22
+ def self.to_d(a)
23
+
24
+ return case a
25
+ when SigningAlgorithms::PDX_HMAC_MD5; OpenSSL::Digest::MD5.new
26
+ when SigningAlgorithms::PDX_HMAC_SHA1; OpenSSL::Digest::SHA1.new
27
+ when SigningAlgorithms::PDX_HMAC_SHA256; OpenSSL::Digest::SHA256.new
28
+ when SigningAlgorithms::PDX_HMAC_SHA384; OpenSSL::Digest::SHA384.new
29
+ when SigningAlgorithms::PDX_HMAC_SHA512; OpenSSL::Digest::SHA512.new
30
+ else raise 'Invalid signing algorithm'
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
37
  end
@@ -1,22 +1,22 @@
1
- module Pandexio
2
-
3
- class SigningAttributes
4
- # Used by "headers" only
5
- AUTHORIZATION = "Authorization"
6
-
7
- # Used by "query_parameters" only
8
- ALGORITHM = "X-Pdx-Algorithm"
9
- CREDENTIAL = "X-Pdx-Credential"
10
- SIGNED_HEADERS = "X-Pdx-SignedHeaders"
11
- SIGNATURE = "X-Pdx-Signature"
12
-
13
- # Used by "headers" and "query_parameters"
14
- DATE = "X-Pdx-Date"
15
- EXPIRES = "X-Pdx-Expires"
16
- ORIGINATOR = "X-Pdx-Originator"
17
- EMAIL_ADDRESS = "X-Pdx-EmailAddress"
18
- DISPLAY_NAME = "X-Pdx-DisplayName"
19
- PROFILE_IMAGE = "X-Pdx-ProfileImage"
20
- end
21
-
1
+ module Pandexio
2
+
3
+ class SigningAttributes
4
+ # Used by "headers" only
5
+ AUTHORIZATION = "Authorization"
6
+
7
+ # Used by "query_parameters" only
8
+ ALGORITHM = "X-Pdx-Algorithm"
9
+ CREDENTIAL = "X-Pdx-Credential"
10
+ SIGNED_HEADERS = "X-Pdx-SignedHeaders"
11
+ SIGNATURE = "X-Pdx-Signature"
12
+
13
+ # Used by "headers" and "query_parameters"
14
+ DATE = "X-Pdx-Date"
15
+ EXPIRES = "X-Pdx-Expires"
16
+ ORIGINATOR = "X-Pdx-Originator"
17
+ EMAIL_ADDRESS = "X-Pdx-EmailAddress"
18
+ DISPLAY_NAME = "X-Pdx-DisplayName"
19
+ PROFILE_IMAGE = "X-Pdx-ProfileImage"
20
+ end
21
+
22
22
  end
@@ -1,17 +1,17 @@
1
- module Pandexio
2
-
3
- class SigningMechanisms
4
-
5
- QUERY_STRING = "QueryString"
6
- HEADER = "Header"
7
-
8
- def self.is_v(m)
9
-
10
- return !m.nil? && m.is_a?(String) &&
11
- (m == QUERY_STRING || m == HEADER)
12
-
13
- end
14
-
15
- end
16
-
1
+ module Pandexio
2
+
3
+ class SigningMechanisms
4
+
5
+ QUERY_STRING = "QueryString"
6
+ HEADER = "Header"
7
+
8
+ def self.is_v(m)
9
+
10
+ return !m.nil? && m.is_a?(String) &&
11
+ (m == QUERY_STRING || m == HEADER)
12
+
13
+ end
14
+
15
+ end
16
+
17
17
  end
@@ -1,30 +1,30 @@
1
- module Pandexio
2
-
3
- class SigningOptions
4
- def initialize(params = {})
5
- @algorithm = params.fetch(:algorithm, nil)
6
- @mechanism = params.fetch(:mechanism, nil)
7
- @domain_id = params.fetch(:domain_id, nil)
8
- @domain_key = params.fetch(:domain_key, nil)
9
- @date = params.fetch(:date, nil)
10
- @expires = params.fetch(:expires, nil)
11
- @originator = params.fetch(:originator, nil)
12
- @email_address = params.fetch(:email_address, nil)
13
- @display_name = params.fetch(:display_name, nil)
14
- @profile_image = params.fetch(:profile_image, nil)
15
- end
16
-
17
- attr_accessor :algorithm
18
- attr_accessor :mechanism
19
- attr_accessor :domain_id
20
- attr_accessor :domain_key
21
- attr_accessor :date
22
- attr_accessor :expires
23
- attr_accessor :originator
24
- attr_accessor :email_address
25
- attr_accessor :display_name
26
- attr_accessor :profile_image
27
-
28
- end
29
-
1
+ module Pandexio
2
+
3
+ class SigningOptions
4
+ def initialize(params = {})
5
+ @algorithm = params.fetch(:algorithm, nil)
6
+ @mechanism = params.fetch(:mechanism, nil)
7
+ @domain_id = params.fetch(:domain_id, nil)
8
+ @domain_key = params.fetch(:domain_key, nil)
9
+ @date = params.fetch(:date, nil)
10
+ @expires = params.fetch(:expires, nil)
11
+ @originator = params.fetch(:originator, nil)
12
+ @email_address = params.fetch(:email_address, nil)
13
+ @display_name = params.fetch(:display_name, nil)
14
+ @profile_image = params.fetch(:profile_image, nil)
15
+ end
16
+
17
+ attr_accessor :algorithm
18
+ attr_accessor :mechanism
19
+ attr_accessor :domain_id
20
+ attr_accessor :domain_key
21
+ attr_accessor :date
22
+ attr_accessor :expires
23
+ attr_accessor :originator
24
+ attr_accessor :email_address
25
+ attr_accessor :display_name
26
+ attr_accessor :profile_image
27
+
28
+ end
29
+
30
30
  end
@@ -1,297 +1,328 @@
1
- # encoding: utf-8
2
-
3
- require 'minitest/autorun'
4
- require_relative '../lib/pandexio.rb'
5
-
6
- describe Pandexio do
7
- describe "#to_authorized_request" do
8
-
9
- describe "when using header signing mechanism to generate a new authorized_request from a given normalized_request" do
10
-
11
- before do
12
- @normalized_request = Pandexio::Request.new(
13
- :method => "PUT",
14
- :path => "/asdf/qwer/1234/title",
15
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
16
- :headers => { "sample" => "example", "Host" => "localhost" },
17
- :payload => "testing")
18
-
19
- signing_options = Pandexio::SigningOptions.new(
20
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
21
- :mechanism => Pandexio::SigningMechanisms::HEADER,
22
- :domain_id => "1234567890",
23
- :domain_key => "asdfjklqwerzxcv",
24
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
25
- :expires => 90,
26
- :originator => "HeaderSigningTest",
27
- :email_address => "Anonymous",
28
- :display_name => "Anonymous")
29
-
30
- @authorized_request = Pandexio::to_authorized_request(@normalized_request, signing_options)
31
- end
32
-
33
- it "does not modify the normalized_request method" do
34
- @normalized_request.method.must_equal "PUT"
35
- end
36
- it "does not modify the normalized_request path" do
37
- @normalized_request.path.must_equal "/asdf/qwer/1234/title"
38
- end
39
- it "does not modify the normalized_request query_parameters" do
40
- @normalized_request.query_parameters.count.must_equal 2
41
- @normalized_request.query_parameters["nonce"].must_equal "987654321"
42
- @normalized_request.query_parameters["Baseline"].must_equal "5"
43
- end
44
- it "does not modify the normalized_request headers" do
45
- @normalized_request.headers.count.must_equal 2
46
- @normalized_request.headers["sample"].must_equal "example"
47
- @normalized_request.headers["Host"].must_equal "localhost"
48
- end
49
- it "does not modify the normalized_request payload" do
50
- @normalized_request.payload.must_equal "testing"
51
- end
52
-
53
- end
54
-
55
- describe "when using header signing mechanism and email_address contains uppercase and lowercase characters" do
56
-
57
- before do
58
- normalized_request = Pandexio::Request.new(
59
- :method => "PUT",
60
- :path => "/asdf/qwer/1234/title",
61
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
62
- :headers => { "sample" => "example", "Host" => "localhost" },
63
- :payload => "testing")
64
-
65
- signing_options = Pandexio::SigningOptions.new(
66
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
67
- :mechanism => Pandexio::SigningMechanisms::HEADER,
68
- :domain_id => "1234567890",
69
- :domain_key => "asdfjklqwerzxcv",
70
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
71
- :expires => 90,
72
- :originator => "HeaderSigningTest",
73
- :email_address => "Anonymous",
74
- :display_name => "Anonymous")
75
-
76
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
77
- end
78
-
79
- it "returns the correct authorization header" do
80
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=a2e3dbc31b712bec6071dc7c5770bc60d4b03afa20e8329e6f4f6a2d74d32709"
81
- end
82
-
83
- end
84
-
85
- describe "when using header signing mechanism and email_address contains all lowercase characters" do
86
-
87
- before do
88
- normalized_request = Pandexio::Request.new(
89
- :method => "PUT",
90
- :path => "/asdf/qwer/1234/title",
91
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
92
- :headers => { "sample" => "example", "Host" => "localhost" },
93
- :payload => "testing")
94
-
95
- signing_options = Pandexio::SigningOptions.new(
96
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
97
- :mechanism => Pandexio::SigningMechanisms::HEADER,
98
- :domain_id => "1234567890",
99
- :domain_key => "asdfjklqwerzxcv",
100
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
101
- :expires => 90,
102
- :originator => "HeaderSigningTest",
103
- :email_address => "anonymous",
104
- :display_name => "Anonymous")
105
-
106
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
107
- end
108
-
109
- it "returns the correct authorization header" do
110
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=d2c3ba8ed5c10371a4a370a7e7ee5f483d4eaac4545a97d6aaced30d8e62d2a0"
111
- end
112
-
113
- end
114
-
115
- describe "when using header signing mechanism and email_address contains all uppercase characters" do
116
-
117
- before do
118
- normalized_request = Pandexio::Request.new(
119
- :method => "PUT",
120
- :path => "/asdf/qwer/1234/title",
121
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
122
- :headers => { "sample" => "example", "Host" => "localhost" },
123
- :payload => "testing")
124
-
125
- signing_options = Pandexio::SigningOptions.new(
126
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
127
- :mechanism => Pandexio::SigningMechanisms::HEADER,
128
- :domain_id => "1234567890",
129
- :domain_key => "asdfjklqwerzxcv",
130
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
131
- :expires => 90,
132
- :originator => "HeaderSigningTest",
133
- :email_address => "ANONYMOUS",
134
- :display_name => "Anonymous")
135
-
136
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
137
- end
138
-
139
- it "returns the correct authorization header" do
140
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=865f3555991dc8f73760058b643a6a169c07c3a32ab3d247aa0eebdc24e9d6e9"
141
- end
142
-
143
- end
144
-
145
- describe "when using header signing mechanism and display_name contains spaces" do
146
-
147
- before do
148
- normalized_request = Pandexio::Request.new(
149
- :method => "PUT",
150
- :path => "/asdf/qwer/1234/title",
151
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
152
- :headers => { "sample" => "example", "Host" => "localhost" },
153
- :payload => "testing")
154
-
155
- signing_options = Pandexio::SigningOptions.new(
156
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
157
- :mechanism => Pandexio::SigningMechanisms::HEADER,
158
- :domain_id => "1234567890",
159
- :domain_key => "asdfjklqwerzxcv",
160
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
161
- :expires => 90,
162
- :originator => "HeaderSigningTest",
163
- :email_address => "Anonymous",
164
- :display_name => "A. Anonymous")
165
-
166
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
167
- end
168
-
169
- it "returns the correct authorization header" do
170
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=e1fc00541454d11c58bae1273af56b528def5e60575feedbe0a9019b88fe1b79"
171
- end
172
-
173
- end
174
-
175
- describe "when using header signing mechanism and display_name contains non-ASCII characters" do
176
-
177
- before do
178
- normalized_request = Pandexio::Request.new(
179
- :method => "PUT",
180
- :path => "/asdf/qwer/1234/title",
181
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
182
- :headers => { "sample" => "example", "Host" => "localhost" },
183
- :payload => "testing")
184
-
185
- signing_options = Pandexio::SigningOptions.new(
186
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
187
- :mechanism => Pandexio::SigningMechanisms::HEADER,
188
- :domain_id => "1234567890",
189
- :domain_key => "asdfjklqwerzxcv",
190
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
191
- :expires => 90,
192
- :originator => "HeaderSigningTest",
193
- :email_address => "Anonymous",
194
- :display_name => "á Anonymous")
195
-
196
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
197
- end
198
-
199
- it "returns the correct authorization header" do
200
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=347ac3df3930eaf2ba107c932e740dae5430a99f4fef76b18a4452d07125c209"
201
- end
202
-
203
- end
204
-
205
- describe "when using header signing mechanism and path contains spaces" do
206
-
207
- before do
208
- normalized_request = Pandexio::Request.new(
209
- :method => "PUT",
210
- :path => "/asdf/qwer/1234/title and description",
211
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
212
- :headers => { "sample" => "example", "Host" => "localhost" },
213
- :payload => "testing")
214
-
215
- signing_options = Pandexio::SigningOptions.new(
216
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
217
- :mechanism => Pandexio::SigningMechanisms::HEADER,
218
- :domain_id => "1234567890",
219
- :domain_key => "asdfjklqwerzxcv",
220
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
221
- :expires => 90,
222
- :originator => "HeaderSigningTest",
223
- :email_address => "Anonymous",
224
- :display_name => "Anonymous")
225
-
226
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
227
- end
228
-
229
- it "returns the correct authorization header" do
230
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=e8946dbd83307f5bf86f7f152d6cee95426834dd5901588da84df1b8207e2bca"
231
- end
232
-
233
- end
234
-
235
- describe "when using header signing mechanism and payload contains non-ASCII characters" do
236
-
237
- before do
238
- normalized_request = Pandexio::Request.new(
239
- :method => "PUT",
240
- :path => "/asdf/qwer/1234/title",
241
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
242
- :headers => { "sample" => "example", "Host" => "localhost" },
243
- :payload => "testing á")
244
-
245
- signing_options = Pandexio::SigningOptions.new(
246
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
247
- :mechanism => Pandexio::SigningMechanisms::HEADER,
248
- :domain_id => "1234567890",
249
- :domain_key => "asdfjklqwerzxcv",
250
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
251
- :expires => 90,
252
- :originator => "HeaderSigningTest",
253
- :email_address => "Anonymous",
254
- :display_name => "Anonymous")
255
-
256
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
257
- end
258
-
259
- it "returns the correct authorization header" do
260
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=fec62f69abbb53261dceaf1a52dab932e24e5f6e97f189da559562e14c13a9f7"
261
- end
262
-
263
- end
264
-
265
- describe "when using header signing mechanism and attributes include profile_image" do
266
-
267
- before do
268
- normalized_request = Pandexio::Request.new(
269
- :method => "PUT",
270
- :path => "/asdf/qwer/1234/title",
271
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
272
- :headers => { "sample" => "example", "Host" => "localhost" },
273
- :payload => "testing")
274
-
275
- signing_options = Pandexio::SigningOptions.new(
276
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
277
- :mechanism => Pandexio::SigningMechanisms::HEADER,
278
- :domain_id => "1234567890",
279
- :domain_key => "asdfjklqwerzxcv",
280
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
281
- :expires => 90,
282
- :originator => "HeaderSigningTest",
283
- :email_address => "Anonymous",
284
- :display_name => "Anonymous",
285
- :profile_image => "abcdefg")
286
-
287
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
288
- end
289
-
290
- it "returns the correct authorization header" do
291
- @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator;x-pdx-profileimage, Signature=e7fb1de006519be4a1c778c3055f05dfa2fafb96fb1bc033a77ba4df4da8829d"
292
- end
293
-
294
- end
295
-
296
- end
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require_relative '../lib/pandexio.rb'
5
+
6
+ describe Pandexio do
7
+ describe "#to_authorized_request" do
8
+
9
+ describe "when using header signing mechanism to generate a new authorized_request from a given normalized_request" do
10
+
11
+ before do
12
+ @normalized_request = Pandexio::Request.new(
13
+ :method => "PUT",
14
+ :path => "/asdf/qwer/1234/title",
15
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
16
+ :headers => { "sample" => "example", "Host" => "localhost" },
17
+ :payload => "testing")
18
+
19
+ signing_options = Pandexio::SigningOptions.new(
20
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
21
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
22
+ :domain_id => "1234567890",
23
+ :domain_key => "asdfjklqwerzxcv",
24
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
25
+ :expires => 90,
26
+ :originator => "HeaderSigningTest",
27
+ :email_address => "Anonymous",
28
+ :display_name => "Anonymous")
29
+
30
+ @authorized_request = Pandexio::to_authorized_request(@normalized_request, signing_options)
31
+ end
32
+
33
+ it "does not modify the normalized_request method" do
34
+ @normalized_request.method.must_equal "PUT"
35
+ end
36
+ it "does not modify the normalized_request path" do
37
+ @normalized_request.path.must_equal "/asdf/qwer/1234/title"
38
+ end
39
+ it "does not modify the normalized_request query_parameters" do
40
+ @normalized_request.query_parameters.count.must_equal 2
41
+ @normalized_request.query_parameters["nonce"].must_equal "987654321"
42
+ @normalized_request.query_parameters["Baseline"].must_equal "5"
43
+ end
44
+ it "does not modify the normalized_request headers" do
45
+ @normalized_request.headers.count.must_equal 2
46
+ @normalized_request.headers["sample"].must_equal "example"
47
+ @normalized_request.headers["Host"].must_equal "localhost"
48
+ end
49
+ it "does not modify the normalized_request payload" do
50
+ @normalized_request.payload.must_equal "testing"
51
+ end
52
+
53
+ end
54
+
55
+ describe "when using header signing mechanism to sign and authorized_request" do
56
+
57
+ before do
58
+ normalized_request = Pandexio::Request.new(
59
+ :method => "PUT",
60
+ :path => "/asdf/qwer/1234/title",
61
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
62
+ :headers => { "sample" => "example", "Host" => "localhost" },
63
+ :payload => "testing")
64
+
65
+ signing_options = Pandexio::SigningOptions.new(
66
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
67
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
68
+ :domain_id => "1234567890",
69
+ :domain_key => "asdfjklqwerzxcv",
70
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
71
+ :expires => 90,
72
+ :originator => "HeaderSigningTest",
73
+ :email_address => "Anonymous",
74
+ :display_name => "Anonymous")
75
+
76
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
77
+ @authorized_request = Pandexio::to_authorized_request(@authorized_request, signing_options)
78
+ end
79
+
80
+ it "returns the correct authorization header" do
81
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=a2e3dbc31b712bec6071dc7c5770bc60d4b03afa20e8329e6f4f6a2d74d32709"
82
+ end
83
+
84
+ end
85
+
86
+ describe "when using header signing mechanism and email_address contains uppercase and lowercase characters" do
87
+
88
+ before do
89
+ normalized_request = Pandexio::Request.new(
90
+ :method => "PUT",
91
+ :path => "/asdf/qwer/1234/title",
92
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
93
+ :headers => { "sample" => "example", "Host" => "localhost" },
94
+ :payload => "testing")
95
+
96
+ signing_options = Pandexio::SigningOptions.new(
97
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
98
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
99
+ :domain_id => "1234567890",
100
+ :domain_key => "asdfjklqwerzxcv",
101
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
102
+ :expires => 90,
103
+ :originator => "HeaderSigningTest",
104
+ :email_address => "Anonymous",
105
+ :display_name => "Anonymous")
106
+
107
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
108
+ end
109
+
110
+ it "returns the correct authorization header" do
111
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=a2e3dbc31b712bec6071dc7c5770bc60d4b03afa20e8329e6f4f6a2d74d32709"
112
+ end
113
+
114
+ end
115
+
116
+ describe "when using header signing mechanism and email_address contains all lowercase characters" do
117
+
118
+ before do
119
+ normalized_request = Pandexio::Request.new(
120
+ :method => "PUT",
121
+ :path => "/asdf/qwer/1234/title",
122
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
123
+ :headers => { "sample" => "example", "Host" => "localhost" },
124
+ :payload => "testing")
125
+
126
+ signing_options = Pandexio::SigningOptions.new(
127
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
128
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
129
+ :domain_id => "1234567890",
130
+ :domain_key => "asdfjklqwerzxcv",
131
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
132
+ :expires => 90,
133
+ :originator => "HeaderSigningTest",
134
+ :email_address => "anonymous",
135
+ :display_name => "Anonymous")
136
+
137
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
138
+ end
139
+
140
+ it "returns the correct authorization header" do
141
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=d2c3ba8ed5c10371a4a370a7e7ee5f483d4eaac4545a97d6aaced30d8e62d2a0"
142
+ end
143
+
144
+ end
145
+
146
+ describe "when using header signing mechanism and email_address contains all uppercase characters" do
147
+
148
+ before do
149
+ normalized_request = Pandexio::Request.new(
150
+ :method => "PUT",
151
+ :path => "/asdf/qwer/1234/title",
152
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
153
+ :headers => { "sample" => "example", "Host" => "localhost" },
154
+ :payload => "testing")
155
+
156
+ signing_options = Pandexio::SigningOptions.new(
157
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
158
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
159
+ :domain_id => "1234567890",
160
+ :domain_key => "asdfjklqwerzxcv",
161
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
162
+ :expires => 90,
163
+ :originator => "HeaderSigningTest",
164
+ :email_address => "ANONYMOUS",
165
+ :display_name => "Anonymous")
166
+
167
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
168
+ end
169
+
170
+ it "returns the correct authorization header" do
171
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=865f3555991dc8f73760058b643a6a169c07c3a32ab3d247aa0eebdc24e9d6e9"
172
+ end
173
+
174
+ end
175
+
176
+ describe "when using header signing mechanism and display_name contains spaces" do
177
+
178
+ before do
179
+ normalized_request = Pandexio::Request.new(
180
+ :method => "PUT",
181
+ :path => "/asdf/qwer/1234/title",
182
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
183
+ :headers => { "sample" => "example", "Host" => "localhost" },
184
+ :payload => "testing")
185
+
186
+ signing_options = Pandexio::SigningOptions.new(
187
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
188
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
189
+ :domain_id => "1234567890",
190
+ :domain_key => "asdfjklqwerzxcv",
191
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
192
+ :expires => 90,
193
+ :originator => "HeaderSigningTest",
194
+ :email_address => "Anonymous",
195
+ :display_name => "A. Anonymous")
196
+
197
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
198
+ end
199
+
200
+ it "returns the correct authorization header" do
201
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=e1fc00541454d11c58bae1273af56b528def5e60575feedbe0a9019b88fe1b79"
202
+ end
203
+
204
+ end
205
+
206
+ describe "when using header signing mechanism and display_name contains non-ASCII characters" do
207
+
208
+ before do
209
+ normalized_request = Pandexio::Request.new(
210
+ :method => "PUT",
211
+ :path => "/asdf/qwer/1234/title",
212
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
213
+ :headers => { "sample" => "example", "Host" => "localhost" },
214
+ :payload => "testing")
215
+
216
+ signing_options = Pandexio::SigningOptions.new(
217
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
218
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
219
+ :domain_id => "1234567890",
220
+ :domain_key => "asdfjklqwerzxcv",
221
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
222
+ :expires => 90,
223
+ :originator => "HeaderSigningTest",
224
+ :email_address => "Anonymous",
225
+ :display_name => "á Anonymous")
226
+
227
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
228
+ end
229
+
230
+ it "returns the correct authorization header" do
231
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=347ac3df3930eaf2ba107c932e740dae5430a99f4fef76b18a4452d07125c209"
232
+ end
233
+
234
+ end
235
+
236
+ describe "when using header signing mechanism and path contains spaces" do
237
+
238
+ before do
239
+ normalized_request = Pandexio::Request.new(
240
+ :method => "PUT",
241
+ :path => "/asdf/qwer/1234/title and description",
242
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
243
+ :headers => { "sample" => "example", "Host" => "localhost" },
244
+ :payload => "testing")
245
+
246
+ signing_options = Pandexio::SigningOptions.new(
247
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
248
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
249
+ :domain_id => "1234567890",
250
+ :domain_key => "asdfjklqwerzxcv",
251
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
252
+ :expires => 90,
253
+ :originator => "HeaderSigningTest",
254
+ :email_address => "Anonymous",
255
+ :display_name => "Anonymous")
256
+
257
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
258
+ end
259
+
260
+ it "returns the correct authorization header" do
261
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=e8946dbd83307f5bf86f7f152d6cee95426834dd5901588da84df1b8207e2bca"
262
+ end
263
+
264
+ end
265
+
266
+ describe "when using header signing mechanism and payload contains non-ASCII characters" do
267
+
268
+ before do
269
+ normalized_request = Pandexio::Request.new(
270
+ :method => "PUT",
271
+ :path => "/asdf/qwer/1234/title",
272
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
273
+ :headers => { "sample" => "example", "Host" => "localhost" },
274
+ :payload => "testing á")
275
+
276
+ signing_options = Pandexio::SigningOptions.new(
277
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
278
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
279
+ :domain_id => "1234567890",
280
+ :domain_key => "asdfjklqwerzxcv",
281
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
282
+ :expires => 90,
283
+ :originator => "HeaderSigningTest",
284
+ :email_address => "Anonymous",
285
+ :display_name => "Anonymous")
286
+
287
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
288
+ end
289
+
290
+ it "returns the correct authorization header" do
291
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator, Signature=fec62f69abbb53261dceaf1a52dab932e24e5f6e97f189da559562e14c13a9f7"
292
+ end
293
+
294
+ end
295
+
296
+ describe "when using header signing mechanism and attributes include profile_image" do
297
+
298
+ before do
299
+ normalized_request = Pandexio::Request.new(
300
+ :method => "PUT",
301
+ :path => "/asdf/qwer/1234/title",
302
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
303
+ :headers => { "sample" => "example", "Host" => "localhost" },
304
+ :payload => "testing")
305
+
306
+ signing_options = Pandexio::SigningOptions.new(
307
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
308
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
309
+ :domain_id => "1234567890",
310
+ :domain_key => "asdfjklqwerzxcv",
311
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
312
+ :expires => 90,
313
+ :originator => "HeaderSigningTest",
314
+ :email_address => "Anonymous",
315
+ :display_name => "Anonymous",
316
+ :profile_image => "abcdefg")
317
+
318
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
319
+ end
320
+
321
+ it "returns the correct authorization header" do
322
+ @authorized_request.headers["Authorization"].must_equal "PDX-HMAC-SHA256 Credential=1234567890, SignedHeaders=host;sample;x-pdx-date;x-pdx-displayname;x-pdx-emailaddress;x-pdx-expires;x-pdx-originator;x-pdx-profileimage, Signature=e7fb1de006519be4a1c778c3055f05dfa2fafb96fb1bc033a77ba4df4da8829d"
323
+ end
324
+
325
+ end
326
+
327
+ end
297
328
  end