/
test_client_helper.rb
147 lines (138 loc) · 4.3 KB
/
test_client_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require File.expand_path('../../test_helper', __FILE__)
require 'oauth/client'
class ClientHelperTest < Minitest::Test
def setup
@consumer=OAuth::Consumer.new(
'consumer_key_86cad9', '5888bf0345e5d237',
{
:site=>"http://blabla.bla",
:proxy=>"http://user:password@proxy.bla:8080",
:request_token_path=>"/oauth/example/request_token.php",
:access_token_path=>"/oauth/example/access_token.php",
:authorize_path=>"/oauth/example/authorize.php",
:scheme=>:header,
:http_method=>:get
})
end
def test_oauth_parameters_allow_empty_params_default
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_version"=>"1.0"
}
assert_equal expected, helper.oauth_parameters
end
end
end
def test_oauth_parameters_allow_empty_params_true
input = true
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer,
:allow_empty_params => input
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_body_hash"=>nil,
"oauth_callback"=>nil,
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_token"=>"",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_verifier"=>nil,
"oauth_version"=>"1.0",
"oauth_session_handle"=>nil
}
assert_equal expected, helper.oauth_parameters
end
end
end
def test_oauth_parameters_allow_empty_params_false
input = false
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer,
:allow_empty_params => input
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_version"=>"1.0"
}
assert_equal expected, helper.oauth_parameters
end
end
end
def test_oauth_parameters_allow_empty_params_only_oauth_token_as_string
input = 'oauth_token'
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer,
:allow_empty_params => input
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_token"=>"",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_version"=>"1.0",
}
assert_equal expected, helper.oauth_parameters
end
end
end
def test_oauth_parameters_allow_empty_params_only_oauth_token_as_array
input = ['oauth_token']
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer,
:allow_empty_params => input
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_token"=>"",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_version"=>"1.0",
}
assert_equal expected, helper.oauth_parameters
end
end
end
def test_oauth_parameters_allow_empty_params_oauth_token_and_oauth_session_handle
input = ['oauth_token', 'oauth_session_handle']
helper = OAuth::Client::Helper.new(nil, {
:consumer => @consumer,
:allow_empty_params => input
})
helper.stub :timestamp, '0' do
helper.stub :nonce, 'nonce' do
expected = {
"oauth_consumer_key"=>"consumer_key_86cad9",
"oauth_token"=>"",
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>"0",
"oauth_nonce"=>"nonce",
"oauth_version"=>"1.0",
"oauth_session_handle"=>nil
}
assert_equal expected, helper.oauth_parameters
end
end
end
end