|
1 |
| -require 'spec_helper' |
| 1 | +require "spec_helper" |
2 | 2 |
|
3 | 3 | describe "OmniAuth::Strategies::OAuth" do
|
4 | 4 | class MyOAuthProvider < OmniAuth::Strategies::OAuth
|
5 | 5 | uid{ access_token.token }
|
6 |
| - info{ {'name' => access_token.token} } |
| 6 | + info{ {"name" => access_token.token} } |
7 | 7 | end
|
8 | 8 |
|
9 | 9 | def app
|
10 | 10 | Rack::Builder.new {
|
11 | 11 | use OmniAuth::Test::PhonySession
|
12 | 12 | use OmniAuth::Builder do
|
13 |
| - provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :name => 'example.org' |
14 |
| - provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :authorize_params => {:abc => 'def'}, :name => 'example.org_with_authorize_params' |
15 |
| - provider MyOAuthProvider, 'abc', 'def', :client_options => {:site => 'https://api.example.org'}, :request_params => {:scope => 'http://foobar.example.org'}, :name => 'example.org_with_request_params' |
| 13 | + provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :name => "example.org" |
| 14 | + provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :authorize_params => {:abc => "def"}, :name => "example.org_with_authorize_params" |
| 15 | + provider MyOAuthProvider, "abc", "def", :client_options => {:site => "https://api.example.org"}, :request_params => {:scope => "http://foobar.example.org"}, :name => "example.org_with_request_params" |
16 | 16 | end
|
17 |
| - run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] } |
| 17 | + run lambda { |env| [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] } |
18 | 18 | }.to_app
|
19 | 19 | end
|
20 | 20 |
|
21 | 21 | def session
|
22 |
| - last_request.env['rack.session'] |
| 22 | + last_request.env["rack.session"] |
23 | 23 | end
|
24 | 24 |
|
25 | 25 | before do
|
26 |
| - stub_request(:post, 'https://api.example.org/oauth/request_token'). |
| 26 | + stub_request(:post, "https://api.example.org/oauth/request_token"). |
27 | 27 | to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
|
28 | 28 | end
|
29 | 29 |
|
30 |
| - it 'should add a camelization for itself' do |
31 |
| - expect(OmniAuth::Utils.camelize('oauth')).to eq('OAuth') |
| 30 | + it "should add a camelization for itself" do |
| 31 | + expect(OmniAuth::Utils.camelize("oauth")).to eq("OAuth") |
32 | 32 | end
|
33 | 33 |
|
34 |
| - describe '/auth/{name}' do |
35 |
| - context 'successful' do |
| 34 | + describe "/auth/{name}" do |
| 35 | + context "successful" do |
36 | 36 | before do
|
37 |
| - get '/auth/example.org' |
| 37 | + get "/auth/example.org" |
38 | 38 | end
|
39 | 39 |
|
40 |
| - it 'should redirect to authorize_url' do |
| 40 | + it "should redirect to authorize_url" do |
41 | 41 | expect(last_response).to be_redirect
|
42 |
| - expect(last_response.headers['Location']).to eq('https://api.example.org/oauth/authorize?oauth_token=yourtoken') |
| 42 | + expect(last_response.headers["Location"]).to eq("https://api.example.org/oauth/authorize?oauth_token=yourtoken") |
43 | 43 | end
|
44 | 44 |
|
45 |
| - it 'should redirect to authorize_url with authorize_params when set' do |
46 |
| - get '/auth/example.org_with_authorize_params' |
| 45 | + it "should redirect to authorize_url with authorize_params when set" do |
| 46 | + get "/auth/example.org_with_authorize_params" |
47 | 47 | expect(last_response).to be_redirect
|
48 | 48 | expect([
|
49 |
| - 'https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken', |
50 |
| - 'https://api.example.org/oauth/authorize?oauth_token=yourtoken&abc=def' |
51 |
| - ]).to be_include(last_response.headers['Location']) |
| 49 | + "https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken", |
| 50 | + "https://api.example.org/oauth/authorize?oauth_token=yourtoken&abc=def" |
| 51 | + ]).to be_include(last_response.headers["Location"]) |
52 | 52 | end
|
53 | 53 |
|
54 |
| - it 'should set appropriate session variables' do |
55 |
| - expect(session['oauth']).to eq({"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}) |
| 54 | + it "should set appropriate session variables" do |
| 55 | + expect(session["oauth"]).to eq({"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}) |
56 | 56 | end
|
57 | 57 |
|
58 |
| - it 'should pass request_params to get_request_token' do |
59 |
| - get '/auth/example.org_with_request_params' |
60 |
| - expect(WebMock).to have_requested(:post, 'https://api.example.org/oauth/request_token'). |
| 58 | + it "should pass request_params to get_request_token" do |
| 59 | + get "/auth/example.org_with_request_params" |
| 60 | + expect(WebMock).to have_requested(:post, "https://api.example.org/oauth/request_token"). |
61 | 61 | with {|req| req.body == "scope=http%3A%2F%2Ffoobar.example.org" }
|
62 | 62 | end
|
63 | 63 | end
|
64 | 64 |
|
65 |
| - context 'unsuccessful' do |
| 65 | + context "unsuccessful" do |
66 | 66 | before do
|
67 |
| - stub_request(:post, 'https://api.example.org/oauth/request_token'). |
| 67 | + stub_request(:post, "https://api.example.org/oauth/request_token"). |
68 | 68 | to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
|
69 |
| - get '/auth/example.org' |
| 69 | + get "/auth/example.org" |
70 | 70 | end
|
71 | 71 |
|
72 |
| - it 'should call fail! with :service_unavailable' do |
73 |
| - expect(last_request.env['omniauth.error']).to be_kind_of(::Net::HTTPFatalError) |
74 |
| - last_request.env['omniauth.error.type'] = :service_unavailable |
| 72 | + it "should call fail! with :service_unavailable" do |
| 73 | + expect(last_request.env["omniauth.error"]).to be_kind_of(::Net::HTTPFatalError) |
| 74 | + last_request.env["omniauth.error.type"] = :service_unavailable |
75 | 75 | end
|
76 | 76 |
|
77 | 77 | context "SSL failure" do
|
78 | 78 | before do
|
79 |
| - stub_request(:post, 'https://api.example.org/oauth/request_token'). |
| 79 | + stub_request(:post, "https://api.example.org/oauth/request_token"). |
80 | 80 | to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
|
81 |
| - get '/auth/example.org' |
| 81 | + get "/auth/example.org" |
82 | 82 | end
|
83 | 83 |
|
84 |
| - it 'should call fail! with :service_unavailable' do |
85 |
| - expect(last_request.env['omniauth.error']).to be_kind_of(::OpenSSL::SSL::SSLError) |
86 |
| - last_request.env['omniauth.error.type'] = :service_unavailable |
| 84 | + it "should call fail! with :service_unavailable" do |
| 85 | + expect(last_request.env["omniauth.error"]).to be_kind_of(::OpenSSL::SSL::SSLError) |
| 86 | + last_request.env["omniauth.error.type"] = :service_unavailable |
87 | 87 | end
|
88 | 88 | end
|
89 | 89 | end
|
90 | 90 | end
|
91 | 91 |
|
92 |
| - describe '/auth/{name}/callback' do |
| 92 | + describe "/auth/{name}/callback" do |
93 | 93 | before do
|
94 |
| - stub_request(:post, 'https://api.example.org/oauth/access_token'). |
| 94 | + stub_request(:post, "https://api.example.org/oauth/access_token"). |
95 | 95 | to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
|
96 |
| - get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} |
| 96 | + get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, {"rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}} |
97 | 97 | end
|
98 | 98 |
|
99 |
| - it 'should exchange the request token for an access token' do |
100 |
| - expect(last_request.env['omniauth.auth']['provider']).to eq('example.org') |
101 |
| - expect(last_request.env['omniauth.auth']['extra']['access_token']).to be_kind_of(OAuth::AccessToken) |
| 99 | + it "should exchange the request token for an access token" do |
| 100 | + expect(last_request.env["omniauth.auth"]["provider"]).to eq("example.org") |
| 101 | + expect(last_request.env["omniauth.auth"]["extra"]["access_token"]).to be_kind_of(OAuth::AccessToken) |
102 | 102 | end
|
103 | 103 |
|
104 |
| - it 'should call through to the master app' do |
105 |
| - expect(last_response.body).to eq('true') |
| 104 | + it "should call through to the master app" do |
| 105 | + expect(last_response.body).to eq("true") |
106 | 106 | end
|
107 | 107 |
|
108 | 108 | context "bad gateway (or any 5xx) for access_token" do
|
109 | 109 | before do
|
110 |
| - stub_request(:post, 'https://api.example.org/oauth/access_token'). |
| 110 | + stub_request(:post, "https://api.example.org/oauth/access_token"). |
111 | 111 | to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
|
112 |
| - get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} |
| 112 | + get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, {"rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}} |
113 | 113 | end
|
114 | 114 |
|
115 |
| - it 'should call fail! with :service_unavailable' do |
116 |
| - expect(last_request.env['omniauth.error']).to be_kind_of(::Net::HTTPFatalError) |
117 |
| - last_request.env['omniauth.error.type'] = :service_unavailable |
| 115 | + it "should call fail! with :service_unavailable" do |
| 116 | + expect(last_request.env["omniauth.error"]).to be_kind_of(::Net::HTTPFatalError) |
| 117 | + last_request.env["omniauth.error.type"] = :service_unavailable |
118 | 118 | end
|
119 | 119 | end
|
120 | 120 |
|
121 | 121 | context "SSL failure" do
|
122 | 122 | before do
|
123 |
| - stub_request(:post, 'https://api.example.org/oauth/access_token'). |
| 123 | + stub_request(:post, "https://api.example.org/oauth/access_token"). |
124 | 124 | to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
|
125 |
| - get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"example.org" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}} |
| 125 | + get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, {"rack.session" => {"oauth" => {"example.org" => {"callback_confirmed" => true, "request_token" => "yourtoken", "request_secret" => "yoursecret"}}}} |
126 | 126 | end
|
127 | 127 |
|
128 |
| - it 'should call fail! with :service_unavailable' do |
129 |
| - expect(last_request.env['omniauth.error']).to be_kind_of(::OpenSSL::SSL::SSLError) |
130 |
| - last_request.env['omniauth.error.type'] = :service_unavailable |
| 128 | + it "should call fail! with :service_unavailable" do |
| 129 | + expect(last_request.env["omniauth.error"]).to be_kind_of(::OpenSSL::SSL::SSLError) |
| 130 | + last_request.env["omniauth.error.type"] = :service_unavailable |
131 | 131 | end
|
132 | 132 | end
|
133 | 133 | end
|
134 | 134 |
|
135 |
| - describe '/auth/{name}/callback with expired session' do |
| 135 | + describe "/auth/{name}/callback with expired session" do |
136 | 136 | before do
|
137 |
| - stub_request(:post, 'https://api.example.org/oauth/access_token'). |
| 137 | + stub_request(:post, "https://api.example.org/oauth/access_token"). |
138 | 138 | to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
|
139 |
| - get '/auth/example.org/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {}} |
| 139 | + get "/auth/example.org/callback", {:oauth_verifier => "dudeman"}, {"rack.session" => {}} |
140 | 140 | end
|
141 | 141 |
|
142 |
| - it 'should call fail! with :session_expired' do |
143 |
| - expect(last_request.env['omniauth.error']).to be_kind_of(::OmniAuth::NoSessionError) |
144 |
| - last_request.env['omniauth.error.type'] = :session_expired |
| 142 | + it "should call fail! with :session_expired" do |
| 143 | + expect(last_request.env["omniauth.error"]).to be_kind_of(::OmniAuth::NoSessionError) |
| 144 | + last_request.env["omniauth.error.type"] = :session_expired |
145 | 145 | end
|
146 | 146 | end
|
147 | 147 | end
|
0 commit comments