pandexio 0.0.3 → 0.0.4

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,249 +1,251 @@
1
- require 'minitest/autorun'
2
- require_relative '../lib/pandexio.rb'
3
-
4
- describe Pandexio do
5
- describe "#to_authorized_request" do
6
-
7
- describe "when using header signing mechanism and email_address contains uppercase and lowercase characters" do
8
-
9
- before do
10
- normalized_request = Pandexio::Request.new(
11
- :method => "PUT",
12
- :path => "/asdf/qwer/1234/title",
13
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
14
- :headers => { "sample" => "example", "Host" => "localhost" },
15
- :payload => "testing")
16
-
17
- signing_options = Pandexio::SigningOptions.new(
18
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
19
- :mechanism => Pandexio::SigningMechanisms::HEADER,
20
- :domain_id => "1234567890",
21
- :domain_key => "asdfjklqwerzxcv",
22
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
23
- :expires => 90,
24
- :originator => "HeaderSigningTest",
25
- :email_address => "Anonymous",
26
- :display_name => "Anonymous")
27
-
28
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
29
- end
30
-
31
- it "returns the correct authorization header" do
32
- @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"
33
- end
34
-
35
- end
36
-
37
- describe "when using header signing mechanism and email_address contains all lowercase characters" do
38
-
39
- before do
40
- normalized_request = Pandexio::Request.new(
41
- :method => "PUT",
42
- :path => "/asdf/qwer/1234/title",
43
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
44
- :headers => { "sample" => "example", "Host" => "localhost" },
45
- :payload => "testing")
46
-
47
- signing_options = Pandexio::SigningOptions.new(
48
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
49
- :mechanism => Pandexio::SigningMechanisms::HEADER,
50
- :domain_id => "1234567890",
51
- :domain_key => "asdfjklqwerzxcv",
52
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
53
- :expires => 90,
54
- :originator => "HeaderSigningTest",
55
- :email_address => "anonymous",
56
- :display_name => "Anonymous")
57
-
58
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
59
- end
60
-
61
- it "returns the correct authorization header" do
62
- @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"
63
- end
64
-
65
- end
66
-
67
- describe "when using header signing mechanism and email_address contains all uppercase characters" do
68
-
69
- before do
70
- normalized_request = Pandexio::Request.new(
71
- :method => "PUT",
72
- :path => "/asdf/qwer/1234/title",
73
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
74
- :headers => { "sample" => "example", "Host" => "localhost" },
75
- :payload => "testing")
76
-
77
- signing_options = Pandexio::SigningOptions.new(
78
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
79
- :mechanism => Pandexio::SigningMechanisms::HEADER,
80
- :domain_id => "1234567890",
81
- :domain_key => "asdfjklqwerzxcv",
82
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
83
- :expires => 90,
84
- :originator => "HeaderSigningTest",
85
- :email_address => "ANONYMOUS",
86
- :display_name => "Anonymous")
87
-
88
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
89
- end
90
-
91
- it "returns the correct authorization header" do
92
- @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"
93
- end
94
-
95
- end
96
-
97
- describe "when using header signing mechanism and display_name contains spaces" do
98
-
99
- before do
100
- normalized_request = Pandexio::Request.new(
101
- :method => "PUT",
102
- :path => "/asdf/qwer/1234/title",
103
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
104
- :headers => { "sample" => "example", "Host" => "localhost" },
105
- :payload => "testing")
106
-
107
- signing_options = Pandexio::SigningOptions.new(
108
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
109
- :mechanism => Pandexio::SigningMechanisms::HEADER,
110
- :domain_id => "1234567890",
111
- :domain_key => "asdfjklqwerzxcv",
112
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
113
- :expires => 90,
114
- :originator => "HeaderSigningTest",
115
- :email_address => "Anonymous",
116
- :display_name => "A. Anonymous")
117
-
118
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
119
- end
120
-
121
- it "returns the correct authorization header" do
122
- @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"
123
- end
124
-
125
- end
126
-
127
- describe "when using header signing mechanism and display_name contains non-ASCII characters" do
128
-
129
- before do
130
- normalized_request = Pandexio::Request.new(
131
- :method => "PUT",
132
- :path => "/asdf/qwer/1234/title",
133
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
134
- :headers => { "sample" => "example", "Host" => "localhost" },
135
- :payload => "testing")
136
-
137
- signing_options = Pandexio::SigningOptions.new(
138
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
139
- :mechanism => Pandexio::SigningMechanisms::HEADER,
140
- :domain_id => "1234567890",
141
- :domain_key => "asdfjklqwerzxcv",
142
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
143
- :expires => 90,
144
- :originator => "HeaderSigningTest",
145
- :email_address => "Anonymous",
146
- :display_name => "á Anonymous")
147
-
148
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
149
- end
150
-
151
- it "returns the correct authorization header" do
152
- @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"
153
- end
154
-
155
- end
156
-
157
- describe "when using header signing mechanism and path contains spaces" do
158
-
159
- before do
160
- normalized_request = Pandexio::Request.new(
161
- :method => "PUT",
162
- :path => "/asdf/qwer/1234/title and description",
163
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
164
- :headers => { "sample" => "example", "Host" => "localhost" },
165
- :payload => "testing")
166
-
167
- signing_options = Pandexio::SigningOptions.new(
168
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
169
- :mechanism => Pandexio::SigningMechanisms::HEADER,
170
- :domain_id => "1234567890",
171
- :domain_key => "asdfjklqwerzxcv",
172
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
173
- :expires => 90,
174
- :originator => "HeaderSigningTest",
175
- :email_address => "Anonymous",
176
- :display_name => "Anonymous")
177
-
178
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
179
- end
180
-
181
- it "returns the correct authorization header" do
182
- @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"
183
- end
184
-
185
- end
186
-
187
- describe "when using header signing mechanism and payload contains non-ASCII characters" do
188
-
189
- before do
190
- normalized_request = Pandexio::Request.new(
191
- :method => "PUT",
192
- :path => "/asdf/qwer/1234/title",
193
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
194
- :headers => { "sample" => "example", "Host" => "localhost" },
195
- :payload => "testing á")
196
-
197
- signing_options = Pandexio::SigningOptions.new(
198
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
199
- :mechanism => Pandexio::SigningMechanisms::HEADER,
200
- :domain_id => "1234567890",
201
- :domain_key => "asdfjklqwerzxcv",
202
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
203
- :expires => 90,
204
- :originator => "HeaderSigningTest",
205
- :email_address => "Anonymous",
206
- :display_name => "Anonymous")
207
-
208
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
209
- end
210
-
211
- it "returns the correct authorization header" do
212
- @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"
213
- end
214
-
215
- end
216
-
217
- describe "when using header signing mechanism and attributes include profile_image" do
218
-
219
- before do
220
- normalized_request = Pandexio::Request.new(
221
- :method => "PUT",
222
- :path => "/asdf/qwer/1234/title",
223
- :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
224
- :headers => { "sample" => "example", "Host" => "localhost" },
225
- :payload => "testing")
226
-
227
- signing_options = Pandexio::SigningOptions.new(
228
- :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
229
- :mechanism => Pandexio::SigningMechanisms::HEADER,
230
- :domain_id => "1234567890",
231
- :domain_key => "asdfjklqwerzxcv",
232
- :date => Time.utc(2014, 11, 21, 13, 43, 15),
233
- :expires => 90,
234
- :originator => "HeaderSigningTest",
235
- :email_address => "Anonymous",
236
- :display_name => "Anonymous",
237
- :profile_image => "abcdefg")
238
-
239
- @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
240
- end
241
-
242
- it "returns the correct authorization header" do
243
- @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"
244
- end
245
-
246
- end
247
-
248
- 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 and email_address contains uppercase and lowercase characters" 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 "returns the correct authorization header" do
34
+ @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"
35
+ end
36
+
37
+ end
38
+
39
+ describe "when using header signing mechanism and email_address contains all lowercase characters" do
40
+
41
+ before do
42
+ normalized_request = Pandexio::Request.new(
43
+ :method => "PUT",
44
+ :path => "/asdf/qwer/1234/title",
45
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
46
+ :headers => { "sample" => "example", "Host" => "localhost" },
47
+ :payload => "testing")
48
+
49
+ signing_options = Pandexio::SigningOptions.new(
50
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
51
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
52
+ :domain_id => "1234567890",
53
+ :domain_key => "asdfjklqwerzxcv",
54
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
55
+ :expires => 90,
56
+ :originator => "HeaderSigningTest",
57
+ :email_address => "anonymous",
58
+ :display_name => "Anonymous")
59
+
60
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
61
+ end
62
+
63
+ it "returns the correct authorization header" do
64
+ @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"
65
+ end
66
+
67
+ end
68
+
69
+ describe "when using header signing mechanism and email_address contains all uppercase characters" do
70
+
71
+ before do
72
+ normalized_request = Pandexio::Request.new(
73
+ :method => "PUT",
74
+ :path => "/asdf/qwer/1234/title",
75
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
76
+ :headers => { "sample" => "example", "Host" => "localhost" },
77
+ :payload => "testing")
78
+
79
+ signing_options = Pandexio::SigningOptions.new(
80
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
81
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
82
+ :domain_id => "1234567890",
83
+ :domain_key => "asdfjklqwerzxcv",
84
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
85
+ :expires => 90,
86
+ :originator => "HeaderSigningTest",
87
+ :email_address => "ANONYMOUS",
88
+ :display_name => "Anonymous")
89
+
90
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
91
+ end
92
+
93
+ it "returns the correct authorization header" do
94
+ @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"
95
+ end
96
+
97
+ end
98
+
99
+ describe "when using header signing mechanism and display_name contains spaces" do
100
+
101
+ before do
102
+ normalized_request = Pandexio::Request.new(
103
+ :method => "PUT",
104
+ :path => "/asdf/qwer/1234/title",
105
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
106
+ :headers => { "sample" => "example", "Host" => "localhost" },
107
+ :payload => "testing")
108
+
109
+ signing_options = Pandexio::SigningOptions.new(
110
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
111
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
112
+ :domain_id => "1234567890",
113
+ :domain_key => "asdfjklqwerzxcv",
114
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
115
+ :expires => 90,
116
+ :originator => "HeaderSigningTest",
117
+ :email_address => "Anonymous",
118
+ :display_name => "A. Anonymous")
119
+
120
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
121
+ end
122
+
123
+ it "returns the correct authorization header" do
124
+ @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"
125
+ end
126
+
127
+ end
128
+
129
+ describe "when using header signing mechanism and display_name contains non-ASCII characters" do
130
+
131
+ before do
132
+ normalized_request = Pandexio::Request.new(
133
+ :method => "PUT",
134
+ :path => "/asdf/qwer/1234/title",
135
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
136
+ :headers => { "sample" => "example", "Host" => "localhost" },
137
+ :payload => "testing")
138
+
139
+ signing_options = Pandexio::SigningOptions.new(
140
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
141
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
142
+ :domain_id => "1234567890",
143
+ :domain_key => "asdfjklqwerzxcv",
144
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
145
+ :expires => 90,
146
+ :originator => "HeaderSigningTest",
147
+ :email_address => "Anonymous",
148
+ :display_name => Anonymous")
149
+
150
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
151
+ end
152
+
153
+ it "returns the correct authorization header" do
154
+ @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"
155
+ end
156
+
157
+ end
158
+
159
+ describe "when using header signing mechanism and path contains spaces" do
160
+
161
+ before do
162
+ normalized_request = Pandexio::Request.new(
163
+ :method => "PUT",
164
+ :path => "/asdf/qwer/1234/title and description",
165
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
166
+ :headers => { "sample" => "example", "Host" => "localhost" },
167
+ :payload => "testing")
168
+
169
+ signing_options = Pandexio::SigningOptions.new(
170
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
171
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
172
+ :domain_id => "1234567890",
173
+ :domain_key => "asdfjklqwerzxcv",
174
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
175
+ :expires => 90,
176
+ :originator => "HeaderSigningTest",
177
+ :email_address => "Anonymous",
178
+ :display_name => "Anonymous")
179
+
180
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
181
+ end
182
+
183
+ it "returns the correct authorization header" do
184
+ @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"
185
+ end
186
+
187
+ end
188
+
189
+ describe "when using header signing mechanism and payload contains non-ASCII characters" do
190
+
191
+ before do
192
+ normalized_request = Pandexio::Request.new(
193
+ :method => "PUT",
194
+ :path => "/asdf/qwer/1234/title",
195
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
196
+ :headers => { "sample" => "example", "Host" => "localhost" },
197
+ :payload => "testing á")
198
+
199
+ signing_options = Pandexio::SigningOptions.new(
200
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
201
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
202
+ :domain_id => "1234567890",
203
+ :domain_key => "asdfjklqwerzxcv",
204
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
205
+ :expires => 90,
206
+ :originator => "HeaderSigningTest",
207
+ :email_address => "Anonymous",
208
+ :display_name => "Anonymous")
209
+
210
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
211
+ end
212
+
213
+ it "returns the correct authorization header" do
214
+ @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"
215
+ end
216
+
217
+ end
218
+
219
+ describe "when using header signing mechanism and attributes include profile_image" do
220
+
221
+ before do
222
+ normalized_request = Pandexio::Request.new(
223
+ :method => "PUT",
224
+ :path => "/asdf/qwer/1234/title",
225
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5" },
226
+ :headers => { "sample" => "example", "Host" => "localhost" },
227
+ :payload => "testing")
228
+
229
+ signing_options = Pandexio::SigningOptions.new(
230
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
231
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
232
+ :domain_id => "1234567890",
233
+ :domain_key => "asdfjklqwerzxcv",
234
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
235
+ :expires => 90,
236
+ :originator => "HeaderSigningTest",
237
+ :email_address => "Anonymous",
238
+ :display_name => "Anonymous",
239
+ :profile_image => "abcdefg")
240
+
241
+ @authorized_request = Pandexio::to_authorized_request(normalized_request, signing_options)
242
+ end
243
+
244
+ it "returns the correct authorization header" do
245
+ @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"
246
+ end
247
+
248
+ end
249
+
250
+ end
249
251
  end