signet 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +47 -36
- data/Gemfile +5 -4
- data/README.md +4 -5
- data/Rakefile +86 -37
- data/lib/signet.rb +17 -14
- data/lib/signet/errors.rb +4 -4
- data/lib/signet/oauth_1.rb +128 -153
- data/lib/signet/oauth_1/client.rb +309 -343
- data/lib/signet/oauth_1/credential.rb +40 -37
- data/lib/signet/oauth_1/server.rb +197 -203
- data/lib/signet/oauth_1/signature_methods/hmac_sha1.rb +11 -10
- data/lib/signet/oauth_1/signature_methods/plaintext.rb +8 -7
- data/lib/signet/oauth_1/signature_methods/rsa_sha1.rb +11 -11
- data/lib/signet/oauth_2.rb +41 -43
- data/lib/signet/oauth_2/client.rb +302 -313
- data/lib/signet/version.rb +2 -73
- data/signet.gemspec +37 -39
- data/spec/signet/oauth_1/client_spec.rb +313 -315
- data/spec/signet/oauth_1/credential_spec.rb +64 -56
- data/spec/signet/oauth_1/server_spec.rb +362 -362
- data/spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb +26 -26
- data/spec/signet/oauth_1/signature_methods/plaintext_spec.rb +28 -28
- data/spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb +34 -35
- data/spec/signet/oauth_1_spec.rb +527 -524
- data/spec/signet/oauth_2/client_spec.rb +612 -576
- data/spec/signet/oauth_2_spec.rb +88 -89
- data/spec/signet_spec.rb +41 -41
- data/spec/spec_helper.rb +7 -7
- data/spec/spec_helper_spec.rb +8 -8
- metadata +50 -43
- data/tasks/clobber.rake +0 -2
- data/tasks/gem.rake +0 -34
- data/tasks/git.rake +0 -40
- data/tasks/metrics.rake +0 -41
- data/tasks/spec.rake +0 -34
- data/tasks/wiki.rake +0 -38
- data/tasks/yard.rake +0 -21
@@ -11,51 +11,51 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
14
|
+
require "spec_helper"
|
15
|
+
require "signet"
|
16
|
+
require "signet/oauth_1"
|
17
|
+
require "signet/oauth_1/signature_methods/hmac_sha1"
|
18
18
|
|
19
19
|
describe Signet::OAuth1::HMACSHA1 do
|
20
|
-
it
|
20
|
+
it "should correctly generate a signature" do
|
21
21
|
method = "GET"
|
22
22
|
uri = "http://photos.example.net/photos"
|
23
23
|
parameters = {
|
24
|
-
"oauth_consumer_key"
|
25
|
-
"oauth_token"
|
24
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
25
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
26
26
|
"oauth_signature_method" => "HMAC-SHA1",
|
27
|
-
"oauth_timestamp"
|
28
|
-
"oauth_nonce"
|
29
|
-
"oauth_version"
|
30
|
-
"file"
|
31
|
-
"size"
|
27
|
+
"oauth_timestamp" => "1191242096",
|
28
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
29
|
+
"oauth_version" => "1.0",
|
30
|
+
"file" => "vacation.jpg",
|
31
|
+
"size" => "original"
|
32
32
|
}
|
33
33
|
client_credential_secret = "kd94hf93k423kf44"
|
34
34
|
token_credential_secret = "pfkkdhi9sl3r4s00"
|
35
|
-
base_string = Signet::OAuth1.generate_base_string
|
35
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
36
36
|
expect(Signet::OAuth1::HMACSHA1.generate_signature(
|
37
|
-
|
38
|
-
|
37
|
+
base_string, client_credential_secret, token_credential_secret
|
38
|
+
)).to eq "tR3+Ty81lMeYAr/Fid0kMTYa/WM="
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it "should correctly generate a signature" do
|
42
42
|
method = "GET"
|
43
43
|
uri = "http://photos.example.net/photos"
|
44
44
|
parameters = {
|
45
|
-
"oauth_consumer_key"
|
46
|
-
"oauth_token"
|
45
|
+
"oauth_consumer_key" => "www.example.com",
|
46
|
+
"oauth_token" => "4/QL2GT6b5uznYem1ZGH6v+-9mMvRL",
|
47
47
|
"oauth_signature_method" => "HMAC-SHA1",
|
48
|
-
"oauth_timestamp"
|
49
|
-
"oauth_nonce"
|
50
|
-
"oauth_version"
|
51
|
-
"file"
|
52
|
-
"size"
|
48
|
+
"oauth_timestamp" => "1191242096",
|
49
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
50
|
+
"oauth_version" => "1.0",
|
51
|
+
"file" => "vacation.jpg",
|
52
|
+
"size" => "original"
|
53
53
|
}
|
54
54
|
client_credential_secret = "Kv+o2XXL/9RxkQW3lO3QTVlH"
|
55
55
|
token_credential_secret = "QllSuL9eQ5FXFO1Z/HcgL4ON"
|
56
|
-
base_string = Signet::OAuth1.generate_base_string
|
56
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
57
57
|
expect(Signet::OAuth1::HMACSHA1.generate_signature(
|
58
|
-
|
59
|
-
|
58
|
+
base_string, client_credential_secret, token_credential_secret
|
59
|
+
)).to eq "G/nkdbmbpEA+6RD1Sc5uIefhFfQ="
|
60
60
|
end
|
61
61
|
end
|
@@ -11,51 +11,51 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
14
|
+
require "spec_helper"
|
15
|
+
require "signet"
|
16
|
+
require "signet/oauth_1"
|
17
|
+
require "signet/oauth_1/signature_methods/plaintext"
|
18
18
|
|
19
19
|
describe Signet::OAuth1::PLAINTEXT do
|
20
|
-
it
|
20
|
+
it "should correctly generate a signature" do
|
21
21
|
method = "GET"
|
22
22
|
uri = "http://photos.example.net/photos"
|
23
23
|
parameters = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
25
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
26
|
+
"oauth_signature_method" => "HMAC-SHA1",
|
27
|
+
"oauth_timestamp" => "1191242096",
|
28
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
29
|
+
"oauth_version" => "1.0",
|
30
|
+
"file" => "vacation.jpg",
|
31
|
+
"size" => "original"
|
32
32
|
}
|
33
33
|
client_credential_secret = "kd94hf93k423kf44"
|
34
34
|
token_credential_secret = "pfkkdhi9sl3r4s00"
|
35
|
-
base_string = Signet::OAuth1.generate_base_string
|
35
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
36
36
|
expect(Signet::OAuth1::PLAINTEXT.generate_signature(
|
37
|
-
|
38
|
-
|
37
|
+
base_string, client_credential_secret, token_credential_secret
|
38
|
+
)).to eq "kd94hf93k423kf44%26pfkkdhi9sl3r4s00"
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it "should correctly generate a signature" do
|
42
42
|
method = "GET"
|
43
43
|
uri = "http://photos.example.net/photos"
|
44
44
|
parameters = {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
"oauth_consumer_key" => "www.example.com",
|
46
|
+
"oauth_token" => "4/QL2GT6b5uznYem1ZGH6v+-9mMvRL",
|
47
|
+
"oauth_signature_method" => "HMAC-SHA1",
|
48
|
+
"oauth_timestamp" => "1191242096",
|
49
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
50
|
+
"oauth_version" => "1.0",
|
51
|
+
"file" => "vacation.jpg",
|
52
|
+
"size" => "original"
|
53
53
|
}
|
54
54
|
client_credential_secret = "Kv+o2XXL/9RxkQW3lO3QTVlH"
|
55
55
|
token_credential_secret = "QllSuL9eQ5FXFO1Z/HcgL4ON"
|
56
|
-
base_string = Signet::OAuth1.generate_base_string
|
56
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
57
57
|
expect(Signet::OAuth1::PLAINTEXT.generate_signature(
|
58
|
-
|
59
|
-
|
58
|
+
base_string, client_credential_secret, token_credential_secret
|
59
|
+
)).to eq "Kv%252Bo2XXL%252F9RxkQW3lO3QTVlH%26QllSuL9eQ5FXFO1Z%252FHcgL4ON"
|
60
60
|
end
|
61
61
|
end
|
@@ -11,21 +11,21 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
14
|
+
require "spec_helper"
|
15
|
+
require "signet"
|
16
|
+
require "signet/oauth_1"
|
17
|
+
require "signet/oauth_1/signature_methods/rsa_sha1"
|
18
18
|
|
19
19
|
describe Signet::OAuth1::RSASHA1 do
|
20
|
-
it
|
20
|
+
it "should correctly generate a signature" do
|
21
21
|
method = "GET"
|
22
22
|
uri = "http://term.ie/oauth/example/request_token.php"
|
23
23
|
parameters = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
"oauth_consumer_key" => "key",
|
25
|
+
"oauth_signature_method" => "RSA-SHA1",
|
26
|
+
"oauth_timestamp" => "1377815426",
|
27
|
+
"oauth_nonce" => "c3839c47cb204a20e042b11a5cc9f971",
|
28
|
+
"oauth_version" => "1.0"
|
29
29
|
}
|
30
30
|
client_credential_secret = "-----BEGIN PRIVATE KEY-----
|
31
31
|
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
|
@@ -44,26 +44,26 @@ AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
|
|
44
44
|
Lw03eHTNQghS0A==
|
45
45
|
-----END PRIVATE KEY-----"
|
46
46
|
token_credential_secret = "pfkkdhi9sl3r4s00"
|
47
|
-
base_string = Signet::OAuth1.generate_base_string
|
47
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
48
48
|
|
49
49
|
expect(Signet::OAuth1::RSASHA1.generate_signature(
|
50
|
-
|
51
|
-
|
50
|
+
base_string, client_credential_secret, token_credential_secret
|
51
|
+
)).to eq "P72T4RS8dVBneQPJSY71D3iLEjge2tiivxEasPVoaoDldDgPdwpQfhS1q0th19jB3B3+9P6tBWjpWaVPxrNZe3ssBCiwS/EmXZ/6VCJGU3YoDHMtz+0jCd36NjHj5I6TpLVQ8/rtfy6+EzpdUMz7ydnhKXYqJFPOWnNv8HM1W7I="
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe Signet::OAuth1::RSASHA1 do
|
56
|
-
it
|
56
|
+
it "should correctly generate a signature" do
|
57
57
|
method = "GET"
|
58
58
|
uri = "http://photos.example.net/photos"
|
59
59
|
parameters = {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
61
|
+
"oauth_signature_method" => "RSA-SHA1",
|
62
|
+
"oauth_timestamp" => "1196666512",
|
63
|
+
"oauth_nonce" => "13917289812797014437",
|
64
|
+
"oauth_version" => "1.0",
|
65
|
+
"file" => "vacaction.jpg",
|
66
|
+
"size" => "original"
|
67
67
|
}
|
68
68
|
client_credential_secret = "-----BEGIN PRIVATE KEY-----
|
69
69
|
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
|
@@ -82,24 +82,24 @@ AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
|
|
82
82
|
Lw03eHTNQghS0A==
|
83
83
|
-----END PRIVATE KEY-----"
|
84
84
|
token_credential_secret = "pfkkdhi9sl3r4s00"
|
85
|
-
base_string = Signet::OAuth1.generate_base_string
|
85
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
86
86
|
|
87
87
|
expect(Signet::OAuth1::RSASHA1.generate_signature(
|
88
|
-
|
89
|
-
|
88
|
+
base_string, client_credential_secret, token_credential_secret
|
89
|
+
)).to eq "jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE="
|
90
90
|
end
|
91
91
|
|
92
92
|
|
93
|
-
it
|
93
|
+
it "should correctly generate a signature" do
|
94
94
|
method = "GET"
|
95
95
|
uri = "http://term.ie/oauth/example/access_token.php"
|
96
96
|
parameters = {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
"oauth_consumer_key" => "key",
|
98
|
+
"oauth_token" => "requestkey",
|
99
|
+
"oauth_signature_method" => "RSA-SHA1",
|
100
|
+
"oauth_timestamp" => "1377815426",
|
101
|
+
"oauth_nonce" => "8ae9ac8192dd3cd7372e0324bf879602",
|
102
|
+
"oauth_version" => "1.0"
|
103
103
|
}
|
104
104
|
client_credential_secret = "-----BEGIN PRIVATE KEY-----
|
105
105
|
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
|
@@ -118,10 +118,9 @@ AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
|
|
118
118
|
Lw03eHTNQghS0A==
|
119
119
|
-----END PRIVATE KEY-----"
|
120
120
|
token_credential_secret = "QllSuL9eQ5FXFO1Z/HcgL4ON"
|
121
|
-
base_string = Signet::OAuth1.generate_base_string
|
121
|
+
base_string = Signet::OAuth1.generate_base_string method, uri, parameters
|
122
122
|
expect(Signet::OAuth1::RSASHA1.generate_signature(
|
123
|
-
|
124
|
-
|
123
|
+
base_string, client_credential_secret, token_credential_secret
|
124
|
+
)).to eq "Q1O7Ovi0jdacl/OTJoH3MAyOO/9H/tTXmoJzP/YqiKEJ+/wfShXo1RXX0xmlcjDR1XYxB1RMgHkFWQYYwz1qGCUhkXlH1c/to2qxPksptfPHRe7PJTxRClrdqLFOlhN7w2kO7tHVCeEp8IJIKON9q7cdXroTP7ctPPS+Q883SS0="
|
125
125
|
end
|
126
|
-
|
127
126
|
end
|
data/spec/signet/oauth_1_spec.rb
CHANGED
@@ -11,64 +11,67 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
14
|
+
require "spec_helper"
|
15
|
+
require "signet/oauth_1"
|
16
|
+
require "signet/oauth_1/client"
|
17
|
+
require "signet/oauth_1/credential"
|
18
18
|
|
19
19
|
describe Signet::OAuth1 do
|
20
|
-
it
|
20
|
+
it "should correctly normalize parameters" do
|
21
21
|
parameters = [
|
22
|
-
[
|
22
|
+
%w[a 1],
|
23
23
|
["c", "hi there"],
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
24
|
+
%w[f 25],
|
25
|
+
%w[f 50],
|
26
|
+
%w[f a],
|
27
|
+
%w[z p],
|
28
|
+
%w[z t]
|
29
29
|
]
|
30
30
|
expect(Signet::OAuth1.normalize_parameters(parameters)).to eq(
|
31
|
-
|
31
|
+
"a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t"
|
32
|
+
)
|
32
33
|
end
|
33
34
|
|
34
|
-
it
|
35
|
+
it "should correctly normalize parameters" do
|
35
36
|
parameters = [
|
36
37
|
["b5", "=%3D"],
|
37
|
-
[
|
38
|
+
%w[a3 a],
|
38
39
|
["c@", ""],
|
39
40
|
["a2", "r b"],
|
40
|
-
[
|
41
|
-
[
|
41
|
+
%w[oauth_consumer_key 9djdj82h48djs9d2],
|
42
|
+
%w[oauth_token kkk9d7dh3k39sjv7],
|
42
43
|
["oauth_signature_method", "HMAC-SHA1"],
|
43
|
-
[
|
44
|
-
[
|
44
|
+
%w[oauth_timestamp 137131201],
|
45
|
+
%w[oauth_nonce 7d8f3e4a],
|
45
46
|
["c2", ""],
|
46
47
|
["a3", "2 q"]
|
47
48
|
]
|
48
49
|
expect(Signet::OAuth1.normalize_parameters(parameters)).to eq(
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
"a2=r%20b&a3=2%20q&a3=a&b5=%3D%253D&c%40=&c2=&oauth_consumer_key=9dj" \
|
51
|
+
"dj82h48djs9d2&oauth_nonce=7d8f3e4a&oauth_signature_method=HMAC-SHA1" \
|
52
|
+
"&oauth_timestamp=137131201&oauth_token=kkk9d7dh3k39sjv7"
|
53
|
+
)
|
52
54
|
end
|
53
55
|
|
54
56
|
it 'should exclude the "oauth_signature" parameter when normalizing' do
|
55
57
|
parameters = [
|
56
|
-
[
|
57
|
-
[
|
58
|
-
[
|
59
|
-
[
|
58
|
+
%w[a 1],
|
59
|
+
%w[b 2],
|
60
|
+
%w[c 3],
|
61
|
+
%w[oauth_signature dpf43f3p2l4k3l03]
|
60
62
|
]
|
61
63
|
expect(Signet::OAuth1.normalize_parameters(parameters)).to eq(
|
62
|
-
"a=1&b=2&c=3"
|
64
|
+
"a=1&b=2&c=3"
|
65
|
+
)
|
63
66
|
end
|
64
67
|
|
65
|
-
it
|
68
|
+
it "should raise an error if normalizing parameters with bogus values" do
|
66
69
|
expect(lambda do
|
67
|
-
Signet::OAuth1.normalize_parameters
|
70
|
+
Signet::OAuth1.normalize_parameters 42
|
68
71
|
end).to raise_error(TypeError)
|
69
72
|
end
|
70
73
|
|
71
|
-
it
|
74
|
+
it "should raise an error if generating a base string with bogus values" do
|
72
75
|
expect(lambda do
|
73
76
|
Signet::OAuth1.generate_base_string(
|
74
77
|
"GET", "http://photos.example.net/photos", 42
|
@@ -76,25 +79,25 @@ describe Signet::OAuth1 do
|
|
76
79
|
end).to raise_error(TypeError)
|
77
80
|
end
|
78
81
|
|
79
|
-
it
|
82
|
+
it "should correctly generate a base string" do
|
80
83
|
method = "GET"
|
81
84
|
uri = "http://photos.example.net/photos"
|
82
85
|
parameters = {
|
83
|
-
"oauth_consumer_key"
|
84
|
-
"oauth_token"
|
86
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
87
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
85
88
|
"oauth_signature_method" => "HMAC-SHA1",
|
86
|
-
"oauth_timestamp"
|
87
|
-
"oauth_nonce"
|
88
|
-
"oauth_version"
|
89
|
-
"file"
|
90
|
-
"size"
|
89
|
+
"oauth_timestamp" => "1191242096",
|
90
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
91
|
+
"oauth_version" => "1.0",
|
92
|
+
"file" => "vacation.jpg",
|
93
|
+
"size" => "original"
|
91
94
|
}
|
92
95
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
93
|
-
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
94
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
95
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
96
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
97
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
96
|
+
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
97
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
98
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
99
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
100
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
98
101
|
"oauth_version%3D1.0%26size%3Doriginal"
|
99
102
|
)
|
100
103
|
end
|
@@ -103,22 +106,22 @@ describe Signet::OAuth1 do
|
|
103
106
|
method = "GET"
|
104
107
|
uri = "http://photos.example.net/https%3A%2F%2Fwww.example.com"
|
105
108
|
parameters = {
|
106
|
-
"oauth_consumer_key"
|
107
|
-
"oauth_token"
|
109
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
110
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
108
111
|
"oauth_signature_method" => "HMAC-SHA1",
|
109
|
-
"oauth_timestamp"
|
110
|
-
"oauth_nonce"
|
111
|
-
"oauth_version"
|
112
|
-
"file"
|
113
|
-
"size"
|
112
|
+
"oauth_timestamp" => "1191242096",
|
113
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
114
|
+
"oauth_version" => "1.0",
|
115
|
+
"file" => "vacation.jpg",
|
116
|
+
"size" => "original"
|
114
117
|
}
|
115
118
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
116
|
-
"GET&http%3A%2F%2Fphotos.example.net%2F"
|
117
|
-
"https%253A%252F%252Fwww.example.com&file%3Dvacation.jpg%26"
|
118
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
119
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
120
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
121
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
119
|
+
"GET&http%3A%2F%2Fphotos.example.net%2F" \
|
120
|
+
"https%253A%252F%252Fwww.example.com&file%3Dvacation.jpg%26" \
|
121
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
122
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
123
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
124
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
122
125
|
"oauth_version%3D1.0%26size%3Doriginal"
|
123
126
|
)
|
124
127
|
end
|
@@ -127,327 +130,327 @@ describe Signet::OAuth1 do
|
|
127
130
|
method = "GET"
|
128
131
|
uri = "http://example.com/r%20v/X?id=123"
|
129
132
|
parameters = {
|
130
|
-
"oauth_consumer_key"
|
131
|
-
"oauth_token"
|
133
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
134
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
132
135
|
"oauth_signature_method" => "HMAC-SHA1",
|
133
|
-
"oauth_timestamp"
|
134
|
-
"oauth_nonce"
|
135
|
-
"oauth_version"
|
136
|
+
"oauth_timestamp" => "1191242096",
|
137
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
138
|
+
"oauth_version" => "1.0"
|
136
139
|
}
|
137
140
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
138
|
-
"GET&http%3A%2F%2Fexample.com%2Fr%2520v%2FX&"
|
139
|
-
"id%3D123%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
140
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
141
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
142
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
141
|
+
"GET&http%3A%2F%2Fexample.com%2Fr%2520v%2FX&" \
|
142
|
+
"id%3D123%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
143
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
144
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
145
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
143
146
|
"oauth_version%3D1.0"
|
144
147
|
)
|
145
148
|
end
|
146
149
|
|
147
|
-
it
|
150
|
+
it "should correctly generate a base string when port 8080 is specified" do
|
148
151
|
method = "GET"
|
149
152
|
uri = "http://www.example.net:8080/?q=1"
|
150
153
|
parameters = {
|
151
|
-
"oauth_consumer_key"
|
152
|
-
"oauth_token"
|
154
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
155
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
153
156
|
"oauth_signature_method" => "HMAC-SHA1",
|
154
|
-
"oauth_timestamp"
|
155
|
-
"oauth_nonce"
|
156
|
-
"oauth_version"
|
157
|
+
"oauth_timestamp" => "1191242096",
|
158
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
159
|
+
"oauth_version" => "1.0"
|
157
160
|
}
|
158
161
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
159
|
-
"GET&http%3A%2F%2Fwww.example.net%3A8080%2F&"
|
160
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
161
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
162
|
-
"oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26"
|
162
|
+
"GET&http%3A%2F%2Fwww.example.net%3A8080%2F&" \
|
163
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
164
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
165
|
+
"oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26" \
|
163
166
|
"oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26q%3D1"
|
164
167
|
)
|
165
168
|
end
|
166
169
|
|
167
|
-
it
|
170
|
+
it "should correctly generate a base string when port 80 is specified" do
|
168
171
|
method = "GET"
|
169
172
|
uri = "http://photos.example.net:80/photos"
|
170
173
|
parameters = {
|
171
|
-
"oauth_consumer_key"
|
172
|
-
"oauth_token"
|
174
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
175
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
173
176
|
"oauth_signature_method" => "HMAC-SHA1",
|
174
|
-
"oauth_timestamp"
|
175
|
-
"oauth_nonce"
|
176
|
-
"oauth_version"
|
177
|
-
"file"
|
178
|
-
"size"
|
177
|
+
"oauth_timestamp" => "1191242096",
|
178
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
179
|
+
"oauth_version" => "1.0",
|
180
|
+
"file" => "vacation.jpg",
|
181
|
+
"size" => "original"
|
179
182
|
}
|
180
183
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
181
|
-
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
182
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
183
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
184
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
185
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
184
|
+
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
185
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
186
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
187
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
188
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
186
189
|
"oauth_version%3D1.0%26size%3Doriginal"
|
187
190
|
)
|
188
191
|
end
|
189
192
|
|
190
|
-
it
|
193
|
+
it "should correctly generate a base string when port 443 is specified" do
|
191
194
|
method = "GET"
|
192
195
|
uri = "https://photos.example.net:443/photos"
|
193
196
|
parameters = {
|
194
|
-
"oauth_consumer_key"
|
195
|
-
"oauth_token"
|
197
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
198
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
196
199
|
"oauth_signature_method" => "HMAC-SHA1",
|
197
|
-
"oauth_timestamp"
|
198
|
-
"oauth_nonce"
|
199
|
-
"oauth_version"
|
200
|
-
"file"
|
201
|
-
"size"
|
200
|
+
"oauth_timestamp" => "1191242096",
|
201
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
202
|
+
"oauth_version" => "1.0",
|
203
|
+
"file" => "vacation.jpg",
|
204
|
+
"size" => "original"
|
202
205
|
}
|
203
206
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
204
|
-
"GET&https%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
205
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
206
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
207
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
208
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
207
|
+
"GET&https%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
208
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
209
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
210
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
211
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
209
212
|
"oauth_version%3D1.0%26size%3Doriginal"
|
210
213
|
)
|
211
214
|
end
|
212
215
|
|
213
|
-
it
|
214
|
-
method =
|
216
|
+
it "should correctly generate a base signature with uppercase scheme" do
|
217
|
+
method = "GET"
|
215
218
|
uri =
|
216
219
|
"HTTP://photos.example.net/photos?file=vacation.jpg"
|
217
220
|
parameters = {
|
218
|
-
"oauth_consumer_key"
|
219
|
-
"oauth_token"
|
221
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
222
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
220
223
|
"oauth_signature_method" => "HMAC-SHA1",
|
221
|
-
"oauth_timestamp"
|
222
|
-
"oauth_nonce"
|
223
|
-
"oauth_version"
|
224
|
-
"size"
|
224
|
+
"oauth_timestamp" => "1191242096",
|
225
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
226
|
+
"oauth_version" => "1.0",
|
227
|
+
"size" => "original"
|
225
228
|
}
|
226
229
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
227
|
-
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
228
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
229
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
230
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
231
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
230
|
+
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
231
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
232
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
233
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
234
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
232
235
|
"oauth_version%3D1.0%26size%3Doriginal"
|
233
236
|
)
|
234
237
|
end
|
235
238
|
|
236
|
-
it
|
237
|
-
method =
|
239
|
+
it "should correctly generate a base signature with mixedcase authority" do
|
240
|
+
method = "GET"
|
238
241
|
uri =
|
239
242
|
"http://photos.eXaMpLe.NET/photos?file=vacation.jpg"
|
240
243
|
parameters = {
|
241
|
-
"oauth_consumer_key"
|
242
|
-
"oauth_token"
|
244
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
245
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
243
246
|
"oauth_signature_method" => "HMAC-SHA1",
|
244
|
-
"oauth_timestamp"
|
245
|
-
"oauth_nonce"
|
246
|
-
"oauth_version"
|
247
|
-
"size"
|
247
|
+
"oauth_timestamp" => "1191242096",
|
248
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
249
|
+
"oauth_version" => "1.0",
|
250
|
+
"size" => "original"
|
248
251
|
}
|
249
252
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
250
|
-
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
251
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
252
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
253
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
254
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
253
|
+
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
254
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
255
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
256
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
257
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
255
258
|
"oauth_version%3D1.0%26size%3Doriginal"
|
256
259
|
)
|
257
260
|
end
|
258
261
|
|
259
|
-
it
|
262
|
+
it "should correctly generate a base signature with a method symbol" do
|
260
263
|
method = :get
|
261
264
|
uri =
|
262
265
|
"http://photos.example.net/photos?file=vacation.jpg"
|
263
266
|
parameters = {
|
264
|
-
"oauth_consumer_key"
|
265
|
-
"oauth_token"
|
267
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
268
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
266
269
|
"oauth_signature_method" => "HMAC-SHA1",
|
267
|
-
"oauth_timestamp"
|
268
|
-
"oauth_nonce"
|
269
|
-
"oauth_version"
|
270
|
-
"size"
|
270
|
+
"oauth_timestamp" => "1191242096",
|
271
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
272
|
+
"oauth_version" => "1.0",
|
273
|
+
"size" => "original"
|
271
274
|
}
|
272
275
|
expect(Signet::OAuth1.generate_base_string(method, uri, parameters)).to eq(
|
273
|
-
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26"
|
274
|
-
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26"
|
275
|
-
"oauth_nonce%3Dkllo9940pd9333jh%26"
|
276
|
-
"oauth_signature_method%3DHMAC-SHA1%26"
|
277
|
-
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26"
|
276
|
+
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" \
|
277
|
+
"oauth_consumer_key%3Ddpf43f3p2l4k3l03%26" \
|
278
|
+
"oauth_nonce%3Dkllo9940pd9333jh%26" \
|
279
|
+
"oauth_signature_method%3DHMAC-SHA1%26" \
|
280
|
+
"oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26" \
|
278
281
|
"oauth_version%3D1.0%26size%3Doriginal"
|
279
282
|
)
|
280
283
|
end
|
281
284
|
|
282
|
-
it
|
285
|
+
it "should correctly generate an authorization header" do
|
283
286
|
parameters = [
|
284
|
-
[
|
285
|
-
[
|
287
|
+
%w[oauth_consumer_key 0685bd9184jfhq22],
|
288
|
+
%w[oauth_token ad180jjd733klru7],
|
286
289
|
["oauth_signature_method", "HMAC-SHA1"],
|
287
290
|
["oauth_signature", "wOJIO9A2W5mFwDgiDvZbTSMK/PY="],
|
288
|
-
[
|
289
|
-
[
|
291
|
+
%w[oauth_timestamp 137131200],
|
292
|
+
%w[oauth_nonce 4572616e48616d6d65724c61686176],
|
290
293
|
["oauth_version", "1.0"]
|
291
294
|
]
|
292
295
|
expect(Signet::OAuth1.generate_authorization_header(
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
end
|
305
|
-
|
306
|
-
it
|
307
|
-
|
296
|
+
parameters, "http://sp.example.com/"
|
297
|
+
)).to eq(
|
298
|
+
'OAuth realm="http://sp.example.com/", ' \
|
299
|
+
'oauth_consumer_key="0685bd9184jfhq22", ' \
|
300
|
+
'oauth_token="ad180jjd733klru7", ' \
|
301
|
+
'oauth_signature_method="HMAC-SHA1", ' \
|
302
|
+
'oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", ' \
|
303
|
+
'oauth_timestamp="137131200", ' \
|
304
|
+
'oauth_nonce="4572616e48616d6d65724c61686176", ' \
|
305
|
+
'oauth_version="1.0"'
|
306
|
+
)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should raise an error if generating an authorization header " \
|
310
|
+
"with bogus values" do
|
308
311
|
expect(lambda do
|
309
|
-
Signet::OAuth1.generate_authorization_header
|
312
|
+
Signet::OAuth1.generate_authorization_header 42
|
310
313
|
end).to raise_error(TypeError)
|
311
314
|
end
|
312
315
|
|
313
|
-
it
|
314
|
-
|
316
|
+
it "should raise an error if generating an authorization header " \
|
317
|
+
'with the "realm" parameter specified the wrong way' do
|
315
318
|
parameters = [
|
316
319
|
["realm", "http://sp.example.com/"],
|
317
|
-
[
|
318
|
-
[
|
320
|
+
%w[oauth_consumer_key 0685bd9184jfhq22],
|
321
|
+
%w[oauth_token ad180jjd733klru7],
|
319
322
|
["oauth_signature_method", "HMAC-SHA1"],
|
320
323
|
["oauth_signature", "wOJIO9A2W5mFwDgiDvZbTSMK/PY="],
|
321
|
-
[
|
322
|
-
[
|
324
|
+
%w[oauth_timestamp 137131200],
|
325
|
+
%w[oauth_nonce 4572616e48616d6d65724c61686176],
|
323
326
|
["oauth_version", "1.0"]
|
324
327
|
]
|
325
328
|
expect(lambda do
|
326
|
-
Signet::OAuth1.generate_authorization_header
|
329
|
+
Signet::OAuth1.generate_authorization_header parameters
|
327
330
|
end).to raise_error(ArgumentError)
|
328
331
|
end
|
329
332
|
|
330
|
-
it
|
333
|
+
it "should correctly parse an authorization header" do
|
331
334
|
parameters = Signet::OAuth1.parse_authorization_header(
|
332
|
-
'OAuth realm="http://sp.example.com/", '
|
333
|
-
'oauth_consumer_key="0685bd9184jfhq22", '
|
334
|
-
'oauth_token="ad180jjd733klru7", '
|
335
|
-
'oauth_signature_method="HMAC-SHA1", '
|
336
|
-
'oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", '
|
337
|
-
'oauth_timestamp="137131200", '
|
338
|
-
'oauth_nonce="4572616e48616d6d65724c61686176", '
|
335
|
+
'OAuth realm="http://sp.example.com/", ' \
|
336
|
+
'oauth_consumer_key="0685bd9184jfhq22", ' \
|
337
|
+
'oauth_token="ad180jjd733klru7", ' \
|
338
|
+
'oauth_signature_method="HMAC-SHA1", ' \
|
339
|
+
'oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", ' \
|
340
|
+
'oauth_timestamp="137131200", ' \
|
341
|
+
'oauth_nonce="4572616e48616d6d65724c61686176", ' \
|
339
342
|
'oauth_version="1.0"'
|
340
|
-
).
|
341
|
-
expect(parameters[
|
342
|
-
expect(parameters[
|
343
|
-
expect(parameters[
|
344
|
-
expect(parameters[
|
345
|
-
expect(parameters[
|
346
|
-
expect(parameters[
|
347
|
-
expect(parameters[
|
348
|
-
expect(parameters[
|
349
|
-
end
|
350
|
-
|
351
|
-
it
|
343
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
344
|
+
expect(parameters["realm"]).to eq "http://sp.example.com/"
|
345
|
+
expect(parameters["oauth_consumer_key"]).to eq "0685bd9184jfhq22"
|
346
|
+
expect(parameters["oauth_token"]).to eq "ad180jjd733klru7"
|
347
|
+
expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
|
348
|
+
expect(parameters["oauth_signature"]).to eq "wOJIO9A2W5mFwDgiDvZbTSMK/PY="
|
349
|
+
expect(parameters["oauth_timestamp"]).to eq "137131200"
|
350
|
+
expect(parameters["oauth_nonce"]).to eq "4572616e48616d6d65724c61686176"
|
351
|
+
expect(parameters["oauth_version"]).to eq "1.0"
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should not unescape a realm in an authorization header" do
|
352
355
|
parameters = Signet::OAuth1.parse_authorization_header(
|
353
|
-
'OAuth realm="http%3A%2F%2Fsp.example.com%2F", '
|
354
|
-
'domain="http%3A%2F%2Fsp.example.com%2F", '
|
355
|
-
'oauth_consumer_key="0685bd9184jfhq22", '
|
356
|
-
'oauth_token="ad180jjd733klru7", '
|
357
|
-
'oauth_signature_method="HMAC-SHA1", '
|
358
|
-
'oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", '
|
359
|
-
'oauth_timestamp="137131200", '
|
360
|
-
'oauth_nonce="4572616e48616d6d65724c61686176", '
|
356
|
+
'OAuth realm="http%3A%2F%2Fsp.example.com%2F", ' \
|
357
|
+
'domain="http%3A%2F%2Fsp.example.com%2F", ' \
|
358
|
+
'oauth_consumer_key="0685bd9184jfhq22", ' \
|
359
|
+
'oauth_token="ad180jjd733klru7", ' \
|
360
|
+
'oauth_signature_method="HMAC-SHA1", ' \
|
361
|
+
'oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", ' \
|
362
|
+
'oauth_timestamp="137131200", ' \
|
363
|
+
'oauth_nonce="4572616e48616d6d65724c61686176", ' \
|
361
364
|
'oauth_version="1.0"'
|
362
|
-
).
|
363
|
-
expect(parameters[
|
364
|
-
expect(parameters[
|
365
|
-
expect(parameters[
|
366
|
-
expect(parameters[
|
367
|
-
expect(parameters[
|
368
|
-
expect(parameters[
|
369
|
-
expect(parameters[
|
370
|
-
expect(parameters[
|
371
|
-
expect(parameters[
|
372
|
-
end
|
373
|
-
|
374
|
-
it
|
375
|
-
|
365
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
366
|
+
expect(parameters["realm"]).to eq "http%3A%2F%2Fsp.example.com%2F"
|
367
|
+
expect(parameters["domain"]).to eq "http://sp.example.com/"
|
368
|
+
expect(parameters["oauth_consumer_key"]).to eq "0685bd9184jfhq22"
|
369
|
+
expect(parameters["oauth_token"]).to eq "ad180jjd733klru7"
|
370
|
+
expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
|
371
|
+
expect(parameters["oauth_signature"]).to eq "wOJIO9A2W5mFwDgiDvZbTSMK/PY="
|
372
|
+
expect(parameters["oauth_timestamp"]).to eq "137131200"
|
373
|
+
expect(parameters["oauth_nonce"]).to eq "4572616e48616d6d65724c61686176"
|
374
|
+
expect(parameters["oauth_version"]).to eq "1.0"
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should raise an error if parsing an authorization header " \
|
378
|
+
"with bogus values" do
|
376
379
|
expect(lambda do
|
377
|
-
Signet::OAuth1.parse_authorization_header
|
380
|
+
Signet::OAuth1.parse_authorization_header 42
|
378
381
|
end).to raise_error(TypeError)
|
379
382
|
end
|
380
383
|
|
381
|
-
it
|
384
|
+
it "should raise an error if parsing a non-OAuth authorization header" do
|
382
385
|
expect(lambda do
|
383
386
|
Signet::OAuth1.parse_authorization_header(
|
384
|
-
|
387
|
+
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
|
385
388
|
)
|
386
389
|
end).to raise_error(Signet::ParseError)
|
387
390
|
end
|
388
391
|
|
389
|
-
it
|
392
|
+
it "should correctly parse a form encoded credential" do
|
390
393
|
credential = Signet::OAuth1.parse_form_encoded_credentials(
|
391
|
-
|
394
|
+
"oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"
|
392
395
|
)
|
393
|
-
expect(credential.key).to eq
|
394
|
-
expect(credential.secret).to eq
|
396
|
+
expect(credential.key).to eq "hh5s93j4hdidpola"
|
397
|
+
expect(credential.secret).to eq "hdhd0244k9j7ao03"
|
395
398
|
end
|
396
399
|
|
397
|
-
it
|
400
|
+
it "should correctly parse a form encoded credential" do
|
398
401
|
credential = Signet::OAuth1.parse_form_encoded_credentials(
|
399
|
-
|
400
|
-
|
402
|
+
"oauth_token=hdk48Djdsa&oauth_token_secret=xyz4992k83j47x0b&" \
|
403
|
+
"oauth_callback_confirmed=true"
|
401
404
|
)
|
402
|
-
expect(credential.key).to eq
|
403
|
-
expect(credential.secret).to eq
|
405
|
+
expect(credential.key).to eq "hdk48Djdsa"
|
406
|
+
expect(credential.secret).to eq "xyz4992k83j47x0b"
|
404
407
|
end
|
405
408
|
|
406
|
-
it
|
407
|
-
|
409
|
+
it "should raise an error if parsing a form encoded credential " \
|
410
|
+
"with bogus values" do
|
408
411
|
expect(lambda do
|
409
|
-
Signet::OAuth1.parse_form_encoded_credentials
|
412
|
+
Signet::OAuth1.parse_form_encoded_credentials 42
|
410
413
|
end).to raise_error(TypeError)
|
411
414
|
end
|
412
415
|
|
413
|
-
it
|
416
|
+
it "should correctly generate a signature for a set of parameters" do
|
414
417
|
method = :get
|
415
418
|
uri = "http://photos.example.net/photos"
|
416
|
-
client_credential_secret =
|
417
|
-
token_credential_secret =
|
419
|
+
client_credential_secret = "kd94hf93k423kf44"
|
420
|
+
token_credential_secret = "pfkkdhi9sl3r4s00"
|
418
421
|
parameters = {
|
419
|
-
"oauth_consumer_key"
|
420
|
-
"oauth_token"
|
422
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
423
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
421
424
|
"oauth_signature_method" => "HMAC-SHA1",
|
422
|
-
"oauth_timestamp"
|
423
|
-
"oauth_nonce"
|
424
|
-
"oauth_version"
|
425
|
-
"file"
|
426
|
-
"size"
|
425
|
+
"oauth_timestamp" => "1191242096",
|
426
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
427
|
+
"oauth_version" => "1.0",
|
428
|
+
"file" => "vacation.jpg",
|
429
|
+
"size" => "original"
|
427
430
|
}
|
428
431
|
expect(Signet::OAuth1.sign_parameters(
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
432
|
+
method,
|
433
|
+
uri,
|
434
|
+
parameters,
|
435
|
+
client_credential_secret,
|
436
|
+
token_credential_secret
|
437
|
+
)).to eq "tR3+Ty81lMeYAr/Fid0kMTYa/WM="
|
435
438
|
end
|
436
439
|
|
437
|
-
it
|
440
|
+
it "should raise an error when trying to sign with with unknown method" do
|
438
441
|
method = :get
|
439
442
|
uri = "http://photos.example.net/photos"
|
440
|
-
client_credential_secret =
|
441
|
-
token_credential_secret =
|
443
|
+
client_credential_secret = "kd94hf93k423kf44"
|
444
|
+
token_credential_secret = "pfkkdhi9sl3r4s00"
|
442
445
|
parameters = {
|
443
|
-
"oauth_consumer_key"
|
444
|
-
"oauth_token"
|
446
|
+
"oauth_consumer_key" => "dpf43f3p2l4k3l03",
|
447
|
+
"oauth_token" => "nnch734d00sl2jdk",
|
445
448
|
"oauth_signature_method" => "HMAC-BOGUS", # Unknown signature method
|
446
|
-
"oauth_timestamp"
|
447
|
-
"oauth_nonce"
|
448
|
-
"oauth_version"
|
449
|
-
"file"
|
450
|
-
"size"
|
449
|
+
"oauth_timestamp" => "1191242096",
|
450
|
+
"oauth_nonce" => "kllo9940pd9333jh",
|
451
|
+
"oauth_version" => "1.0",
|
452
|
+
"file" => "vacation.jpg",
|
453
|
+
"size" => "original"
|
451
454
|
}
|
452
455
|
expect(lambda do
|
453
456
|
Signet::OAuth1.sign_parameters(
|
@@ -460,548 +463,548 @@ describe Signet::OAuth1 do
|
|
460
463
|
end).to raise_error(NotImplementedError)
|
461
464
|
end
|
462
465
|
|
463
|
-
it
|
464
|
-
authorization_uri =
|
465
|
-
temporary_credential_key =
|
466
|
-
callback =
|
466
|
+
it "should correctly generate authorization URIs" do
|
467
|
+
authorization_uri = "http://photos.example.net/authorize"
|
468
|
+
temporary_credential_key = "hh5s93j4hdidpola"
|
469
|
+
callback = "http://printer.example.com/request_token_ready"
|
467
470
|
parsed_uri = Addressable::URI.parse(
|
468
|
-
|
471
|
+
Signet::OAuth1.generate_authorization_uri(
|
469
472
|
authorization_uri,
|
470
|
-
:
|
471
|
-
:callback
|
473
|
+
temporary_credential_key: temporary_credential_key,
|
474
|
+
callback: callback
|
472
475
|
)
|
473
476
|
)
|
474
|
-
expect(parsed_uri.query_values).to have_key(
|
475
|
-
expect(parsed_uri.query_values[
|
476
|
-
expect(parsed_uri.query_values).to have_key(
|
477
|
-
expect(parsed_uri.query_values[
|
477
|
+
expect(parsed_uri.query_values).to have_key("oauth_token")
|
478
|
+
expect(parsed_uri.query_values["oauth_token"]).to eq temporary_credential_key
|
479
|
+
expect(parsed_uri.query_values).to have_key("oauth_callback")
|
480
|
+
expect(parsed_uri.query_values["oauth_callback"]).to eq callback
|
478
481
|
end
|
479
482
|
end
|
480
483
|
|
481
|
-
describe Signet::OAuth1,
|
484
|
+
describe Signet::OAuth1, "when generating temporary credentials parameters" do
|
482
485
|
before do
|
483
|
-
@client_credential_key =
|
484
|
-
@callback =
|
485
|
-
@signature_method =
|
486
|
-
@scope =
|
487
|
-
@additional_parameters = [[
|
486
|
+
@client_credential_key = "dpf43f3p2l4k3l03"
|
487
|
+
@callback = "http://printer.example.com/request_token_ready"
|
488
|
+
@signature_method = "HMAC-SHA1"
|
489
|
+
@scope = "http://photos.example.com/full_access"
|
490
|
+
@additional_parameters = [["scope", @scope]]
|
488
491
|
@unsigned_parameters =
|
489
492
|
Signet::OAuth1.unsigned_temporary_credential_parameters(
|
490
|
-
:
|
491
|
-
:
|
492
|
-
:
|
493
|
-
:
|
494
|
-
).
|
493
|
+
client_credential_key: @client_credential_key,
|
494
|
+
callback: @callback,
|
495
|
+
signature_method: @signature_method,
|
496
|
+
additional_parameters: @additional_parameters
|
497
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
495
498
|
end
|
496
499
|
|
497
|
-
it
|
500
|
+
it "should raise an error if the client credential key is missing" do
|
498
501
|
expect(lambda do
|
499
502
|
Signet::OAuth1.unsigned_temporary_credential_parameters(
|
500
|
-
:
|
501
|
-
:
|
502
|
-
:
|
503
|
-
:
|
503
|
+
client_credential_key: nil,
|
504
|
+
callback: @callback,
|
505
|
+
signature_method: @signature_method,
|
506
|
+
additional_parameters: @additional_parameters
|
504
507
|
)
|
505
508
|
end).to raise_error(ArgumentError)
|
506
509
|
end
|
507
510
|
|
508
|
-
it
|
509
|
-
expect(@unsigned_parameters).to have_key(
|
510
|
-
expect(@unsigned_parameters[
|
511
|
+
it "should have the correct client credential key" do
|
512
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
513
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client_credential_key
|
511
514
|
end
|
512
515
|
|
513
|
-
it
|
514
|
-
expect(@unsigned_parameters).to have_key(
|
515
|
-
expect(@unsigned_parameters[
|
516
|
+
it "should have the correct signature method" do
|
517
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
518
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
516
519
|
end
|
517
520
|
|
518
|
-
it
|
521
|
+
it "should have a valid timestamp" do
|
519
522
|
# Verify that we have a timestamp, it's in the correct format and within
|
520
523
|
# a reasonable range of the current time.
|
521
|
-
expect(@unsigned_parameters).to have_key(
|
522
|
-
expect(@unsigned_parameters[
|
523
|
-
expect(@unsigned_parameters[
|
524
|
-
expect(@unsigned_parameters[
|
524
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
525
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
526
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
527
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
525
528
|
end
|
526
529
|
|
527
|
-
it
|
530
|
+
it "should have a valid nonce" do
|
528
531
|
# Verify that we have a nonce and that it has sufficient length for
|
529
532
|
# uniqueness.
|
530
|
-
expect(@unsigned_parameters).to have_key(
|
531
|
-
expect(@unsigned_parameters[
|
533
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
534
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
532
535
|
end
|
533
536
|
|
534
|
-
it
|
535
|
-
expect(@unsigned_parameters).to have_key(
|
536
|
-
expect(@unsigned_parameters[
|
537
|
+
it "should have the correct callback" do
|
538
|
+
expect(@unsigned_parameters).to have_key("oauth_callback")
|
539
|
+
expect(@unsigned_parameters["oauth_callback"]).to eq @callback
|
537
540
|
end
|
538
541
|
|
539
|
-
it
|
540
|
-
expect(@unsigned_parameters).to have_key(
|
541
|
-
expect(@unsigned_parameters[
|
542
|
+
it "should have the correct scope parameter" do
|
543
|
+
expect(@unsigned_parameters).to have_key("scope")
|
544
|
+
expect(@unsigned_parameters["scope"]).to eq @scope
|
542
545
|
end
|
543
546
|
|
544
|
-
it
|
545
|
-
expect(@unsigned_parameters).to have_key(
|
546
|
-
expect(@unsigned_parameters[
|
547
|
+
it "should have the correct OAuth version" do
|
548
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
549
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
547
550
|
end
|
548
551
|
end
|
549
552
|
|
550
|
-
describe Signet::OAuth1,
|
553
|
+
describe Signet::OAuth1, "when generating token credential parameters" do
|
551
554
|
before do
|
552
|
-
@client_credential_key =
|
553
|
-
@temporary_credential_key =
|
554
|
-
@verifier =
|
555
|
-
@signature_method =
|
555
|
+
@client_credential_key = "dpf43f3p2l4k3l03"
|
556
|
+
@temporary_credential_key = "hh5s93j4hdidpola"
|
557
|
+
@verifier = "473f82d3"
|
558
|
+
@signature_method = "HMAC-SHA1"
|
556
559
|
@unsigned_parameters =
|
557
560
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
558
|
-
:
|
559
|
-
:
|
560
|
-
:
|
561
|
-
:
|
562
|
-
).
|
561
|
+
client_credential_key: @client_credential_key,
|
562
|
+
temporary_credential_key: @temporary_credential_key,
|
563
|
+
signature_method: @signature_method,
|
564
|
+
verifier: @verifier
|
565
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
563
566
|
end
|
564
567
|
|
565
|
-
it
|
568
|
+
it "should raise an error if the client credential key is missing" do
|
566
569
|
expect(lambda do
|
567
570
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
568
|
-
:
|
569
|
-
:
|
570
|
-
:
|
571
|
-
:
|
571
|
+
client_credential_key: nil,
|
572
|
+
temporary_credential_key: @temporary_credential_key,
|
573
|
+
signature_method: @signature_method,
|
574
|
+
verifier: @verifier
|
572
575
|
)
|
573
576
|
end).to raise_error(ArgumentError)
|
574
577
|
end
|
575
578
|
|
576
|
-
it
|
579
|
+
it "should raise an error if the temporary credential key is missing" do
|
577
580
|
expect(lambda do
|
578
581
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
579
|
-
:
|
580
|
-
:
|
581
|
-
:
|
582
|
-
:
|
582
|
+
client_credential_key: @client_credential_key,
|
583
|
+
temporary_credential_key: nil,
|
584
|
+
signature_method: @signature_method,
|
585
|
+
verifier: @verifier
|
583
586
|
)
|
584
587
|
end).to raise_error(ArgumentError)
|
585
588
|
end
|
586
589
|
|
587
|
-
it
|
590
|
+
it "should raise an error if the verifier is missing" do
|
588
591
|
expect(lambda do
|
589
592
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
590
|
-
:
|
591
|
-
:
|
592
|
-
:
|
593
|
-
:
|
593
|
+
client_credential_key: @client_credential_key,
|
594
|
+
temporary_credential_key: @temporary_credential_key,
|
595
|
+
signature_method: @signature_method,
|
596
|
+
verifier: nil
|
594
597
|
)
|
595
598
|
end).to raise_error(ArgumentError)
|
596
599
|
end
|
597
600
|
|
598
|
-
it
|
599
|
-
expect(@unsigned_parameters).to have_key(
|
600
|
-
expect(@unsigned_parameters[
|
601
|
+
it "should have the correct client credential key" do
|
602
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
603
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client_credential_key
|
601
604
|
end
|
602
605
|
|
603
|
-
it
|
604
|
-
expect(@unsigned_parameters).to have_key(
|
605
|
-
expect(@unsigned_parameters[
|
606
|
+
it "should have the correct temporary credentials key" do
|
607
|
+
expect(@unsigned_parameters).to have_key("oauth_token")
|
608
|
+
expect(@unsigned_parameters["oauth_token"]).to eq @temporary_credential_key
|
606
609
|
end
|
607
610
|
|
608
|
-
it
|
609
|
-
expect(@unsigned_parameters).to have_key(
|
610
|
-
expect(@unsigned_parameters[
|
611
|
+
it "should have the correct signature method" do
|
612
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
613
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
611
614
|
end
|
612
615
|
|
613
|
-
it
|
616
|
+
it "should have a valid timestamp" do
|
614
617
|
# Verify that we have a timestamp, it's in the correct format and within
|
615
618
|
# a reasonable range of the current time.
|
616
|
-
expect(@unsigned_parameters).to have_key(
|
617
|
-
expect(@unsigned_parameters[
|
618
|
-
expect(@unsigned_parameters[
|
619
|
-
expect(@unsigned_parameters[
|
619
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
620
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
621
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
622
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
620
623
|
end
|
621
624
|
|
622
|
-
it
|
625
|
+
it "should have a valid nonce" do
|
623
626
|
# Verify that we have a nonce and that it has sufficient length for
|
624
627
|
# uniqueness.
|
625
|
-
expect(@unsigned_parameters).to have_key(
|
626
|
-
expect(@unsigned_parameters[
|
628
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
629
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
627
630
|
end
|
628
631
|
|
629
|
-
it
|
630
|
-
expect(@unsigned_parameters).to have_key(
|
631
|
-
expect(@unsigned_parameters[
|
632
|
+
it "should have the verifier" do
|
633
|
+
expect(@unsigned_parameters).to have_key("oauth_verifier")
|
634
|
+
expect(@unsigned_parameters["oauth_verifier"]).to eq @verifier
|
632
635
|
end
|
633
636
|
|
634
|
-
it
|
635
|
-
expect(@unsigned_parameters).to have_key(
|
636
|
-
expect(@unsigned_parameters[
|
637
|
+
it "should have the correct OAuth version" do
|
638
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
639
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
637
640
|
end
|
638
641
|
end
|
639
642
|
|
640
|
-
describe Signet::OAuth1,
|
643
|
+
describe Signet::OAuth1, "when generating protected resource parameters" do
|
641
644
|
before do
|
642
|
-
@client_credential_key =
|
643
|
-
@token_credential_key =
|
644
|
-
@signature_method =
|
645
|
+
@client_credential_key = "dpf43f3p2l4k3l03"
|
646
|
+
@token_credential_key = "nnch734d00sl2jdk"
|
647
|
+
@signature_method = "HMAC-SHA1"
|
645
648
|
@unsigned_parameters =
|
646
649
|
Signet::OAuth1.unsigned_resource_parameters(
|
647
|
-
:
|
648
|
-
:
|
649
|
-
:
|
650
|
-
).
|
650
|
+
client_credential_key: @client_credential_key,
|
651
|
+
token_credential_key: @token_credential_key,
|
652
|
+
signature_method: @signature_method
|
653
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
651
654
|
end
|
652
655
|
|
653
|
-
it
|
656
|
+
it "should raise an error if the client credential key is missing" do
|
654
657
|
expect(lambda do
|
655
658
|
Signet::OAuth1.unsigned_resource_parameters(
|
656
|
-
:
|
657
|
-
:
|
658
|
-
:
|
659
|
+
client_credential_key: nil,
|
660
|
+
token_credential_key: @token_credential_key,
|
661
|
+
signature_method: @signature_method
|
659
662
|
)
|
660
663
|
end).to raise_error(ArgumentError)
|
661
664
|
end
|
662
665
|
|
663
|
-
it
|
666
|
+
it "should raise an error if the token credential key is missing" do
|
664
667
|
expect(lambda do
|
665
668
|
Signet::OAuth1.unsigned_resource_parameters(
|
666
|
-
:
|
667
|
-
:
|
668
|
-
:
|
669
|
+
client_credential_key: @client_credential_key,
|
670
|
+
token_credential_key: nil,
|
671
|
+
signature_method: @signature_method
|
669
672
|
)
|
670
673
|
end).to raise_error(ArgumentError)
|
671
674
|
end
|
672
675
|
|
673
|
-
it
|
674
|
-
expect(@unsigned_parameters).to have_key(
|
675
|
-
expect(@unsigned_parameters[
|
676
|
+
it "should have the correct client credential key" do
|
677
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
678
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client_credential_key
|
676
679
|
end
|
677
680
|
|
678
|
-
it
|
679
|
-
expect(@unsigned_parameters).to have_key(
|
680
|
-
expect(@unsigned_parameters[
|
681
|
+
it "should have the correct token credentials key" do
|
682
|
+
expect(@unsigned_parameters).to have_key("oauth_token")
|
683
|
+
expect(@unsigned_parameters["oauth_token"]).to eq @token_credential_key
|
681
684
|
end
|
682
685
|
|
683
|
-
it
|
684
|
-
expect(@unsigned_parameters).to have_key(
|
685
|
-
expect(@unsigned_parameters[
|
686
|
+
it "should have the correct signature method" do
|
687
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
688
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
686
689
|
end
|
687
690
|
|
688
|
-
it
|
691
|
+
it "should have a valid timestamp" do
|
689
692
|
# Verify that we have a timestamp, it's in the correct format and within
|
690
693
|
# a reasonable range of the current time.
|
691
|
-
expect(@unsigned_parameters).to have_key(
|
692
|
-
expect(@unsigned_parameters[
|
693
|
-
expect(@unsigned_parameters[
|
694
|
-
expect(@unsigned_parameters[
|
694
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
695
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
696
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
697
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
695
698
|
end
|
696
699
|
|
697
|
-
it
|
700
|
+
it "should have a valid nonce" do
|
698
701
|
# Verify that we have a nonce and that it has sufficient length for
|
699
702
|
# uniqueness.
|
700
|
-
expect(@unsigned_parameters).to have_key(
|
701
|
-
expect(@unsigned_parameters[
|
703
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
704
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
702
705
|
end
|
703
706
|
|
704
|
-
it
|
705
|
-
expect(@unsigned_parameters).to have_key(
|
706
|
-
expect(@unsigned_parameters[
|
707
|
+
it "should have the correct OAuth version" do
|
708
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
709
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
707
710
|
end
|
708
711
|
end
|
709
712
|
|
710
|
-
describe Signet::OAuth1,
|
711
|
-
|
713
|
+
describe Signet::OAuth1, "when generating token credential parameters " \
|
714
|
+
"with Signet::OAuth1::Credential objects" do
|
712
715
|
before do
|
713
716
|
@client_credential = Signet::OAuth1::Credential.new(
|
714
|
-
|
717
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
715
718
|
)
|
716
719
|
@temporary_credential = Signet::OAuth1::Credential.new(
|
717
|
-
|
720
|
+
"hh5s93j4hdidpola", "hdhd0244k9j7ao03"
|
718
721
|
)
|
719
|
-
@verifier =
|
720
|
-
@signature_method =
|
722
|
+
@verifier = "473f82d3"
|
723
|
+
@signature_method = "HMAC-SHA1"
|
721
724
|
@unsigned_parameters =
|
722
725
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
723
|
-
:
|
724
|
-
:
|
725
|
-
:
|
726
|
-
:
|
727
|
-
).
|
726
|
+
client_credential: @client_credential,
|
727
|
+
temporary_credential: @temporary_credential,
|
728
|
+
signature_method: @signature_method,
|
729
|
+
verifier: @verifier
|
730
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
728
731
|
end
|
729
732
|
|
730
|
-
it
|
731
|
-
expect(@unsigned_parameters).to have_key(
|
732
|
-
expect(@unsigned_parameters[
|
733
|
+
it "should have the correct client credential key" do
|
734
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
735
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client_credential.key
|
733
736
|
end
|
734
737
|
|
735
|
-
it
|
736
|
-
expect(@unsigned_parameters).to have_key(
|
737
|
-
expect(@unsigned_parameters[
|
738
|
+
it "should have the correct temporary credentials key" do
|
739
|
+
expect(@unsigned_parameters).to have_key("oauth_token")
|
740
|
+
expect(@unsigned_parameters["oauth_token"]).to eq @temporary_credential.key
|
738
741
|
end
|
739
742
|
|
740
|
-
it
|
741
|
-
expect(@unsigned_parameters).to have_key(
|
742
|
-
expect(@unsigned_parameters[
|
743
|
+
it "should have the correct signature method" do
|
744
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
745
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
743
746
|
end
|
744
747
|
|
745
|
-
it
|
748
|
+
it "should have a valid timestamp" do
|
746
749
|
# Verify that we have a timestamp, it's in the correct format and within
|
747
750
|
# a reasonable range of the current time.
|
748
|
-
expect(@unsigned_parameters).to have_key(
|
749
|
-
expect(@unsigned_parameters[
|
750
|
-
expect(@unsigned_parameters[
|
751
|
-
expect(@unsigned_parameters[
|
751
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
752
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
753
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
754
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
752
755
|
end
|
753
756
|
|
754
|
-
it
|
757
|
+
it "should have a valid nonce" do
|
755
758
|
# Verify that we have a nonce and that it has sufficient length for
|
756
759
|
# uniqueness.
|
757
|
-
expect(@unsigned_parameters).to have_key(
|
758
|
-
expect(@unsigned_parameters[
|
760
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
761
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
759
762
|
end
|
760
763
|
|
761
|
-
it
|
762
|
-
expect(@unsigned_parameters).to have_key(
|
763
|
-
expect(@unsigned_parameters[
|
764
|
+
it "should have the correct OAuth version" do
|
765
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
766
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
764
767
|
end
|
765
768
|
end
|
766
769
|
|
767
|
-
describe Signet::OAuth1,
|
768
|
-
|
770
|
+
describe Signet::OAuth1, "when generating token credential parameters " \
|
771
|
+
"with a Signet::OAuth1::Client object" do
|
769
772
|
before do
|
770
773
|
@client = Signet::OAuth1::Client.new
|
771
774
|
@client.client_credential = Signet::OAuth1::Credential.new(
|
772
|
-
|
775
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
773
776
|
)
|
774
777
|
@client.temporary_credential = Signet::OAuth1::Credential.new(
|
775
|
-
|
778
|
+
"hh5s93j4hdidpola", "hdhd0244k9j7ao03"
|
776
779
|
)
|
777
|
-
@verifier =
|
778
|
-
@signature_method =
|
780
|
+
@verifier = "473f82d3"
|
781
|
+
@signature_method = "HMAC-SHA1"
|
779
782
|
@unsigned_parameters =
|
780
783
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
781
|
-
:
|
782
|
-
:
|
783
|
-
:
|
784
|
-
).
|
784
|
+
client: @client,
|
785
|
+
signature_method: @signature_method,
|
786
|
+
verifier: @verifier
|
787
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
785
788
|
end
|
786
789
|
|
787
|
-
it
|
788
|
-
expect(@unsigned_parameters).to have_key(
|
789
|
-
expect(@unsigned_parameters[
|
790
|
+
it "should have the correct client credential key" do
|
791
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
792
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client.client_credential_key
|
790
793
|
end
|
791
794
|
|
792
|
-
it
|
793
|
-
expect(@unsigned_parameters).to have_key(
|
794
|
-
expect(@unsigned_parameters[
|
795
|
+
it "should have the correct temporary credentials key" do
|
796
|
+
expect(@unsigned_parameters).to have_key("oauth_token")
|
797
|
+
expect(@unsigned_parameters["oauth_token"]).to eq @client.temporary_credential_key
|
795
798
|
end
|
796
799
|
|
797
|
-
it
|
798
|
-
expect(@unsigned_parameters).to have_key(
|
799
|
-
expect(@unsigned_parameters[
|
800
|
+
it "should have the correct signature method" do
|
801
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
802
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
800
803
|
end
|
801
804
|
|
802
|
-
it
|
805
|
+
it "should have a valid timestamp" do
|
803
806
|
# Verify that we have a timestamp, it's in the correct format and within
|
804
807
|
# a reasonable range of the current time.
|
805
|
-
expect(@unsigned_parameters).to have_key(
|
806
|
-
expect(@unsigned_parameters[
|
807
|
-
expect(@unsigned_parameters[
|
808
|
-
expect(@unsigned_parameters[
|
808
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
809
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
810
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
811
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
809
812
|
end
|
810
813
|
|
811
|
-
it
|
814
|
+
it "should have a valid nonce" do
|
812
815
|
# Verify that we have a nonce and that it has sufficient length for
|
813
816
|
# uniqueness.
|
814
|
-
expect(@unsigned_parameters).to have_key(
|
815
|
-
expect(@unsigned_parameters[
|
817
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
818
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
816
819
|
end
|
817
820
|
|
818
|
-
it
|
819
|
-
expect(@unsigned_parameters).to have_key(
|
820
|
-
expect(@unsigned_parameters[
|
821
|
+
it "should have the correct OAuth version" do
|
822
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
823
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
821
824
|
end
|
822
825
|
end
|
823
826
|
|
824
|
-
describe Signet::OAuth1,
|
825
|
-
|
827
|
+
describe Signet::OAuth1, "when generating token credential parameters " \
|
828
|
+
"with Signet::OAuth1::Credential objects" do
|
826
829
|
before do
|
827
830
|
@client_credential = Signet::OAuth1::Credential.new(
|
828
|
-
|
831
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
829
832
|
)
|
830
833
|
@temporary_credential = Signet::OAuth1::Credential.new(
|
831
|
-
|
834
|
+
"hh5s93j4hdidpola", "hdhd0244k9j7ao03"
|
832
835
|
)
|
833
|
-
@verifier =
|
834
|
-
@signature_method =
|
836
|
+
@verifier = "473f82d3"
|
837
|
+
@signature_method = "HMAC-SHA1"
|
835
838
|
@unsigned_parameters =
|
836
839
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
837
|
-
:
|
838
|
-
:
|
839
|
-
:
|
840
|
-
:
|
841
|
-
).
|
840
|
+
client_credential: @client_credential,
|
841
|
+
temporary_credential: @temporary_credential,
|
842
|
+
signature_method: @signature_method,
|
843
|
+
verifier: @verifier
|
844
|
+
).each_with_object({}) { |(k, v), h| h[k] = v; }
|
842
845
|
end
|
843
846
|
|
844
|
-
it
|
845
|
-
expect(@unsigned_parameters).to have_key(
|
846
|
-
expect(@unsigned_parameters[
|
847
|
+
it "should have the correct client credential key" do
|
848
|
+
expect(@unsigned_parameters).to have_key("oauth_consumer_key")
|
849
|
+
expect(@unsigned_parameters["oauth_consumer_key"]).to eq @client_credential.key
|
847
850
|
end
|
848
851
|
|
849
|
-
it
|
850
|
-
expect(@unsigned_parameters).to have_key(
|
851
|
-
expect(@unsigned_parameters[
|
852
|
+
it "should have the correct temporary credentials key" do
|
853
|
+
expect(@unsigned_parameters).to have_key("oauth_token")
|
854
|
+
expect(@unsigned_parameters["oauth_token"]).to eq @temporary_credential.key
|
852
855
|
end
|
853
856
|
|
854
|
-
it
|
855
|
-
expect(@unsigned_parameters).to have_key(
|
856
|
-
expect(@unsigned_parameters[
|
857
|
+
it "should have the correct signature method" do
|
858
|
+
expect(@unsigned_parameters).to have_key("oauth_signature_method")
|
859
|
+
expect(@unsigned_parameters["oauth_signature_method"]).to eq @signature_method
|
857
860
|
end
|
858
861
|
|
859
|
-
it
|
862
|
+
it "should have a valid timestamp" do
|
860
863
|
# Verify that we have a timestamp, it's in the correct format and within
|
861
864
|
# a reasonable range of the current time.
|
862
|
-
expect(@unsigned_parameters).to have_key(
|
863
|
-
expect(@unsigned_parameters[
|
864
|
-
expect(@unsigned_parameters[
|
865
|
-
expect(@unsigned_parameters[
|
865
|
+
expect(@unsigned_parameters).to have_key("oauth_timestamp")
|
866
|
+
expect(@unsigned_parameters["oauth_timestamp"]).to match(/^[0-9]+$/)
|
867
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be <= Time.now.to_i
|
868
|
+
expect(@unsigned_parameters["oauth_timestamp"].to_i).to be >= Time.now.to_i - 1
|
866
869
|
end
|
867
870
|
|
868
|
-
it
|
871
|
+
it "should have a valid nonce" do
|
869
872
|
# Verify that we have a nonce and that it has sufficient length for
|
870
873
|
# uniqueness.
|
871
|
-
expect(@unsigned_parameters).to have_key(
|
872
|
-
expect(@unsigned_parameters[
|
874
|
+
expect(@unsigned_parameters).to have_key("oauth_nonce")
|
875
|
+
expect(@unsigned_parameters["oauth_nonce"]).to match(/^[0-9a-zA-Z]{16,100}$/)
|
873
876
|
end
|
874
877
|
|
875
|
-
it
|
876
|
-
expect(@unsigned_parameters).to have_key(
|
877
|
-
expect(@unsigned_parameters[
|
878
|
+
it "should have the correct OAuth version" do
|
879
|
+
expect(@unsigned_parameters).to have_key("oauth_version")
|
880
|
+
expect(@unsigned_parameters["oauth_version"]).to eq "1.0"
|
878
881
|
end
|
879
882
|
end
|
880
883
|
|
881
|
-
describe Signet::OAuth1,
|
882
|
-
it
|
884
|
+
describe Signet::OAuth1, "extracting credential keys from options" do
|
885
|
+
it "should raise an error for bogus credentials" do
|
883
886
|
expect(lambda do
|
884
887
|
Signet::OAuth1.extract_credential_key_option(
|
885
|
-
:client,
|
888
|
+
:client, client_credential_key: true
|
886
889
|
)
|
887
890
|
end).to raise_error(TypeError)
|
888
891
|
end
|
889
892
|
|
890
|
-
it
|
893
|
+
it "should raise an error for bogus credentials" do
|
891
894
|
expect(lambda do
|
892
895
|
Signet::OAuth1.extract_credential_key_option(
|
893
|
-
:client,
|
896
|
+
:client, client_credential: 42
|
894
897
|
)
|
895
898
|
end).to raise_error(TypeError)
|
896
899
|
end
|
897
900
|
|
898
|
-
it
|
901
|
+
it "should raise an error for bogus credentials" do
|
899
902
|
expect(lambda do
|
900
903
|
Signet::OAuth1.extract_credential_key_option(
|
901
|
-
:client,
|
904
|
+
:client, client: 42
|
902
905
|
)
|
903
906
|
end).to raise_error(TypeError)
|
904
907
|
end
|
905
908
|
|
906
|
-
it
|
909
|
+
it "should return nil for missing credential key" do
|
907
910
|
expect(Signet::OAuth1.extract_credential_key_option(:client, {})).to eq nil
|
908
911
|
end
|
909
912
|
|
910
|
-
it
|
913
|
+
it "should find the correct credential key" do
|
911
914
|
expect(Signet::OAuth1.extract_credential_key_option(
|
912
|
-
|
913
|
-
|
915
|
+
:client, client_credential_key: "dpf43f3p2l4k3l03"
|
916
|
+
)).to eq "dpf43f3p2l4k3l03"
|
914
917
|
end
|
915
918
|
|
916
|
-
it
|
919
|
+
it "should find the correct credential key" do
|
917
920
|
expect(Signet::OAuth1.extract_credential_key_option(
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
921
|
+
:client, client_credential: Signet::OAuth1::Credential.new(
|
922
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
923
|
+
)
|
924
|
+
)).to eq "dpf43f3p2l4k3l03"
|
922
925
|
end
|
923
926
|
|
924
|
-
it
|
927
|
+
it "should find the correct credential key" do
|
925
928
|
client = Signet::OAuth1::Client.new
|
926
929
|
client.client_credential = Signet::OAuth1::Credential.new(
|
927
|
-
|
930
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
928
931
|
)
|
929
932
|
expect(Signet::OAuth1.extract_credential_key_option(
|
930
|
-
|
931
|
-
|
933
|
+
:client, client: client
|
934
|
+
)).to eq "dpf43f3p2l4k3l03"
|
932
935
|
end
|
933
936
|
|
934
|
-
it
|
937
|
+
it "should find the correct credential key" do
|
935
938
|
client = Signet::OAuth1::Client.new
|
936
939
|
client.temporary_credential = Signet::OAuth1::Credential.new(
|
937
|
-
|
940
|
+
"hh5s93j4hdidpola", "hdhd0244k9j7ao03"
|
938
941
|
)
|
939
942
|
expect(Signet::OAuth1.extract_credential_key_option(
|
940
|
-
|
941
|
-
|
943
|
+
:temporary, client: client
|
944
|
+
)).to eq "hh5s93j4hdidpola"
|
942
945
|
end
|
943
946
|
end
|
944
947
|
|
945
|
-
describe Signet::OAuth1,
|
946
|
-
it
|
948
|
+
describe Signet::OAuth1, "extracting credential secrets from options" do
|
949
|
+
it "should raise an error for bogus credentials" do
|
947
950
|
expect(lambda do
|
948
951
|
Signet::OAuth1.extract_credential_secret_option(
|
949
|
-
:client,
|
952
|
+
:client, client_credential_secret: true
|
950
953
|
)
|
951
954
|
end).to raise_error(TypeError)
|
952
955
|
end
|
953
956
|
|
954
|
-
it
|
957
|
+
it "should raise an error for bogus credentials" do
|
955
958
|
expect(lambda do
|
956
959
|
Signet::OAuth1.extract_credential_secret_option(
|
957
|
-
:client,
|
960
|
+
:client, client_credential: 42
|
958
961
|
)
|
959
962
|
end).to raise_error(TypeError)
|
960
963
|
end
|
961
964
|
|
962
|
-
it
|
965
|
+
it "should raise an error for bogus credentials" do
|
963
966
|
expect(lambda do
|
964
967
|
Signet::OAuth1.extract_credential_secret_option(
|
965
|
-
:client,
|
968
|
+
:client, client: 42
|
966
969
|
)
|
967
970
|
end).to raise_error(TypeError)
|
968
971
|
end
|
969
972
|
|
970
|
-
it
|
973
|
+
it "should raise an error for missing credential secret" do
|
971
974
|
expect(Signet::OAuth1.extract_credential_secret_option(:client, {})).to eq nil
|
972
975
|
end
|
973
976
|
|
974
|
-
it
|
977
|
+
it "should find the correct credential secret" do
|
975
978
|
expect(Signet::OAuth1.extract_credential_secret_option(
|
976
|
-
|
977
|
-
|
979
|
+
:client, client_credential_secret: "kd94hf93k423kf44"
|
980
|
+
)).to eq "kd94hf93k423kf44"
|
978
981
|
end
|
979
982
|
|
980
|
-
it
|
983
|
+
it "should find the correct credential secret" do
|
981
984
|
expect(Signet::OAuth1.extract_credential_secret_option(
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
985
|
+
:client, client_credential: Signet::OAuth1::Credential.new(
|
986
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
987
|
+
)
|
988
|
+
)).to eq "kd94hf93k423kf44"
|
986
989
|
end
|
987
990
|
|
988
|
-
it
|
991
|
+
it "should find the correct credential secret" do
|
989
992
|
client = Signet::OAuth1::Client.new
|
990
993
|
client.client_credential = Signet::OAuth1::Credential.new(
|
991
|
-
|
994
|
+
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
992
995
|
)
|
993
996
|
expect(Signet::OAuth1.extract_credential_secret_option(
|
994
|
-
|
995
|
-
|
997
|
+
:client, client: client
|
998
|
+
)).to eq "kd94hf93k423kf44"
|
996
999
|
end
|
997
1000
|
|
998
|
-
it
|
1001
|
+
it "should find the correct credential secret" do
|
999
1002
|
client = Signet::OAuth1::Client.new
|
1000
1003
|
client.temporary_credential = Signet::OAuth1::Credential.new(
|
1001
|
-
|
1004
|
+
"hh5s93j4hdidpola", "hdhd0244k9j7ao03"
|
1002
1005
|
)
|
1003
1006
|
expect(Signet::OAuth1.extract_credential_secret_option(
|
1004
|
-
|
1005
|
-
|
1007
|
+
:temporary, client: client
|
1008
|
+
)).to eq "hdhd0244k9j7ao03"
|
1006
1009
|
end
|
1007
1010
|
end
|