Skip to content

Commit

Permalink
Fix loading current value for nexus user passwords (#146)
Browse files Browse the repository at this point in the history
* Fix loading current value for nexus user passwords

There's two issues solved by this commit:

- The API calls to check if the new password works always failed;
- The new password was given as the old password value when the
  call failed, making it impossible to update the password.

* Adapt spec tests for updating user password
  • Loading branch information
jlundqvist-criteo authored Jun 25, 2024
1 parent e4df09a commit 3a02f95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# Check if we need to change the password.
if self.class.properties[:password].is_set?(desired)
begin
::Nexus3::Api.new(api_client.endpoint, username, desired.password).request(:get, '/service/metrics/ping')
password 'Supercalifragilisticexpialidocious-that-does-not-exist-so-maybe-the-resource-will-need-to-converge'
rescue ::Nexus3::ApiError
::Nexus3::Api.new(api_client.endpoint, username, desired.password).request(:get, 'status')
password desired.password
rescue ::Nexus3::ApiError
password 'Supercalifragilisticexpialidocious-that-does-not-exist-so-maybe-the-resource-will-need-to-converge'
end
end
rescue LoadError, ::Nexus3::ApiError => e
Expand Down
7 changes: 5 additions & 2 deletions spec/unit/resources/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
user_response('user_with_role'),
user_response('user_with_role'))

stub_request(:get, 'http://localhost:8081/service/metrics/ping')
.to_return(api_response(200))
stub_request(:get, 'http://localhost:8081/service/rest/v1/status')
.to_return(api_response(200)) # Nominal case
stub_request(:get, 'http://localhost:8081/service/rest/v1/status')
.with(basic_auth: %w[test-with-pass newpassword])
.to_return(api_response(401)) # When password is changed
end

it 'creates a user' do
Expand Down

0 comments on commit 3a02f95

Please sign in to comment.