smaak 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,9 @@
1
1
  require './spec/spec_helper.rb'
2
2
  require 'smaak'
3
- require 'mock/request.rb'
4
3
 
5
4
  def mock_auth_message(env)
6
5
  request = Rack::Request.new(env)
7
- adaptor = Smaak::create_adaptor(request)
6
+ adaptor = Smaak.create_adaptor(request)
8
7
  @iut.build_auth_message_from_request(adaptor)
9
8
  end
10
9
 
@@ -29,7 +28,7 @@ describe Smaak::Server do
29
28
  expect(@iut.nonce_store[@test_nonce]).to eq(nil)
30
29
 
31
30
  @test_expires = "#{Time.now.to_i + 5}"
32
- @env = {"CONTENT_LENGTH" => "25", "REQUEST_METHOD" => "POST", "PATH_INFO" => "/gems/smaak", "HTTP_X_SMAAK_ENCRYPT" => "false", "HTTP_X_SMAAK_RECIPIENT" => Base64.strict_encode64(@test_server_public_key.export), "HTTP_X_SMAAK_IDENTIFIER" => @test_identifier, "HTTP_X_SMAAK_ROUTE_INFO" => @test_route_info, "HTTP_X_SMAAK_NONCE" => @test_nonce, "HTTP_X_SMAAK_EXPIRES" => @test_expires, "HTTP_X_SMAAK_PSK" => Smaak::Crypto::obfuscate_psk(@test_psk) }
31
+ @env = {"CONTENT_LENGTH" => "25", "REQUEST_METHOD" => "POST", "PATH_INFO" => "/gems/smaak", "HTTP_X_SMAAK_ENCRYPT" => "false", "HTTP_X_SMAAK_RECIPIENT" => Base64.strict_encode64(@test_server_public_key.export), "HTTP_X_SMAAK_IDENTIFIER" => @test_identifier, "HTTP_X_SMAAK_ROUTE_INFO" => @test_route_info, "HTTP_X_SMAAK_NONCE" => @test_nonce, "HTTP_X_SMAAK_EXPIRES" => @test_expires, "HTTP_X_SMAAK_PSK" => Smaak::Crypto.obfuscate_psk(@test_psk) }
33
32
  @auth_message = mock_auth_message(@env)
34
33
  end
35
34
 
@@ -113,7 +112,7 @@ describe Smaak::Server do
113
112
  end
114
113
 
115
114
  it "should set the psk to the x-smaak-psk header value" do
116
- expect(@auth_message.psk).to eql(Smaak::Crypto::obfuscate_psk(@test_psk))
115
+ expect(@auth_message.psk).to eql(Smaak::Crypto.obfuscate_psk(@test_psk))
117
116
  end
118
117
 
119
118
  it "should set expires to the x-smaak-expires header value" do
@@ -11,7 +11,7 @@ class Tester < Smaak::SmaakService
11
11
  @@instance
12
12
  end
13
13
 
14
- def configure_services(configuration = nil)
14
+ def configure_services(_configuration = nil)
15
15
  @configured = true
16
16
  end
17
17
  end
@@ -44,8 +44,8 @@ describe Smaak::SmaakService do
44
44
 
45
45
  context "as a singleton" do
46
46
  it "should implement the singleton pattern and be thread-safe" do
47
- expect(Tester::mutex.is_a? Mutex).to eq(true)
48
- expect(Tester::instance.nil?).to eq(false)
47
+ expect(Tester.mutex.is_a? Mutex).to eq(true)
48
+ expect(Tester.instance.nil?).to eq(false)
49
49
  end
50
50
  end
51
51
  end
@@ -14,8 +14,8 @@ describe Smaak do
14
14
  @test_route_info = 'identifier'
15
15
  @test_recipient = @test_server_public_key.export
16
16
  @test_encrypt = true
17
- @auth_message = Smaak::AuthMessage.new(@test_identifier, @test_route_info, @test_nonce, @test_expires, Smaak::Crypto::obfuscate_psk(@test_psk), @test_recipient, @test_encrypt)
18
- @adaptor = Smaak::create_adaptor(@request)
17
+ @auth_message = Smaak::AuthMessage.new(@test_identifier, @test_route_info, @test_nonce, @test_expires, Smaak::Crypto.obfuscate_psk(@test_psk), @test_recipient, @test_encrypt)
18
+ @adaptor = Smaak.create_adaptor(@request)
19
19
  @mock_specification = Smaak::Cavage04.new(@adaptor)
