Skip to content

Commit b0b5bd7

Browse files
committed
Add test to ensure OmniAuth can be called directly
1 parent af6df13 commit b0b5bd7

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

lib/rodauth/features/omniauth_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def build_omniauth_app
108108
)
109109
builder.configure do |config|
110110
[:request_validation_phase, :before_request_phase, :before_callback_phase, :on_failure].each do |hook|
111-
config.send(:"#{hook}=", -> (env) { env["rodauth.omniauth.instance"].send(:"omniauth_#{hook}") if env["rodauth.omniauth.instance"] })
111+
config.send(:"#{hook}=", -> (env) { env["rodauth.omniauth.instance"]&.send(:"omniauth_#{hook}") })
112112
end
113113
end
114114
self.class.instance_variable_get(:@omniauth_providers).each do |(provider, *args)|

test/omniauth_base_test.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@
339339

340340
page.driver.post "/auth/developer"
341341
assert_equal "Roda::RodaPlugins::RouteCsrf::InvalidToken: encoded token is not a string", page.html
342-
343-
OmniAuth.config.allowed_request_methods = %i[get post]
344342
end
345343

346344
it "returns authorize URL when using JSON" do
@@ -509,4 +507,22 @@
509507
app.freeze
510508
assert app.rodauth.frozen?
511509
end
510+
511+
it "still allows calling OmniAuth directly" do
512+
rodauth do
513+
enable :omniauth_base
514+
end
515+
roda do |r|
516+
end
517+
518+
builder = OmniAuth::Builder.new do |b|
519+
b.use Rack::Session::Cookie, :secret => "a" * 64
520+
b.provider :developer
521+
b.run -> (env) { [404, {}, []] } # pass through
522+
end
523+
app = Rack::MockRequest.new(builder.to_app)
524+
response = app.get "/auth/developer"
525+
assert_equal 200, response.status
526+
assert_includes response.body, "</form>"
527+
end
512528
end

test/omniauth_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@
181181

182182
visit "/auth/developer"
183183
assert_equal 404, page.status_code
184-
185-
OmniAuth.config.allowed_request_methods = %i[get post]
186184
end
187185

188186
it "deletes omniauth identities when account is closed" do

test/test_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454

5555
Sequel::Model.cache_anonymous_models = false
5656

57-
OmniAuth.config.allowed_request_methods = %i[get post]
58-
OmniAuth.config.logger = Logger.new(nil)
59-
6057
class Minitest::HooksSpec
6158
include Capybara::DSL
6259

@@ -113,12 +110,18 @@ def logout
113110
click_on "Logout"
114111
end
115112

113+
before do
114+
OmniAuth.config.allowed_request_methods = %i[get post]
115+
OmniAuth.config.logger = Logger.new(nil)
116+
end
117+
116118
around do |&block|
117119
DB.transaction(rollback: :always, auto_savepoint: true) { super(&block) }
118120
end
119121

120122
after do
121123
Capybara.reset_sessions!
124+
OmniAuth.config.send(:initialize) # reset OmniAuth configuration
122125
end
123126
end
124127

0 commit comments

Comments
 (0)