pandexio 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/request.rb CHANGED
@@ -1,25 +1,25 @@
1
- module Pandexio
2
-
3
- class Request
4
-
5
- def initialize(params = {})
6
- @method = params.fetch(:method, nil)
7
- @path = params.fetch(:path, nil)
8
- @query_parameters = params.fetch(:query_parameters, {})
9
- @headers = params.fetch(:headers, {})
10
- @payload = params.fetch(:payload, nil)
11
- end
12
-
13
- attr_accessor :method
14
- attr_accessor :path
15
- attr_accessor :query_parameters
16
- attr_accessor :headers
17
- attr_accessor :payload
18
-
19
- def to_s
20
- "#{@method} #{@path}#{LINE_BREAK}query_parameters: #{query_parameters}#{LINE_BREAK}headers: #{headers}#{LINE_BREAK}payload: #{payload}"
21
- end
22
-
23
- end
24
-
1
+ module Pandexio
2
+
3
+ class Request
4
+
5
+ def initialize(params = {})
6
+ @method = params.fetch(:method, nil)
7
+ @path = params.fetch(:path, nil)
8
+ @query_parameters = params.fetch(:query_parameters, {})
9
+ @headers = params.fetch(:headers, {})
10
+ @payload = params.fetch(:payload, nil)
11
+ end
12
+
13
+ attr_accessor :method
14
+ attr_accessor :path
15
+ attr_accessor :query_parameters
16
+ attr_accessor :headers
17
+ attr_accessor :payload
18
+
19
+ def to_s
20
+ "#{@method} #{@path}#{LINE_BREAK}query_parameters: #{query_parameters}#{LINE_BREAK}headers: #{headers}#{LINE_BREAK}payload: #{payload}"
21
+ end
22
+
23
+ end
24
+
25
25
  end
@@ -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,297 @@
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 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
297
297
  end