Skip to content

Commit

Permalink
Revive pgb (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp authored Mar 6, 2023
1 parent a208203 commit 45df132
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/relations/backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def _on_database_created(self, event: DatabaseCreatedEvent) -> None:
return

plaintext_password = pgb.generate_password()
hashed_password = pgb.get_hashed_password(self.auth_user, plaintext_password)
# create authentication user on postgres database, so we can authenticate other users
# later on
self.postgres.create_user(self.auth_user, plaintext_password, admin=True)
self.postgres.create_user(self.auth_user, hashed_password, admin=True)
self.initialise_auth_function([self.database.database, PG])

hashed_password = pgb.get_hashed_password(self.auth_user, plaintext_password)
self.charm.render_auth_file(f'"{self.auth_user}" "{hashed_password}"')

cfg = self.charm.read_pgb_config()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/relations/test_backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def test_on_database_created(
mock_event = MagicMock()
mock_event.username = "mock_user"
self.backend._on_database_created(mock_event)
hash_pw = get_hashed_password(self.backend.auth_user, pw)

postgres.create_user.assert_called_with(self.backend.auth_user, pw, admin=True)
postgres.create_user.assert_called_with(self.backend.auth_user, hash_pw, admin=True)
_init_auth.assert_has_calls([call([self.backend.database.database, "postgres"])])

hash_pw = get_hashed_password(self.backend.auth_user, pw)
_render.assert_any_call(
f"{PGB_DIR}/userlist.txt", f'"{self.backend.auth_user}" "{hash_pw}"', perms=0o700
)
Expand Down

0 comments on commit 45df132

Please sign in to comment.