oauthenticator 1.3.5 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # config methods for testing OAuthenticator. simple
4
- module OAuthenticatorTestConfigMethods
5
- class << self
6
- # a set of nonces
7
- define_method(:nonces) { @nonces ||= Set.new }
8
- # a Hash keyed by consumer keys with values of consumer secrets
9
- define_method(:consumer_secrets) { @consumer_secrets ||= {} }
10
- # a Hash keyed by tokens with values of token secrets
11
- define_method(:token_secrets) { @token_secrets ||= {} }
12
- # a Hash keyed by tokens with values of consumer keys
13
- define_method(:token_consumers) { @token_consumers ||= {} }
14
- end
15
-
16
- def nonce_used?
17
- OAuthenticatorTestConfigMethods.nonces.include?(nonce)
18
- end
19
-
20
- def use_nonce!
21
- if OAuthenticatorTestConfigMethods.nonces.include?(nonce)
22
- # checking the same thing as #nonce_used? lets #nonce_used? be overridden to return false and things still work
23
- raise OAuthenticator::NonceUsedError
24
- else
25
- OAuthenticatorTestConfigMethods.nonces << nonce
26
- end
27
- end
28
-
29
- def timestamp_valid_period
30
- 10
31
- end
32
-
33
- def allowed_signature_methods
34
- %w(HMAC-SHA1 RSA-SHA1 PLAINTEXT)
35
- end
36
-
37
- def consumer_secret
38
- OAuthenticatorTestConfigMethods.consumer_secrets[consumer_key]
39
- end
40
-
41
- def token_secret
42
- OAuthenticatorTestConfigMethods.token_secrets[token]
43
- end
44
-
45
- def token_belongs_to_consumer?
46
- OAuthenticatorTestConfigMethods.token_consumers[token] == consumer_key
47
- end
48
- end
49
-
50
- module TestHelperMethods
51
- def self.let(name, &block)
52
- define_method(name) { |*args| (@lets ||= {}).key?(name) ? @lets[name] : (@lets[name] = instance_eval(*args, &block)) }
53
- end
54
-
55
- let(:simpleapp) { proc { |env| [200, {'Content-Type' => 'text/plain; charset=UTF-8'}, ['☺']] } }
56
- let(:oapp) { OAuthenticator::RackAuthenticator.new(simpleapp, :config_methods => OAuthenticatorTestConfigMethods) }
57
-
58
- let(:consumer) do
59
- {:key => "test_client_app_key", :secret => "test_client_app_secret"}.tap do |consumer|
60
- OAuthenticatorTestConfigMethods.consumer_secrets[consumer[:key]] = consumer[:secret]
61
- end
62
- end
63
- let(:consumer_key) { consumer[:key] }
64
- let(:consumer_secret) { consumer[:secret] }
65
-
66
- let(:token_hash) do
67
- {:token => 'test_token', :secret => 'test_token_secret', :consumer_key => consumer_key}.tap do |hash|
68
- OAuthenticatorTestConfigMethods.token_secrets[hash[:token]] = hash[:secret]
69
- OAuthenticatorTestConfigMethods.token_consumers[hash[:token]] = hash[:consumer_key]
70
- end
71
- end
72
- let(:token) { token_hash[:token] }
73
- let(:token_secret) { token_hash[:secret] }
74
- end