Commit b4173913 authored by Loïc Dachary's avatar Loïc Dachary
Browse files

Merge branch 'wip-authenticate' into 'master'

forge: finalize user creation for gitlab / gitea

See merge request fedeproxy/fedeproxy!12
parents aaae1d88 06503a79
Pipeline #23786 canceled with stage
......@@ -33,6 +33,26 @@ class Gitea(Forge):
r.raise_for_status()
self.set_token(r.json()["sha1"])
def _finalize_user_create(self, username, password):
r = self.s.post(
f"{self.url}/user/login",
data={
"user_name": username,
"password": password,
},
)
logger.debug(r.status_code)
r.raise_for_status()
r = self.s.post(
f"{self.url}/user/settings/change_password",
data={
"password": password,
"retype": password,
"_csrf": self.s.cookies["_csrf"],
},
)
r.raise_for_status()
def set_token(self, token):
self.s.headers["Authorization"] = f"token {token}"
......@@ -72,6 +92,7 @@ class Gitea(Forge):
logger.debug(r.text)
r.raise_for_status()
info = r.json()
Gitea(self.url)._finalize_user_create(username, password)
return info
def project_delete(self, username, namespace, project):
......
......@@ -124,7 +124,7 @@ class GitLab(Forge):
"username": username,
"email": email,
"password": password,
"force_random_password": True,
"skip_confirmation": True,
},
)
logger.debug(r.text)
......
......@@ -21,6 +21,8 @@ def verify_user_create(forge):
forge.user_delete(username)
u = forge.user_create(username, password, email)
assert u["id"] == forge.user_create(username, password, email)["id"]
forge.authenticate(username=username, password=password)
forge.authenticate(username="root", password="Wrobyak4")
assert forge.user_delete(username) is True
assert forge.user_get(username) is None
assert forge.user_delete(username) is False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment