oauthenticator 1.3.5 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
- proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
3
- require 'helper'
4
-
5
- describe 'OAuthenticator.parse_authorization' do
6
- let :spec_authorization do
7
- %q(OAuth realm="Example",
8
- oauth_consumer_key="9djdj82h48djs9d2",
9
- oauth_token="kkk9d7dh3k39sjv7",
10
- oauth_signature_method="HMAC-SHA1",
11
- oauth_timestamp="137131201",
12
- oauth_nonce="7d8f3e4a",
13
- oauth_signature="r6%2FTJjbCOr97%2F%2BUU0NsvSne7s5g%3D"
14
- )
15
- end
16
- let :spec_authorization_hash do
17
- {
18
- 'realm' => "Example",
19
- 'oauth_consumer_key' => "9djdj82h48djs9d2",
20
- 'oauth_token' => "kkk9d7dh3k39sjv7",
21
- 'oauth_signature_method' => "HMAC-SHA1",
22
- 'oauth_timestamp' => "137131201",
23
- 'oauth_nonce' => "7d8f3e4a",
24
- 'oauth_signature' => "r6/TJjbCOr97/+UU0NsvSne7s5g=",
25
- }
26
- end
27
-
28
- it 'parses the example in the spec' do
29
- assert_equal(spec_authorization_hash, OAuthenticator.parse_authorization(spec_authorization))
30
- end
31
- it 'parses the authorization SignableRequest calculates' do
32
- request = OAuthenticator::SignableRequest.new({
33
- :request_method => 'POST',
34
- :uri => 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b',
35
- :media_type => 'application/x-www-form-urlencoded',
36
- :body => 'c2&a3=2+q',
37
- :authorization => spec_authorization_hash,
38
- :consumer_secret => 'j49sk3j29djd',
39
- :token_secret => 'dh893hdasih9',
40
- })
41
- assert_equal(spec_authorization_hash, OAuthenticator.parse_authorization(request.authorization))
42
- end
43
-
44
- describe 'optional linear white space' do
45
- { :space => %q(OAuth a="b", c="d", e="f"),
46
- :spaces => %q(OAuth a="b", c="d", e="f" ),
47
- :tab => %q(OAuth a="b", c="d", e="f"),
48
- :tabs => %q(OAuth a="b", c="d", e="f"),
49
- :tabs_and_spaces => %q(OAuth a="b", c="d", e="f"),
50
- :none => %q(OAuth a="b",c="d",e="f"),
51
- }.map do |name, authorization|
52
- it "parses with #{name}" do
53
- assert_equal({'a' => 'b', 'c' => 'd', 'e' => 'f'}, OAuthenticator.parse_authorization(authorization))
54
- end
55
- end
56
- end
57
-
58
- it "handles commas inside quoted values" do
59
- # note that this is invalid according to the spec; commas should be %-encoded, but this is accepted in
60
- # the interests of robustness and consistency (other characters are accepted when they should really be
61
- # escaped).
62
- header_with_commas = 'OAuth oauth_consumer_key="a,bcd", oauth_nonce="o,LKtec51GQy", oauth_signature="efgh%2Cmnop"'
63
- assert_equal({'oauth_consumer_key' => "a,bcd", 'oauth_nonce' => "o,LKtec51GQy", 'oauth_signature' => "efgh,mnop"},
64
- OAuthenticator.parse_authorization(header_with_commas))
65
- end
66
-
67
- it "raises ParseError on input without a comma between key/value pairs" do
68
- assert_raises(OAuthenticator::ParseError) do
69
- OAuthenticator.parse_authorization(%q(OAuth oauth_consumer_key="k" oauth_nonce="n"))
70
- end
71
- end
72
-
73
- it "raises ParseError on malformed input" do
74
- assert_raises(OAuthenticator::ParseError) { OAuthenticator.parse_authorization(%q(OAuth huh=/)) }
75
- end
76
-
77
- it "raises ParseError when the header does not start with 'OAuth '" do
78
- assert_raises(OAuthenticator::ParseError) { OAuthenticator.parse_authorization(%q(FooAuth foo="baz")) }
79
- end
80
-
81
- it "raises DuplicatedParameter when the header contains duplicated parameters" do
82
- assert_raises(OAuthenticator::DuplicatedParameters) do
83
- OAuthenticator.parse_authorization(%q(OAuth oauth_nonce="a", oauth_nonce="b"))
84
- end
85
- end
86
- end