signet 0.13.2 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,194 +0,0 @@
1
- # Copyright (C) 2010 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require "spec_helper"
15
- require "signet/errors"
16
- require "signet/oauth_2"
17
-
18
- describe Signet::OAuth2 do
19
- # This behavior will almost certainly change in subsequent updates.
20
- describe "when parsing an Authorization header" do
21
- it "should correctly handle HTTP Basic auth-scheme" do
22
- parameters = Signet::OAuth2.parse_authorization_header(
23
- "Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW"
24
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
25
- expect(parameters["client_id"]).to eq "s6BhdRkqt3"
26
- expect(parameters["client_secret"]).to eq "gX1fBat3bV"
27
- end
28
-
29
- it "should correctly handle OAuth auth-scheme" do
30
- parameters = Signet::OAuth2.parse_authorization_header(
31
- "OAuth vF9dft4qmT"
32
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
33
- expect(parameters["access_token"]).to eq "vF9dft4qmT"
34
- end
35
-
36
- it "should correctly handle OAuth auth-scheme with realm" do
37
- parameters = Signet::OAuth2.parse_authorization_header(
38
- 'OAuth vF9dft4qmT, realm="http://sp.example.com/"'
39
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
40
- expect(parameters["access_token"]).to eq "vF9dft4qmT"
41
- expect(parameters["realm"]).to eq "http://sp.example.com/"
42
- end
43
-
44
- it "should correctly handle OAuth auth-scheme with multiple auth-params" do
45
- parameters = Signet::OAuth2.parse_authorization_header(
46
- 'OAuth vF9dft4qmT, first="one", second="two"'
47
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
48
- expect(parameters["access_token"]).to eq "vF9dft4qmT"
49
- expect(parameters["first"]).to eq "one"
50
- expect(parameters["second"]).to eq "two"
51
- end
52
-
53
- it "should liberally handle auth-params with single-quoted strings" do
54
- parameters = Signet::OAuth2.parse_authorization_header(
55
- "OAuth vF9dft4qmT, first='one', second='two'"
56
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
57
- expect(parameters["access_token"]).to eq "vF9dft4qmT"
58
- expect(parameters["first"]).to eq "one"
59
- expect(parameters["second"]).to eq "two"
60
- end
61
-
62
- it "should liberally handle auth-params with unquoted strings" do
63
- parameters = Signet::OAuth2.parse_authorization_header(
64
- "OAuth vF9dft4qmT, first=one, second=two"
65
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
66
- expect(parameters["access_token"]).to eq "vF9dft4qmT"
67
- expect(parameters["first"]).to eq "one"
68
- expect(parameters["second"]).to eq "two"
69
- end
70
-
71
- it "should not allow unquoted strings that do not match tchar" do
72
- expect(lambda do
73
- parameters = Signet::OAuth2.parse_authorization_header(
74
- "OAuth vF9dft4qmT, first=one:1"
75
- )
76
- end).to raise_error(Signet::ParseError)
77
- end
78
-
79
- it "should not parse non-OAuth auth-schemes" do
80
- expect(lambda do
81
- Signet::OAuth2.parse_authorization_header(
82
- 'AuthSub token="GD32CMCL25aZ-v____8B"'
83
- )
84
- end).to raise_error(Signet::ParseError)
85
- end
86
- end
87
-
88
- # This behavior will almost certainly change in subsequent updates.
89
- describe "when parsing a WWW-Authenticate header" do
90
- it "should correctly handle OAuth challenge with auth-params" do
91
- parameters = Signet::OAuth2.parse_www_authenticate_header(
92
- 'OAuth realm="http://sp.example.com/", error="expired_token", ' \
93
- 'error_description="The access token has expired."'
94
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
95
- expect(parameters["realm"]).to eq "http://sp.example.com/"
96
- expect(parameters["error"]).to eq "expired_token"
97
- expect(parameters["error_description"]).to eq "The access token has expired."
98
- end
99
-
100
- it "should liberally handle auth-params with single-quoted strings" do
101
- parameters = Signet::OAuth2.parse_www_authenticate_header(
102
- "OAuth realm='http://sp.example.com/', error='expired_token', " \
103
- "error_description='The access token has expired.'"
104
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
105
- expect(parameters["realm"]).to eq "http://sp.example.com/"
106
- expect(parameters["error"]).to eq "expired_token"
107
- expect(parameters["error_description"]).to eq "The access token has expired."
108
- end
109
-
110
- it "should liberally handle auth-params with token strings" do
111
- parameters = Signet::OAuth2.parse_www_authenticate_header(
112
- 'OAuth realm="http://sp.example.com/", error=expired_token, ' \
113
- 'error_description="The access token has expired."'
114
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
115
- expect(parameters["realm"]).to eq "http://sp.example.com/"
116
- expect(parameters["error"]).to eq "expired_token"
117
- expect(parameters["error_description"]).to eq "The access token has expired."
118
- end
119
-
120
- it "should liberally handle out-of-order auth-params" do
121
- parameters = Signet::OAuth2.parse_www_authenticate_header(
122
- "OAuth error_description='The access token has expired.', " \
123
- "error='expired_token', realm='http://sp.example.com/'"
124
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
125
- expect(parameters["realm"]).to eq "http://sp.example.com/"
126
- expect(parameters["error"]).to eq "expired_token"
127
- expect(parameters["error_description"]).to eq "The access token has expired."
128
- end
129
-
130
- it "should not allow unquoted strings that do not match tchar" do
131
- expect(lambda do
132
- Signet::OAuth2.parse_www_authenticate_header(
133
- "OAuth realm=http://sp.example.com/, error=expired_token, " \
134
- 'error_description="The access token has expired."'
135
- )
136
- end).to raise_error(Signet::ParseError)
137
- end
138
-
139
- it "should not parse non-OAuth challenges" do
140
- expect(lambda do
141
- Signet::OAuth2.parse_www_authenticate_header(
142
- 'AuthSub realm="https://www.google.com/accounts/AuthSubRequest"'
143
- )
144
- end).to raise_error(Signet::ParseError)
145
- end
146
- end
147
-
148
- describe "when generating a Basic Authorization header" do
149
- it "should correctly handle client ID and password pairs" do
150
- # Example from OAuth 2 spec
151
- expect(Signet::OAuth2.generate_basic_authorization_header(
152
- "s6BhdRkqt3", "gX1fBat3bV"
153
- )).to eq "Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW"
154
- end
155
-
156
- it "should correctly encode using the alogrithm given in RFC 2617" do
157
- # Example from RFC 2617
158
- expect(Signet::OAuth2.generate_basic_authorization_header(
159
- "Aladdin", "open sesame"
160
- )).to eq "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
161
- end
162
- end
163
-
164
- describe "when parsing a token response body" do
165
- it "should correctly handle just an access token" do
166
- expect(Signet::OAuth2.parse_credentials(
167
- '{"access_token": "12345"}',
168
- "application/json; charset=utf-8"
169
- )).to eq ({ "access_token" => "12345" })
170
- end
171
-
172
- it "should handle form encoded responses" do
173
- expect(Signet::OAuth2.parse_credentials(
174
- "access_token=12345&expires=1000",
175
- "application/x-www-form-urlencoded; charset=utf-8"
176
- )).to eq("access_token" => "12345", "expires" => "1000")
177
- end
178
-
179
- it "should raise an error for an invalid body" do
180
- expect(lambda do
181
- Signet::OAuth2.parse_credentials(
182
- "This is not JSON.",
183
- "application/json"
184
- )
185
- end).to raise_error(MultiJson::DecodeError)
186
- end
187
-
188
- it "should raise an error for a bogus body" do
189
- expect(lambda do
190
- Signet::OAuth2.parse_credentials :bogus, "application/json"
191
- end).to raise_error(TypeError)
192
- end
193
- end
194
- end
data/spec/signet_spec.rb DELETED
@@ -1,78 +0,0 @@
1
- # Copyright (C) 2010 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require "spec_helper"
15
- require "signet/oauth_2"
16
-
17
- describe Signet do
18
- describe "when parsing an auth param list" do
19
- it "should correctly handle commas" do
20
- parameters = Signet.parse_auth_param_list(
21
- 'a="1, 2" , b="3,4",c="5 , 6" ,d="7 ,8"'
22
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
23
- expect(parameters["a"]).to eq "1, 2"
24
- expect(parameters["b"]).to eq "3,4"
25
- expect(parameters["c"]).to eq "5 , 6"
26
- expect(parameters["d"]).to eq "7 ,8"
27
- end
28
-
29
- it "should correctly handle backslash-escaped pairs" do
30
- parameters = Signet.parse_auth_param_list(
31
- 'token="\t\o\k\e\n" sigalg="\s\i\g\a\l\g" data="\d\a\t\a"'
32
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
33
- expect(parameters["token"]).to eq "token"
34
- expect(parameters["sigalg"]).to eq "sigalg"
35
- expect(parameters["data"]).to eq "data"
36
- end
37
-
38
- it "should liberally handle space-separated auth-param lists" do
39
- parameters = Signet.parse_auth_param_list(
40
- 'token="token" sigalg="sigalg" data="data" sig="sig"'
41
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
42
- expect(parameters["token"]).to eq "token"
43
- expect(parameters["sigalg"]).to eq "sigalg"
44
- expect(parameters["data"]).to eq "data"
45
- expect(parameters["sig"]).to eq "sig"
46
- end
47
-
48
- it "should liberally handle single-quoted auth-param lists" do
49
- parameters = Signet.parse_auth_param_list(
50
- "token='token' sigalg='sigalg' data='data' sig='sig'"
51
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
52
- expect(parameters["token"]).to eq "token"
53
- expect(parameters["sigalg"]).to eq "sigalg"
54
- expect(parameters["data"]).to eq "data"
55
- expect(parameters["sig"]).to eq "sig"
56
- end
57
-
58
- it "should liberally handle unquoted auth-param lists" do
59
- parameters = Signet.parse_auth_param_list(
60
- "token=token sigalg=sigalg data=data sig=sig"
61
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
62
- expect(parameters["token"]).to eq "token"
63
- expect(parameters["sigalg"]).to eq "sigalg"
64
- expect(parameters["data"]).to eq "data"
65
- expect(parameters["sig"]).to eq "sig"
66
- end
67
-
68
- it "should liberally handle auth-param lists with empty sections" do
69
- parameters = Signet.parse_auth_param_list(
70
- "token=token, , sigalg=sigalg,, data=data, sig=sig"
71
- ).each_with_object({}) { |(k, v), h| h[k] = v; }
72
- expect(parameters["token"]).to eq "token"
73
- expect(parameters["sigalg"]).to eq "sigalg"
74
- expect(parameters["data"]).to eq "data"
75
- expect(parameters["sig"]).to eq "sig"
76
- end
77
- end
78
- end
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --format documentation
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- $LOAD_PATH.uniq!
2
-
3
- require "rubygems"
4
- require "signet"
5
- require "rspec"
6
- require "simplecov"
7
- require "faraday"
8
-
9
- SimpleCov.start if ENV["COVERAGE"]
10
- Faraday::Adapter.load_middleware :test
@@ -1,17 +0,0 @@
1
- RSpec.describe "spec_helper.rb" do
2
- let(:spec_dir) { __dir__ }
3
- let(:root_dir) { File.expand_path File.join(spec_dir, "..") }
4
- let(:lib_dir) { File.expand_path File.join(root_dir, "lib") }
5
-
6
- describe "spec_dir" do
7
- it "is already in $LOAD_PATH" do
8
- expect($LOAD_PATH).to include spec_dir
9
- end
10
- end
11
-
12
- describe "lib_dir" do
13
- it "is already in $LOAD_PATH" do
14
- expect($LOAD_PATH).to include lib_dir
15
- end
16
- end
17
- end
data/website/index.html DELETED
@@ -1,95 +0,0 @@
1
- <!DOCTYPE html>
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3
- <head>
4
- <meta charset="utf-8"/>
5
- <title>Signet</title>
6
- <style type="text/css">
7
- * {
8
- font-size: 100%;
9
- margin: 0;
10
- padding: 0;
11
- }
12
-
13
- body {
14
- font-family: "Lucida Grande", Verdana, sans-serif;
15
- margin: 1em;
16
- }
17
-
18
- a {
19
- color: #880000;
20
- }
21
-
22
- a:visited {
23
- color: #333333;
24
- }
25
-
26
- h1 {
27
- font-size: 2em;
28
- margin: 0 0 0.8em 0;
29
- text-align: center;
30
- }
31
-
32
- h2 {
33
- font-size: 1em;
34
- margin: 0.8em 0;
35
- }
36
-
37
- p {
38
- margin: 0.8em 0;
39
- }
40
-
41
- ul {
42
- font-size: 0.9em;
43
- margin: 0 0 0 1.5em;
44
- }
45
-
46
- div {
47
- width: 50%;
48
- margin: 0 auto;
49
- padding: 0.8em;
50
- background-color: #AA5852;
51
- border: 2px solid #C2645D;
52
- }
53
-
54
- @media print {
55
- body {
56
- font-size: 0.9em;
57
- }
58
-
59
- a {
60
- text-decoration: none;
61
- color: #000;
62
- }
63
- }
64
- </style>
65
- </head>
66
- <body>
67
- <h1>Signet</h1>
68
- <div>
69
- <p>
70
- Signet is an OAuth 1.0 / OAuth 2.0 implementation.
71
- </p>
72
- <ul>
73
- <li>
74
- <a href="http://rubyforge.org/projects/signet/">
75
- Project Page
76
- </a>
77
- </li>
78
- <li>
79
- <a href="http://github.com/sporkmonger/signet/tree/">
80
- GitHub Page
81
- </a>
82
- </li>
83
- <li><a href="/api/">API</a></li>
84
- <li><a href="/specdoc/">Specifications</a></li>
85
- <li><a href="/coverage/">Code Coverage</a></li>
86
- </ul>
87
- <p>
88
- You know what to do:
89
- </p>
90
- <p>
91
- <code>sudo gem install signet</code>
92
- </p>
93
- </div>
94
- </body>
95
- </html>