Skip to content

Commit a0915d1

Browse files
committed
Update omniauthable tests for OmniAuth 2.0
1 parent 8bb358c commit a0915d1

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gem "responders", "~> 3.0"
1717

1818
group :test do
1919
gem "omniauth-facebook"
20-
gem "omniauth-openid"
20+
gem "omniauth-openid", git: 'https://github.com/jkowens/omniauth-openid', branch: 'patch-1'
2121
gem "timecop"
2222
gem "webrat", "0.7.3", require: false
2323
gem "mocha", "~> 1.1", require: false

Gemfile.lock

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GIT
2-
remote: https://github.com/rails/activemodel-serializers-xml.git
2+
remote: git://github.com/rails/activemodel-serializers-xml.git
33
revision: 694f4071c6b16e4c8597cc323c241b5f787b3ea8
44
specs:
55
activemodel-serializers-xml (1.0.2)
@@ -8,14 +8,23 @@ GIT
88
builder (~> 3.1)
99

1010
GIT
11-
remote: https://github.com/rails/rails-controller-testing.git
11+
remote: git://github.com/rails/rails-controller-testing.git
1212
revision: 4b15c86e82ee380f2a7cc009e470368f7520560a
1313
specs:
1414
rails-controller-testing (1.0.5)
1515
actionpack (>= 5.0.1.rc1)
1616
actionview (>= 5.0.1.rc1)
1717
activesupport (>= 5.0.1.rc1)
1818

19+
GIT
20+
remote: https://github.com/jkowens/omniauth-openid
21+
revision: c70d35f266a814340b01f6f5649bb664a78743f4
22+
branch: patch-1
23+
specs:
24+
omniauth-openid (2.0.0)
25+
omniauth (>= 1.0, < 3.0)
26+
rack-openid (~> 1.4.0)
27+
1928
PATH
2029
remote: .
2130
specs:
@@ -89,8 +98,11 @@ GEM
8998
concurrent-ruby (1.1.7)
9099
crass (1.0.6)
91100
erubi (1.9.0)
92-
faraday (1.0.1)
101+
faraday (1.3.0)
102+
faraday-net_http (~> 1.0)
93103
multipart-post (>= 1.2, < 3)
104+
ruby2_keywords
105+
faraday-net_http (1.0.1)
94106
globalid (0.4.2)
95107
activesupport (>= 4.2.0)
96108
hashie (4.1.0)
@@ -122,22 +134,22 @@ GEM
122134
multi_json (~> 1.3)
123135
multi_xml (~> 0.5)
124136
rack (>= 1.2, < 3)
125-
omniauth (1.9.1)
137+
omniauth (2.0.1)
126138
hashie (>= 3.4.6)
127139
rack (>= 1.6.2, < 3)
140+
rack-protection
128141
omniauth-facebook (7.0.0)
129142
omniauth-oauth2 (~> 1.2)
130-
omniauth-oauth2 (1.7.0)
143+
omniauth-oauth2 (1.7.1)
131144
oauth2 (~> 1.4)
132-
omniauth (~> 1.9)
133-
omniauth-openid (1.0.1)
134-
omniauth (~> 1.0)
135-
rack-openid (~> 1.3.1)
145+
omniauth (>= 1.9, < 3)
136146
orm_adapter (0.5.0)
137147
rack (2.2.3)
138-
rack-openid (1.3.1)
148+
rack-openid (1.4.2)
139149
rack (>= 1.1.0)
140150
ruby-openid (>= 2.1.8)
151+
rack-protection (2.1.0)
152+
rack
141153
rack-test (1.1.0)
142154
rack (>= 1.0, < 3)
143155
rails (6.0.3.3)
@@ -172,6 +184,7 @@ GEM
172184
actionpack (>= 5.0)
173185
railties (>= 5.0)
174186
ruby-openid (2.9.2)
187+
ruby2_keywords (0.0.2)
175188
sprockets (4.0.2)
176189
concurrent-ruby (~> 1.0)
177190
rack (> 1, < 3)
@@ -206,7 +219,7 @@ DEPENDENCIES
206219
omniauth
207220
omniauth-facebook
208221
omniauth-oauth2
209-
omniauth-openid
222+
omniauth-openid!
210223
rails (~> 6.0.0)
211224
rails-controller-testing!
212225
rdoc

