Skip to content

Commit fbcbdf4

Browse files
authored
Merge pull request #1982 from yeti-switch/test/admin-api-auth-regression
Add regression test: admin API auth in OIDC mode
2 parents 69d512b + 21cc14e commit fbcbdf4

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

app/models/concerns/admin_user_oidc_handler.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ module AdminUserOidcHandler
1515
# which would shadow a method defined earlier in the ancestor chain.
1616
define_method(:valid_password?) { |_password| false }
1717

18-
# REST API auth calls admin_user.authenticate(password) — alias it
19-
# so it returns false instead of raising NoMethodError.
20-
alias_method :authenticate, :valid_password?
18+
# Keep web password sign-in disabled while preserving the legacy
19+
# password-backed admin JWT API authentication path.
20+
define_method(:authenticate) do |password|
21+
Devise::Encryptor.compare(self.class, encrypted_password, password)
22+
end
2123
end
2224
end

spec/models/concerns/admin_user_oidc_handler_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class DummyOidcUser < ActiveRecord::Base
5656
end
5757
end
5858

59+
describe '#authenticate' do
60+
it 'checks the encrypted password for API auth callers' do
61+
user = DummyOidcUser.new(username: 'alice')
62+
user.password = 'Password123!'
63+
64+
expect(user.authenticate('Password123!')).to be(true)
65+
expect(user.authenticate('wrong-password')).to be(false)
66+
end
67+
end
68+
5969
describe 'oidc_raw_info serialization' do
6070
it 'round-trips a hash through JSON' do
6171
user = DummyOidcUser.new(username: 'alice')

spec/requests/api/rest/admin/auth_controller_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@
8282
expect(response_json).to match(jwt: a_kind_of(String))
8383
end
8484
end
85+
86+
context 'oidc mode', oidc_mode: true do
87+
it 'still authenticates via password' do
88+
subject
89+
expect(response.status).to eq(201)
90+
expect(response_json).to match(jwt: a_kind_of(String))
91+
end
92+
end
93+
94+
context 'ldap mode', :ldap do
95+
it 'still authenticates via password' do
96+
subject
97+
expect(response.status).to eq(201)
98+
expect(response_json).to match(jwt: a_kind_of(String))
99+
end
100+
end
85101
end
86102

87103
context 'when attributes are invalid' do

0 commit comments

Comments
 (0)