This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user: do not allow the update of the portus user
The only exception is on the password, that may change depending on whether the given secret changed or not. For this case, Portus will always update the password of the portus user on start. Fixes #1878 Signed-off-by: Miquel Sabaté Solà <[email protected]>
- Loading branch information
Showing
3 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# This file updates the password of the portus hidden user if this | ||
# exists and the secret is given. | ||
|
||
portus_exists = false | ||
begin | ||
portus_exists = User.exists?(username: "portus") | ||
rescue StandardError | ||
# We will ignore any error and skip this initializer. This is done this way | ||
# because it can get really tricky to catch all the myriad of exceptions that | ||
# might be raised on database errors. | ||
portus_exists = false | ||
end | ||
|
||
password = Rails.application.secrets.portus_password | ||
if portus_exists && password.present? | ||
portus = User.find_by(username: "portus") | ||
portus&.update_attribute("password", Rails.application.secrets.portus_password) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,15 @@ | |
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
|
||
context "portus user" do | ||
it "does not allow portus user to be updated" do | ||
create :user, username: "portus", email: "[email protected]" | ||
portus = User.find_by(username: "portus") | ||
put "/api/v1/users/#{portus.id}", { user: user_data }, @header | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
|
||
context "DELETE /api/v1/users/:id" do | ||
|