20
20
  end
21
21
 
@@ -27,31 +27,31 @@ describe Smaak do
27
27
 
28
28
  context "when asked which headers should be signed" do
29
29
  it "should list all the smaak header extensions" do
30
- expect(Smaak::headers_to_be_signed.include?("x-smaak-recipient")).to eql(true)
31
- expect(Smaak::headers_to_be_signed.include?("x-smaak-identifier")).to eql(true)
32
- expect(Smaak::headers_to_be_signed.include?("x-smaak-psk")).to eql(true)
33
- expect(Smaak::headers_to_be_signed.include?("x-smaak-expires")).to eql(true)
34
- expect(Smaak::headers_to_be_signed.include?("x-smaak-nonce")).to eql(true)
35
- expect(Smaak::headers_to_be_signed.include?("x-smaak-encrypt")).to eql(true)
30
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-recipient")).to eql(true)
31
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-identifier")).to eql(true)
32
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-psk")).to eql(true)
33
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-expires")).to eql(true)
34
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-nonce")).to eql(true)
35
+ expect(Smaak.headers_to_be_signed.include?("x-smaak-encrypt")).to eql(true)
36
36
  end
37
37
  end
38
38
 
39
39
  context "when told about a new request adaptor" do
40
40
  it "should remember the adaptor class associated with the request class" do
41
- Smaak::add_request_adaptor(Integer, String)
42
- expect(Smaak::adaptors[Integer]).to eql(String)
41
+ Smaak.add_request_adaptor(Integer, String)
42
+ expect(Smaak.adaptors[Integer]).to eql(String)
43
43
  end
44
44
  end
45
45
 
46
46
  context "when asked to create a request adaptor" do
47
47
  it "should raise an ArgumentError if the request type does not have an adaptor configured" do
48
48
  expect {
49
- Smaak::create_adaptor(0.1)
50
- }.to raise_error ArgumentError, "Unknown request class Float. Add an adaptor using Smaak::add_request_adaptor."
49
+ Smaak.create_adaptor(0.1)
50
+ }.to raise_error ArgumentError, "Unknown request class Float. Add an adaptor using Smaak.add_request_adaptor."
51
51
  end
52
52
 
53
53
  it "should create a new instance of the adaptor class specified in the request adaptor dictionary" do
54
- adaptor = Smaak::create_adaptor(Net::HTTP::Post.new("http://rubygems.org:80/gems/smaak"))
54
+ adaptor = Smaak.create_adaptor(Net::HTTP::Post.new("http://rubygems.org:80/gems/smaak"))
55
55
  expect(adaptor.is_a? Smaak::NetHttpAdaptor).to eql(true)
56
56
  end
57
57
  end
@@ -59,17 +59,17 @@ describe Smaak do
59
59
  context "when asked to select a header signature specification" do
60
60
  it "should raise an ArgumentError if the specification is unknown" do
61
61
  expect {
62
- Smaak::select_specification(@adaptor, "unknown specification")
62
+ Smaak.select_specification(@adaptor, "unknown specification")
63
63
  }.to raise_error ArgumentError, "Unknown specification"
64
64
  end
65
65
 
66
66
  it "should return an instance of a known specification" do
67
- expect(Smaak::select_specification(@adaptor, Smaak::Cavage04::SPECIFICATION).is_a?(Smaak::Cavage04)).to eql(true)
67
+ expect(Smaak.select_specification(@adaptor, Smaak::Cavage04::SPECIFICATION).is_a?(Smaak::Cavage04)).to eql(true)
68
68
  end
69
69
 
70
70
  it "should raise an ArgumentError if the adaptor specified is nil" do
71
71
  expect {
72
- Smaak::select_specification(nil, Smaak::Cavage04::SPECIFICATION)
72
+ Smaak.select_specification(nil, Smaak::Cavage04::SPECIFICATION)
73
73
  }.to raise_error ArgumentError, "Adaptor must be provided"
