simple-hmac 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rest-client/request.rb +3 -1
- data/lib/simple-hmac.rb +1 -0
- data/lib/simple-hmac/helper.rb +7 -5
- data/lib/simple-hmac/version.rb +1 -1
- data/spec/hmac_token_spec.rb +16 -0
- data/spec/spec_helper.rb +88 -0
- metadata +6 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bfa82f93215fb4ea957df12f431f8724ddf21e5
|
4
|
+
data.tar.gz: 03d8abc02af61be2dc51d3bba4e534176a5765e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09ef402f20b5c9d9c04424184f7fc327e99425e8ec7937f72c13a443a7da728ebe8ae8b7f189501e4e5fdbd827bd863c2e9b6728802e39b812161fccf326e04b
|
7
|
+
data.tar.gz: 726648a3c861e53a80fa9c8cba3873bce3ea03fd1d32877600f3f0299beb2a0d0e7b4fc8878b309f498864cc6043272102628dc071030e8e57d65f4164828dea
|
data/lib/rest-client/request.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
module RestClient
|
2
4
|
class Request
|
3
5
|
include SimpleHmac::Helper
|
@@ -5,7 +7,7 @@ module RestClient
|
|
5
7
|
def sign!(api_id, api_secret, options={})
|
6
8
|
options = { auth_prefix: 'WIZYPAY' }.merge(options)
|
7
9
|
auth_prefix = options.delete :auth_prefix
|
8
|
-
date = Time.now.
|
10
|
+
date = Time.now.httpdate
|
9
11
|
processed_headers.merge! 'Date' => date
|
10
12
|
content_type = processed_headers['Content-Type'] || 'text/plain'
|
11
13
|
processed_headers.merge! 'Content-Type' => content_type
|
data/lib/simple-hmac.rb
CHANGED
data/lib/simple-hmac/helper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module SimpleHmac
|
2
2
|
module Helper
|
3
|
-
def hmac_token(verb, content_type,
|
4
|
-
options = { separator: "\n", algorithm: 'sha256' }.merge(options)
|
5
|
-
|
6
|
-
data
|
7
|
-
|
3
|
+
def hmac_token(verb, content_type, content_md5, url, date, api_secret, options={})
|
4
|
+
options = { separator: "\n", algorithm: 'sha256', include_verb: true }.merge(options)
|
5
|
+
url_without_server = url.gsub(/https?:\/\/[^(,|\?|\/)]*/, '')
|
6
|
+
data = [verb.upcase, content_type, content_md5, url_without_server, date]
|
7
|
+
data.shift unless options[:include_verb]
|
8
|
+
string_to_sign = data.join(options[:separator])
|
9
|
+
Base64.strict_encode64(OpenSSL::HMAC.digest(options[:algorithm], api_secret, string_to_sign))
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
data/lib/simple-hmac/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
RSpec.describe SimpleHmac::Helper do
|
2
|
+
context '#hmac_token' do
|
3
|
+
before do
|
4
|
+
@signer = Object.new
|
5
|
+
@signer.extend SimpleHmac::Helper
|
6
|
+
end
|
7
|
+
it 'should use default values for GET' do
|
8
|
+
actual = @signer.hmac_token(:get, 'application/json', '', 'http://example.com/hello', 'Mon, 16 Feb 2015 11:06:40 GMT', 'SECRET_CODE')
|
9
|
+
|
10
|
+
string_to_sign = ['GET', 'application/json', '', '/hello', 'Mon, 16 Feb 2015 11:06:40 GMT'].join("\n")
|
11
|
+
expected = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', 'SECRET_CODE', string_to_sign))
|
12
|
+
|
13
|
+
expect(actual).to eq(expected)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'simple-hmac'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
# Conventionally, all specs live under a `spec` directory, which RSpec adds to
|
6
|
+
# the `$LOAD_PATH`. The generated `.rspec` file contains `--require spec_helper`
|
7
|
+
# which will cause this file to always be loaded, without a need to explicitly
|
8
|
+
# require it in any files.
|
9
|
+
#
|
10
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
11
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
12
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
13
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
14
|
+
# a separate helper file that requires the additional dependencies and performs
|
15
|
+
# the additional setup, and require it from the spec files that actually need it.
|
16
|
+
#
|
17
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
18
|
+
# users commonly want.
|
19
|
+
#
|
20
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# rspec-expectations config goes here. You can use an alternate
|
23
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
+
# assertions if you prefer.
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
+
# and `failure_message` of custom matchers include text for helper methods
|
28
|
+
# defined using `chain`, e.g.:
|
29
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
+
# # => "be bigger than 2 and smaller than 4"
|
31
|
+
# ...rather than:
|
32
|
+
# # => "be bigger than 2"
|
33
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
|
+
end
|
35
|
+
|
36
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
|
+
config.mock_with :rspec do |mocks|
|
39
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
+
# a real object. This is generally recommended, and will default to
|
41
|
+
# `true` in RSpec 4.
|
42
|
+
mocks.verify_partial_doubles = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# The settings below are suggested to provide a good initial experience
|
46
|
+
# with RSpec, but feel free to customize to your heart's content.
|
47
|
+
|
48
|
+
# These two settings work together to allow you to limit a spec run
|
49
|
+
# to individual examples or groups you care about by tagging them with
|
50
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
51
|
+
# get run.
|
52
|
+
config.filter_run :focus
|
53
|
+
config.run_all_when_everything_filtered = true
|
54
|
+
|
55
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
56
|
+
# For more details, see:
|
57
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
58
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
59
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
60
|
+
config.disable_monkey_patching!
|
61
|
+
|
62
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
+
# file, and it's useful to allow more verbose output when running an
|
64
|
+
# individual spec file.
|
65
|
+
if config.files_to_run.one?
|
66
|
+
# Use the documentation formatter for detailed output,
|
67
|
+
# unless a formatter has already been configured
|
68
|
+
# (e.g. via a command-line flag).
|
69
|
+
config.default_formatter = 'doc'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Print the 10 slowest examples and example groups at the
|
73
|
+
# end of the spec run, to help surface which specs are running
|
74
|
+
# particularly slow.
|
75
|
+
config.profile_examples = 10
|
76
|
+
|
77
|
+
# Run specs in random order to surface order dependencies. If you find an
|
78
|
+
# order dependency and want to debug it, you can fix the order by providing
|
79
|
+
# the seed, which is printed after each run.
|
80
|
+
# --seed 1234
|
81
|
+
config.order = :random
|
82
|
+
|
83
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
+
# test failures related to randomization by passing the same `--seed` value
|
86
|
+
# as the one that triggered the failure.
|
87
|
+
Kernel.srand config.seed
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chaker Nakhli
|
@@ -24,34 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '4.2'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '4.2'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activemodel
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '4.2'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '4.2'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
28
|
name: bundler
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +94,8 @@ files:
|
|
122
94
|
- lib/simple-hmac.rb
|
123
95
|
- lib/simple-hmac/helper.rb
|
124
96
|
- lib/simple-hmac/version.rb
|
97
|
+
- spec/hmac_token_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
125
99
|
homepage: http://www.wizypay.com
|
126
100
|
licenses:
|
127
101
|
- MIT
|
@@ -147,4 +121,6 @@ rubygems_version: 2.4.3
|
|
147
121
|
signing_key:
|
148
122
|
specification_version: 4
|
149
123
|
summary: Lightweight HMAC implementation for Rails + Restclient.
|
150
|
-
test_files:
|
124
|
+
test_files:
|
125
|
+
- spec/hmac_token_spec.rb
|
126
|
+
- spec/spec_helper.rb
|