Skip to content

Commit ca63ac9

Browse files
committed
MAC signature & body hash calculation check
* Signature calculation example is from the example of MAC spec section 1.2 & 3.2 * Body hash calculation example is from the example of MAC spec section 3.2 ref) http://tools.ietf.org/pdf/draft-ietf-oauth-v2-http-mac-00.pdf
1 parent 11a7306 commit ca63ac9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
describe Rack::OAuth2::AccessToken::MAC::BodyHash do
4+
# From the example of MAC spec section 3.2
5+
# ref) http://tools.ietf.org/pdf/draft-ietf-oauth-v2-http-mac-00.pdf
6+
subject do
7+
Rack::OAuth2::AccessToken::MAC::BodyHash.new(
8+
:algorithm => 'hmac-sha-1',
9+
:raw_body => 'hello=world%21'
10+
)
11+
end
12+
its(:calculate) { should == 'k9kbtCIy0CkI3/FEfpS/oIDjk6k=' }
13+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'spec_helper'
2+
3+
describe Rack::OAuth2::AccessToken::MAC::Signature do
4+
5+
# From the example of MAC spec section 1.2
6+
# ref) http://tools.ietf.org/pdf/draft-ietf-oauth-v2-http-mac-00.pdf
7+
context 'when body_hash is given' do
8+
subject do
9+
Rack::OAuth2::AccessToken::MAC::Signature.new(
10+
:secret => '8yfrufh348h',
11+
:algorithm => 'hmac-sha-1',
12+
:nonce => '273156:di3hvdf8',
13+
:method => 'POST',
14+
:request_uri => '/request',
15+
:host => 'example.com',
16+
:port => 80,
17+
:body_hash => 'k9kbtCIy0CkI3/FEfpS/oIDjk6k=',
18+
:ext => nil
19+
)
20+
end
21+
its(:calculate) { should == 'W7bdMZbv9UWOTadASIQHagZyirA=' }
22+
end
23+
24+
# From the example of MAC spec section 3.2
25+
# ref) http://tools.ietf.org/pdf/draft-ietf-oauth-v2-http-mac-00.pdf
26+
context 'otherwize' do
27+
subject do
28+
Rack::OAuth2::AccessToken::MAC::Signature.new(
29+
:secret => '489dks293j39',
30+
:algorithm => 'hmac-sha-1',
31+
:nonce => '264095:dj83hs9s',
32+
:method => 'GET',
33+
:request_uri => '/resource/1?b=1&a=2',
34+
:host => 'example.com',
35+
:port => 80,
36+
:body_hash => nil,
37+
:ext => nil
38+
)
39+
end
40+
its(:calculate) { should == 'SLDJd4mg43cjQfElUs3Qub4L6xE=' }
41+
end
42+
43+
end

0 commit comments

Comments
 (0)