pandexio 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pandexio.rb +6 -1
- data/test/test_header_signing.rb +46 -0
- data/test/test_query_string_signing.rb +46 -0
- metadata +1 -1
data/lib/pandexio.rb
CHANGED
@@ -115,7 +115,12 @@ module Pandexio
|
|
115
115
|
raise ArgumentError, 'signing_options.email_address must be of type String and cannot be nil or empty' unless !signing_options.email_address.nil? && signing_options.email_address.is_a?(String) && !signing_options.email_address.empty?
|
116
116
|
raise ArgumentError, 'signing_options.display_name must be of type String and cannot be nil or empty' unless !signing_options.display_name.nil? && signing_options.display_name.is_a?(String) && !signing_options.display_name.empty?
|
117
117
|
|
118
|
-
authorized_request =
|
118
|
+
authorized_request = Pandexio::Request.new(
|
119
|
+
:method => normalized_request.method,
|
120
|
+
:path => normalized_request.path,
|
121
|
+
:query_parameters => normalized_request.query_parameters.clone,
|
122
|
+
:headers => normalized_request.headers.clone,
|
123
|
+
:payload => normalized_request.payload)
|
119
124
|
|
120
125
|
append = lambda { |p|
|
121
126
|
p[SigningAttributes::DATE] = signing_options.date.iso8601
|
data/test/test_header_signing.rb
CHANGED
@@ -6,6 +6,52 @@ require_relative '../lib/pandexio.rb'
|
|
6
6
|
describe Pandexio do
|
7
7
|
describe "#to_authorized_request" do
|
8
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
|
+
|
9
55
|
describe "when using header signing mechanism and email_address contains uppercase and lowercase characters" do
|
10
56
|
|
11
57
|
before do
|
@@ -6,6 +6,52 @@ require_relative '../lib/pandexio.rb'
|
|
6
6
|
describe Pandexio do
|
7
7
|
describe "#to_authorized_request" do
|
8
8
|
|
9
|
+
describe "when using query string 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::QUERY_STRING,
|
22
|
+
:domain_id => "1234567890",
|
23
|
+
:domain_key => "asdfjklqwerzxcv",
|
24
|
+
:date => Time.utc(2014, 11, 21, 13, 43, 15),
|
25
|
+
:expires => 90,
|
26
|
+
:originator => "QueryStringSigningTest",
|
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
|
+
|
9
55
|
describe "when using query string signing mechanism and email_address contains uppercase and lowercase characters" do
|
10
56
|
|
11
57
|
before do
|