ChangeUserPassword Handler + API

This commit is contained in:
al8763be 2024-04-17 22:04:23 +02:00
parent 47d4bda99b
commit 0176f78067
8 changed files with 163 additions and 7 deletions

View file

@ -38,8 +38,9 @@ unsignReportPath = base_url + "/api/unsignReport"
deleteReportPath = base_url + "/api/deleteReport"
getStatisticsPath = base_url + "/api/getStatistics"
changeProjectNamePath = base_url + "/api/changeProjectName"
changeUserPasswordPath = base_url + "/api/changeUserPassword"
debug_output = True
debug_output = False
def gprint(*args, **kwargs):
@ -179,4 +180,12 @@ def changeProjectName(token: string, projectName: string, newProjectName: string
headers = {"Authorization": "Bearer " + token},
params={"newProjectName": newProjectName}
)
return response
def changeUserPassword(token: string, username: string, newPassword: string):
response = requests.put(
changeUserPasswordPath + "/" + username,
headers = {"Authorization": "Bearer " + token},
params={"newPassword": newPassword}
)
return response

View file

@ -675,6 +675,14 @@ def test_project_name_change():
token = register_and_login(admin_username, admin_password)
# Promote to admin
response = requests.post(
promoteToAdminPath,
json={"username": admin_username},
headers={"Authorization": "Bearer " + token},
)
response = create_project(token, project_name)
assert response.status_code == 200, "Create project failed"
@ -703,8 +711,36 @@ def test_project_name_change():
assert response.status_code == 200, "Project name change failed"
gprint("test_projectNameChange successful")
def test_change_user_password():
# Create admin
admin_username = randomString()
admin_password = randomString()
user = randomString()
password = randomString()
token = register_and_login(admin_username, admin_password)
# Promote to admin
response = requests.post(
promoteToAdminPath,
json={"username": admin_username},
headers={"Authorization": "Bearer " + token},
)
_ = register_and_login(user, password)
response = changeUserPassword(token, user, "new_password")
assert response.status_code == 200, "Change user password failed"
response = login(user, "new_password")
assert response.status_code == 200, "Login failed with new password"
gprint("test_change_user_password successful")
if __name__ == "__main__":
test_change_user_password()
test_project_name_change();
test_delete_report()
test_unsign_report()