74
74
  end
75
75
  end
@@ -77,33 +77,33 @@ describe Smaak do
77
77
  context "when asked to sign authorization headers given a key, auth_message, request adaptor and specification" do
78
78
  it "should select the requested specification" do
79
79
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
80
- Smaak::sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
80
+ Smaak.sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
81
81
  end
82
82
 
83
83
  it "should compile the signature header from the auth_message using the specification" do
84
84
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
85
85
  expect(@mock_specification).to receive(:compile_signature_headers).with(@auth_message).and_return "headers"
86
- Smaak::sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
86
+ Smaak.sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
87
87
  end
88
88
 
89
89
  it "should sign the signature headers using the key" do
90
90
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
91
91
  expect(@mock_specification).to receive(:compile_signature_headers).with(@auth_message).and_return "headers"
92
92
  expect(Smaak::Crypto).to receive(:sign_data).with("headers", @test_server_private_key).and_return("signed headers")
93
- Smaak::sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
93
+ Smaak.sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
94
94
  end
95
95
 
96
96
  it "should compile an auth header using the signature as the signature data base 64 encoded" do
97
97
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
98
98
  expect(@mock_specification).to receive(:compile_signature_headers).with(@auth_message).and_return "headers"
99
99
  expect(Smaak::Crypto).to receive(:sign_data).with("headers", @test_server_private_key).and_return("signed headers")
100
- expect(@mock_specification).to receive(:compile_auth_header).with(Base64::strict_encode64("signed headers"))
101
- Smaak::sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
100
+ expect(@mock_specification).to receive(:compile_auth_header).with(Base64.strict_encode64("signed headers"))
101
+ Smaak.sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)
102
102
  end
103
103
 
104
104
  it "should return the adapter" do
105
105
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
106
- expect(Smaak::sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)).to eql(@adaptor)
106
+ expect(Smaak.sign_authorization_headers(@test_server_private_key, @auth_message, @adaptor, Smaak::Cavage04::SPECIFICATION)).to eql(@adaptor)
107
107
  end
108
108
  end
109
109
 
@@ -111,7 +111,7 @@ describe Smaak do
111
111
  it "should select the requested specification" do
112
112
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
113
113
  expect {
114
- Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)
114
+ Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)
115
115
  }.to raise_error
116
116
  end
117
117
 
@@ -119,7 +119,7 @@ describe Smaak do
119
119
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
120
120
  expect(@mock_specification).to receive(:extract_signature_headers).and_return "headers"
121
121
  expect {
122
- Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)
122
+ Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)
123
123
  }.to raise_error
124
124
  end
125
125
 
@@ -127,41 +127,41 @@ describe Smaak do
127
127
  expect(Smaak::Cavage04).to receive(:new).and_return(@mock_specification)
128
128
  expect(@mock_specification).to receive(:extract_signature_headers).and_return "headers"
129
129
  expect(@mock_specification).to receive(:extract_signature).and_return Base64.strict_encode64("signature")
130
- Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)
130
+ Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)
131
131
  end
132
132
 
133
133
  it "should return false if the signature is nil" do
134
134
  expect(Smaak).to receive(:get_signature_data_from_request).with(@adaptor).and_return(["headers", nil])
135
- expect(Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
135
+ expect(Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
136
136
  end
137
137
 
138
138
  it "should return false if the signature headers are nil" do
139
139
  expect(Smaak).to receive(:get_signature_data_from_request).with(@adaptor).and_return([nil, "signature"])
140
- expect(Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
140
+ expect(Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
141
141
  end
142
142
 
143
143
  it "should raise an ArgumentError if the public key is nil" do
144
144
  expect {
145
- Smaak::verify_authorization_headers(@adaptor, nil)
145
+ Smaak.verify_authorization_headers(@adaptor, nil)
146
146
  }.to raise_error ArgumentError, "Key is required"
147
147
  end
148
148
 
149
149
  it "should verify the signature using the signature headers base 64 encoded, with the public key. I.e. can I produce the same signature?" do
150
150
  expect(Smaak).to receive(:get_signature_data_from_request).with(@adaptor).and_return(["headers", "signature"])
151
- expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto::encode64("headers"), @test_server_public_key).and_return true
152
- Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)
151
+ expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto.encode64("headers"), @test_server_public_key).and_return true
152
+ Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)
153
153
  end
