mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: delete associated ssh public keys with account deletion
Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
This commit is contained in:
parent
bce5b81acd
commit
ff92e95f7a
2 changed files with 32 additions and 1 deletions
|
@ -13,7 +13,7 @@ class SSHPubKey(Base):
|
||||||
|
|
||||||
User = relationship(
|
User = relationship(
|
||||||
"User",
|
"User",
|
||||||
backref=backref("ssh_pub_keys", lazy="dynamic"),
|
backref=backref("ssh_pub_keys", lazy="dynamic", cascade="all, delete"),
|
||||||
foreign_keys=[__table__.c.UserID],
|
foreign_keys=[__table__.c.UserID],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2032,6 +2032,37 @@ def test_account_delete_self(client: TestClient, user: User):
|
||||||
assert record is None
|
assert record is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_account_delete_self_with_ssh_public_key(client: TestClient, user: User):
|
||||||
|
username = user.Username
|
||||||
|
|
||||||
|
with db.begin():
|
||||||
|
db.create(
|
||||||
|
SSHPubKey, User=user, Fingerprint="testFingerprint", PubKey="testPubKey"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Confirm that we can view our own account deletion page
|
||||||
|
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||||
|
endpoint = f"/account/{username}/delete"
|
||||||
|
with client as request:
|
||||||
|
resp = request.get(endpoint, cookies=cookies)
|
||||||
|
assert resp.status_code == HTTPStatus.OK
|
||||||
|
|
||||||
|
# Supply everything correctly and delete ourselves
|
||||||
|
with client as request:
|
||||||
|
resp = request.post(
|
||||||
|
endpoint,
|
||||||
|
data={"passwd": "testPassword", "confirm": True},
|
||||||
|
cookies=cookies,
|
||||||
|
)
|
||||||
|
assert resp.status_code == HTTPStatus.SEE_OTHER
|
||||||
|
|
||||||
|
# Check that our User record no longer exists in the database
|
||||||
|
user_record = db.query(User).filter(User.Username == username).first()
|
||||||
|
assert user_record is None
|
||||||
|
sshpubkey_record = db.query(SSHPubKey).filter(SSHPubKey.User == user).first()
|
||||||
|
assert sshpubkey_record is None
|
||||||
|
|
||||||
|
|
||||||
def test_account_delete_as_tu(client: TestClient, tu_user: User):
|
def test_account_delete_as_tu(client: TestClient, tu_user: User):
|
||||||
with db.begin():
|
with db.begin():
|
||||||
user = create_user("user2")
|
user = create_user("user2")
|
||||||
|
|
Loading…
Add table
Reference in a new issue