authograph 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a009a88fac93d49a6386eb963bd7e540ab904c3
4
- data.tar.gz: 299582d4a1eb05ababa92219e1a6c4883a327d88
3
+ metadata.gz: a52a4a4e452cfbaa7157719b09cc0c4ec6c24cb9
4
+ data.tar.gz: aafe1c75a3b8c62a26e8ca3090541100f474b703
5
5
  SHA512:
6
- metadata.gz: a61ca58c96985b2357ba5af9a3ea503869c51836edfe9bb3bd84c818c9974cd8e5ba1b8f3b14e39086193d566fc033a03f35ed4ed62461efb827d069d8eb5c7c
7
- data.tar.gz: 1c032e7dad769f70a81fc0186f6b6de6d122c7b8be9829bf16a72e10d013301beb5bd304ab4a25ea030e47ad8dd272c278c4a6dc9cd6625c02c9a79d1a27c436
6
+ metadata.gz: 1707868c3bbc1a64159c7950d16f417daa0448811409d325f1f863957afa4fe63a13b31739b164cad65ccedc1aeb5ab3028d848bd58c642cc7fa600af2734293
7
+ data.tar.gz: 56957e84964052c0268f801d024f5bcd1c4f9ae42db14482a8b58e6f35381a047b94ec61bbad0c694456ec81c5c0edcffde4c1334810889f5686889173c8b56d
data/README.md CHANGED
@@ -44,7 +44,6 @@ Yo can later validate the request by using `authentic?`
44
44
  signer.authentic?(my_request, my_secret) # this will check the signature and the date by default
45
45
  ```
46
46
 
47
-
48
47
  ### Signer options
49
48
 
50
49
  **IMPORTANT** Remember to always configure both the signer-signer and the validator-signer using the same paremeters.
@@ -58,6 +57,23 @@ The following parameters are available when calling `Authograph.signer`:
58
57
  * `date_header`: header key to store date in (`'X-Date'` by default).
59
58
  * `date_max_skew`: maximum difference (in secs) between request time and validaton (`'600'` by default).
60
59
 
60
+ ### Testing (only rspec)
61
+
62
+ Sometimes is useful to stub the signing process on tests.
63
+
64
+ Make sure to include the rspec extensions on your `spec_helper.rb`:
65
+
66
+ ```ruby
67
+ require 'authograph/rspec'
68
+ ```
69
+
70
+ Now you can call the `stub_authograph` inside your tests:
71
+
72
+ ```ruby
73
+ before { stub_authograph(:any, 'mysignature') } }
74
+ before { stub_authograph({ secret: 'my_secret' }, 'mysignature') } # only stub signatures for a given secret (TODO)
75
+ before { stub_authograph({ path: '/my/path' }, 'mysignature') } # only stub signatures for a given path (TODO)
76
+ ```
61
77
 
62
78
  ### Generated signature structure
63
79
 
@@ -0,0 +1,27 @@
1
+ module Authograph
2
+ module RSpecHelpers
3
+ def stub_authograph(_matcher, _signature = nil)
4
+ if _signature.nil?
5
+ _signature = _matcher
6
+ _matcher = :any
7
+ end
8
+
9
+ allow_any_instance_of(Authograph::Signer)
10
+ .to receive(:calc_signature)
11
+ .and_wrap_original do |original, request, secret|
12
+ case _matcher
13
+ when :any
14
+ next _signature
15
+ when Hash
16
+ # TODO
17
+ end
18
+
19
+ original.call(request, secret) # fallback to original
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+ config.include Authograph::RSpecHelpers
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Authograph
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authograph
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - lib/authograph/adapters/faraday.rb
107
107
  - lib/authograph/adapters/http.rb
108
108
  - lib/authograph/adapters/rack.rb
109
+ - lib/authograph/rspec.rb
109
110
  - lib/authograph/signer.rb
110
111
  - lib/authograph/version.rb
111
112
  homepage: https://github.com/SurBTC/authograph