154
154
 
155
155
  it "should return false if verification fails" do
156
156
  expect(Smaak).to receive(:get_signature_data_from_request).with(@adaptor).and_return(["headers", "signature"])
157
- expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto::encode64("headers"), @test_server_public_key).and_return false
158
- expect(Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
157
+ expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto.encode64("headers"), @test_server_public_key).and_return false
158
+ expect(Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(false)
159
159
  end
160
160
 
161
161
  it "should return true if verification succeeds" do
162
162
  expect(Smaak).to receive(:get_signature_data_from_request).with(@adaptor).and_return(["headers", "signature"])
163
- expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto::encode64("headers"), @test_server_public_key).and_return true
164
- expect(Smaak::verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(true)
163
+ expect(Smaak::Crypto).to receive(:verify_signature).with("signature", Smaak::Crypto.encode64("headers"), @test_server_public_key).and_return true
164
+ expect(Smaak.verify_authorization_headers(@adaptor, @test_server_public_key)).to eql(true)
165
165
  end
166
166
  end
167
167
  end
@@ -1,12 +1,17 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'rspec'
2
5
  require 'rspec/mocks'
3
6
  require 'tempfile'
4
- require 'simplecov'
5
- require 'simplecov-rcov'
6
- #require 'byebug'
7
+ # require 'simplecov'
8
+ # require 'simplecov-rcov'
9
+ # require 'byebug'
7
10
  require 'net/http'
8
11
  require 'rack/request'
9
12
 
13
+
14
+
10
15
  # This file was generated by the `rspec --init` command. Conventionally, all
11
16
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
17
  # Require this file using `require "spec_helper"` to ensure that it is only
@@ -27,7 +32,7 @@ require 'lib/smaak/smaak_service.rb'
27
32
  RSpec.configure do |config|
28
33
  config.run_all_when_everything_filtered = true
29
34
  config.filter_run :focus
30
- #config.expect_with(:rspec) { |c| c.syntax = :should }
35
+ # config.expect_with(:rspec) { |c| c.syntax = :should }
31
36
 
32
37
  # Run specs in random order to surface order dependencies. If you find an
33
38
  # order dependency and want to debug it, you can fix the order by providing
@@ -37,8 +42,8 @@ RSpec.configure do |config|
37
42
  end
38
43
  RSpec::Expectations.configuration.warn_about_potential_false_positives = false
39
44
 
40
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
41
- SimpleCov.start do
42
- add_filter "/spec/"
43
- end
45
+ # SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
46
+ # SimpleCov.start do
47
+ # add_filter "/spec/"
48
+ # end
44
49
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smaak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: persistent-cache-ram
@@ -67,33 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov
70
+ name: coveralls
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: 0.11.1
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: 0.11.1
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov-rcov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ~>
73
+ - - '>='
88
74
  - !ruby/object:Gem::Version
89
- version: 0.2.3
75
+ version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ~>
80
+ - - '>='
95
81
  - !ruby/object:Gem::Version
96
- version: 0.2.3
82
+ version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rspec
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +118,7 @@ files:
132
118
  - .gitignore
133
119
  - .ruby-gemset
134
120
  - .ruby-version
121
+ - .travis.yml
135
122
  - Gemfile
136
123
  - LICENSE.txt
137
124
  - README.md
@@ -159,7 +146,6 @@ files:
159
146
  - spec/lib/smaak/server_spec.rb
160
147
  - spec/lib/smaak/smaak_service_spec.rb
161
148
  - spec/lib/smaak_spec.rb
162
- - spec/mock/request.rb
163
149
  - spec/spec_helper.rb
164
150
  homepage: https://github.com/evangraan/smaak.git
165
151
  licenses:
@@ -200,5 +186,4 @@ test_files:
200
186
  - spec/lib/smaak/server_spec.rb
201
187
  - spec/lib/smaak/smaak_service_spec.rb
202
188
  - spec/lib/smaak_spec.rb
203
- - spec/mock/request.rb
204
189
  - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- class Request
2
- attr_accessor :env
3
-
4
- def initialize(env)
5
- @env = env
6
- end
7
- end