app/views/devise/shared/_links.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
<%- if devise_mapping.omniauthable? %>
2222
<%- resource_class.omniauth_providers.each do |provider| %>
23-
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
23+
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), method: :post %><br />
2424
<% end %>
2525
<% end %>

test/integration/omniauthable_test.rb

+26-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class OmniauthableIntegrationTest < Devise::IntegrationTest
2323
"extra" => {"user_hash" => FACEBOOK_INFO}
2424
}
2525
OmniAuth.config.add_camelization 'facebook', 'FaceBook'
26+
if OmniAuth.config.respond_to?(:request_validation_phase)
27+
OmniAuth.config.request_validation_phase = ->(env) {}
28+
end
2629
end
2730

2831
teardown do
@@ -45,17 +48,17 @@ def stub_action!(name)
4548
test "omniauth sign in should not run model validations" do
4649
stub_action!(:sign_in_facebook) do
4750
create_user
48-
visit "/users/sign_in"
49-
click_link "Sign in with FaceBook"
51+
post "/users/auth/facebook"
52+
follow_redirect!
5053
assert warden.authenticated?(:user)
5154

5255
refute User.validations_performed
5356
end
5457
end
5558

5659
test "can access omniauth.auth in the env hash" do
57-
visit "/users/sign_in"
58-
click_link "Sign in with FaceBook"
60+
post "/users/auth/facebook"
61+
follow_redirect!
5962

6063
json = ActiveSupport::JSON.decode(response.body)
6164

@@ -68,8 +71,8 @@ def stub_action!(name)
6871

6972
test "cleans up session on sign up" do
7073
assert_no_difference "User.count" do
71-
visit "/users/sign_in"
72-
click_link "Sign in with FaceBook"
74+
post "/users/auth/facebook"
75+
follow_redirect!
7376
end
7477

7578
assert session["devise.facebook_data"]
@@ -89,8 +92,8 @@ def stub_action!(name)
8992

9093
test "cleans up session on cancel" do
9194
assert_no_difference "User.count" do
92-
visit "/users/sign_in"
93-
click_link "Sign in with FaceBook"
95+
post "/users/auth/facebook"
96+
follow_redirect!
9497
end
9598

9699
assert session["devise.facebook_data"]
@@ -100,8 +103,8 @@ def stub_action!(name)
100103

101104
test "cleans up session on sign in" do
102105
assert_no_difference "User.count" do
103-
visit "/users/sign_in"
104-
click_link "Sign in with FaceBook"
106+
post "/users/auth/facebook"
107+
follow_redirect!
105108
end
106109

107110
assert session["devise.facebook_data"]
@@ -110,23 +113,28 @@ def stub_action!(name)
110113
end
111114

112115
test "sign in and send remember token if configured" do
113-
visit "/users/sign_in"
114-
click_link "Sign in with FaceBook"
116+
post "/users/auth/facebook"
117+
follow_redirect!
115118
assert_nil warden.cookies["remember_user_token"]
116119

117120
stub_action!(:sign_in_facebook) do
118121
create_user
119-
visit "/users/sign_in"
120-
click_link "Sign in with FaceBook"
122+
post "/users/auth/facebook"
123+
follow_redirect!
121124
assert warden.authenticated?(:user)
122125
assert warden.cookies["remember_user_token"]
123126
end
124127
end
125128

129+
test "generates a link to authenticate with provider" do
130+
visit "/users/sign_in"
131+
assert_select "a[href=?][data-method='post']", "/users/auth/facebook", text: "Sign in with FaceBook"
132+
end
133+
126134
test "generates a proper link when SCRIPT_NAME is set" do
127135
header 'SCRIPT_NAME', '/q'
128136
visit "/users/sign_in"
129-
assert_select "a", href: "/q/users/auth/facebook"
137+
assert_select "a[href=?][data-method='post']", "/q/users/auth/facebook", text: "Sign in with FaceBook"
130138
end
131139

132140
test "handles callback error parameter according to the specification" do
@@ -139,10 +147,10 @@ def stub_action!(name)
139147
test "handles other exceptions from OmniAuth" do
140148
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
141149

142-
visit "/users/sign_in"
143-
click_link "Sign in with FaceBook"
150+
post "/users/auth/facebook"
151+
follow_redirect!
152+
follow_redirect!
144153

145-
assert_current_url "/users/sign_in"
146154
assert_contain 'Could not authenticate you from FaceBook because "Invalid credentials".'
147155
end
148156
end

0 commit comments

Comments
 (0)