pandexio 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require_relative '../lib/scope.rb'
5
+
6
+ describe Pandexio::Scope do
7
+ describe "#initialize" do
8
+
9
+ describe "when passing no document_ids param" do
10
+
11
+ before do
12
+ @scope = Pandexio::Scope.new()
13
+ end
14
+
15
+ it "should initialize document_ids as an empty array" do
16
+ @scope.document_ids.count.must_equal 0
17
+ end
18
+
19
+ end
20
+
21
+ describe "when passing document_ids param" do
22
+
23
+ before do
24
+ @scope = Pandexio::Scope.new(:document_ids => ['a', 'b', 'c'])
25
+ end
26
+
27
+ it "should initialize document_ids with params value" do
28
+ @scope.document_ids.count.must_equal 3
29
+ @scope.document_ids[0].must_equal 'a'
30
+ @scope.document_ids[1].must_equal 'b'
31
+ @scope.document_ids[2].must_equal 'c'
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require_relative '../lib/scope_patterns.rb'
5
+
6
+ describe Pandexio::ScopePatterns do
7
+
8
+ it 'extracts_document_id_from_path_regardless_of_leading_segment' do
9
+ match = '/asdf/documents/123/snips/abc'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
10
+ refute_nil(match)
11
+ match['documentid'].must_equal '123'
12
+ end
13
+
14
+ it 'extracts_document_id_from_path_containing_uppercase_and_lowercase_characters' do
15
+ match = '/v2/Documents/123/Snips/abc'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
16
+ refute_nil(match)
17
+ match['documentid'].must_equal '123'
18
+ end
19
+
20
+ it 'extracts_document_id_from_path_containing_only_lowercase_characters' do
21
+ match = '/v2/documents/123/snips/abc'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
22
+ refute_nil(match)
23
+ match['documentid'].must_equal '123'
24
+ end
25
+
26
+ it 'extracts_document_id_from_path_containing_only_uppercase_characters' do
27
+ match = '/V2/DOCUMENTS/123/SNIPS/abc'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
28
+ refute_nil(match)
29
+ match['documentid'].must_equal '123'
30
+ end
31
+
32
+ it 'extracts_document_id_from_path_containing_only_document_id' do
33
+ match = '/v2/documents/123'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
34
+ refute_nil(match)
35
+ match['documentid'].must_equal '123'
36
+ end
37
+
38
+ it 'extracts_document_id_from_path_containing_document_id_and_trailing_slash' do
39
+ match = '/v2/documents/123/'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
40
+ refute_nil(match)
41
+ match['documentid'].must_equal '123'
42
+ end
43
+
44
+ it 'extracts_document_id_from_path_containing_document_id_and_trailing_query_string' do
45
+ match = '/v2/documents/123?coversize=xl'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
46
+ refute_nil(match)
47
+ match['documentid'].must_equal '123'
48
+ end
49
+
50
+ it 'extracts_document_id_from_path_containing_document_id_and_snip_id' do
51
+ match = '/v2/documents/123/snips/abc'.match(Pandexio::ScopePatterns::DOCUMENT_PATH_PATTERN)
52
+ refute_nil(match)
53
+ match['documentid'].must_equal '123'
54
+ end
55
+
56
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require_relative '../lib/signer.rb'
5
+
6
+ describe Pandexio::Signer do
7
+ describe "#scope_and_sign" do
8
+
9
+ describe "when path contains a document_id" do
10
+
11
+ before do
12
+ normalized_request = Pandexio::Request.new(
13
+ :method => "PUT",
14
+ :path => "/asdf/documents/123/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
+ signer = Pandexio::Signer.new()
31
+
32
+ @scope, authorized_request = signer.scope_and_sign(normalized_request, signing_options)
33
+ end
34
+
35
+ it "extracts document_id" do
36
+ @scope.document_ids.count.must_equal 1
37
+ @scope.document_ids[0].must_equal "123"
38
+ end
39
+
40
+ end
41
+
42
+ describe "when query string contains document_ids" do
43
+
44
+ before do
45
+ normalized_request = Pandexio::Request.new(
46
+ :method => "PUT",
47
+ :path => "/asdf/qwer/1234/title",
48
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5", "documentIds" => "456,789" },
49
+ :headers => { "sample" => "example", "Host" => "localhost" },
50
+ :payload => "testing")
51
+
52
+ signing_options = Pandexio::SigningOptions.new(
53
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
54
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
55
+ :domain_id => "1234567890",
56
+ :domain_key => "asdfjklqwerzxcv",
57
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
58
+ :expires => 90,
59
+ :originator => "HeaderSigningTest",
60
+ :email_address => "Anonymous",
61
+ :display_name => "Anonymous")
62
+
63
+ signer = Pandexio::Signer.new()
64
+
65
+ @scope, authorized_request = signer.scope_and_sign(normalized_request, signing_options)
66
+ end
67
+
68
+ it "extracts document_id" do
69
+ @scope.document_ids.count.must_equal 2
70
+ @scope.document_ids[0].must_equal "456"
71
+ @scope.document_ids[1].must_equal "789"
72
+ end
73
+
74
+ end
75
+
76
+ describe "when path contains a document_id and query string contains document_ids" do
77
+
78
+ before do
79
+ normalized_request = Pandexio::Request.new(
80
+ :method => "PUT",
81
+ :path => "/asdf/documents/123/title",
82
+ :query_parameters => { "nonce" => "987654321", "Baseline" => "5", "documentIds" => "456,789" },
83
+ :headers => { "sample" => "example", "Host" => "localhost" },
84
+ :payload => "testing")
85
+
86
+ signing_options = Pandexio::SigningOptions.new(
87
+ :algorithm => Pandexio::SigningAlgorithms::PDX_HMAC_SHA256,
88
+ :mechanism => Pandexio::SigningMechanisms::HEADER,
89
+ :domain_id => "1234567890",
90
+ :domain_key => "asdfjklqwerzxcv",
91
+ :date => Time.utc(2014, 11, 21, 13, 43, 15),
92
+ :expires => 90,
93
+ :originator => "HeaderSigningTest",
94
+ :email_address => "Anonymous",
95
+ :display_name => "Anonymous")
96
+
97
+ signer = Pandexio::Signer.new()
98
+
99
+ @scope, authorized_request = signer.scope_and_sign(normalized_request, signing_options)
100
+ end
101
+
102
+ it "extracts document_id" do
103
+ @scope.document_ids.count.must_equal 3
104
+ @scope.document_ids[0].must_equal "123"
105
+ @scope.document_ids[1].must_equal "456"
106
+ @scope.document_ids[2].must_equal "789"
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandexio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Brandon Varilone
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
12
+ date: 2015-07-09 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: Pandexio SDK for Ruby
14
15
  email: bvarilone@gmail.com
@@ -20,34 +21,41 @@ files:
20
21
  - Rakefile
21
22
  - lib/pandexio.rb
22
23
  - lib/request.rb
24
+ - lib/scope.rb
25
+ - lib/scope_patterns.rb
26
+ - lib/signer.rb
23
27
  - lib/signing_algorithms.rb
24
28
  - lib/signing_attributes.rb
25
29
  - lib/signing_mechanisms.rb
26
30
  - lib/signing_options.rb
27
31
  - test/test_header_signing.rb
28
32
  - test/test_query_string_signing.rb
33
+ - test/test_scope.rb
34
+ - test/test_scope_patterns.rb
35
+ - test/test_signer.rb
29
36
  homepage: http://rubygems.org/gems/pandexio
30
37
  licenses:
31
38
  - MIT
32
- metadata: {}
33
39
  post_install_message:
34
40
  rdoc_options: []
35
41
  require_paths:
36
42
  - lib
37
43
  required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
38
45
  requirements:
39
- - - ">="
46
+ - - ! '>='
40
47
  - !ruby/object:Gem::Version
41
48
  version: '0'
42
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
43
51
  requirements:
44
- - - ">="
52
+ - - ! '>='
45
53
  - !ruby/object:Gem::Version
46
54
  version: '0'
47
55
  requirements: []
48
56
  rubyforge_project:
49
- rubygems_version: 2.4.4
57
+ rubygems_version: 1.8.23.2
50
58
  signing_key:
51
- specification_version: 4
59
+ specification_version: 3
52
60
  summary: Signs Pandexio requests using HMAC
53
61
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 6c9d55b6ec58cc16963480e75a5e9eac548de250
4
- data.tar.gz: bfb4999c3f1e26d397de6706899731f69255b39d
5
- SHA512:
6
- metadata.gz: 0853e2951622cd1821d701649592548ea9d9d1709618a132b0ce68965c78e55fcc042e954d91c556fb7709261e60aa8ec8ffff6ea89da3b7af85c5ffe7c2d0b6
7
- data.tar.gz: 925a55615f1ba481d18639ca24cda967773a0733e63d86de05ef95df1a8062833786d9fd649763d183a94866da89e5e5c789e41c91e178ab91f11e82e12cfa61