pandexio 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +78 -78
- data/Rakefile +8 -8
- data/lib/pandexio.rb +14 -155
- data/lib/request.rb +24 -24
- data/lib/scope.rb +13 -0
- data/lib/scope_patterns.rb +7 -0
- data/lib/signer.rb +192 -0
- data/lib/signing_algorithms.rb +36 -36
- data/lib/signing_attributes.rb +21 -21
- data/lib/signing_mechanisms.rb +16 -16
- data/lib/signing_options.rb +29 -29
- data/test/test_header_signing.rb +327 -296
- data/test/test_query_string_signing.rb +408 -368
- data/test/test_scope.rb +37 -0
- data/test/test_scope_patterns.rb +56 -0
- data/test/test_signer.rb +112 -0
- metadata +15 -7
- checksums.yaml +0 -7
data/lib/signing_algorithms.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
module Pandexio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
data/lib/signing_attributes.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
module Pandexio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
data/lib/signing_mechanisms.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
module Pandexio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
data/lib/signing_options.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
module Pandexio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
data/test/test_header_signing.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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
|