Skip to content

Commit e32e803

Browse files
authored
Skip fetching keycloak configuration when in testing mode (ccrockett#33)
* skip fetching keycloak when in testing mode * add test
1 parent 2b5dc54 commit e32e803

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/omniauth/strategies/keycloak-openid.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class IntegrationError < Error; end
1818
def setup_phase
1919
super
2020

21-
if @authorize_url.nil? || @token_url.nil?
21+
if (@authorize_url.nil? || @token_url.nil?) && !OmniAuth.config.test_mode
22+
2223
prevent_site_option_mistake
2324

2425
realm = options.client_options[:realm].nil? ? options.client_id : options.client_options[:realm]

spec/omniauth/strategies/keycloak_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@
5151
end
5252
end
5353

54+
describe "test mode" do
55+
let(:config_url) { "http://localhost:8080/realms/example-realm/.well-known/openid-configuration" }
56+
57+
subject do
58+
stub_request(:get, config_url)
59+
OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', 'Example-Client', 'b53c572b-9f3b-4e79-bf8b-f03c799ba6ec',
60+
client_options: {site: 'http://localhost:8080/', realm: 'example-realm', base_url: ''})
61+
end
62+
63+
before do
64+
OmniAuth.config.test_mode = true
65+
end
66+
67+
after do
68+
OmniAuth.config.test_mode = false
69+
end
70+
71+
it 'should not fetch configuration when in test mode' do
72+
subject.setup_phase
73+
expect(a_request(:get, config_url)).not_to have_been_made
74+
OmniAuth.config.test_mode = false
75+
end
76+
end
77+
5478
describe 'client base_url option set' do
5579
context 'to blank string' do
5680
let(:new_body_endpoints) {

0 commit comments

Comments
 (0)