Add robot tests for auth system

This commit is contained in:
Zoe Roux 2024-09-05 17:59:00 +02:00
parent 10d8c121b3
commit 8b1cf61209
No known key found for this signature in database
6 changed files with 151 additions and 1 deletions

43
auth/robot/auth.resource Normal file
View File

@ -0,0 +1,43 @@
*** Settings ***
Documentation Common things to handle rest requests
Library REST http://localhost:8901/api
*** Keywords ***
Login
[Documentation] Shortcut to login with the given username for future requests
[Arguments] ${username}
&{res}= POST /sessions {"username": "${username}", "password": "password-${username}"}
Output
Integer response status 201
String response body access_token
ConvertToJwt ${res.body.token}
Register
[Documentation] Shortcut to register with the given username for future requests
[Arguments] ${username}
&{res}= POST
... /users
... {"username": "${username}", "password": "password-${username}", "email": "${username}@zoriya.dev"}
Output
Integer response status 201
String response body token
ConvertToJwt ${res.body.token}
ConvertToJwt
[Documentation] Convert a session token to a jwt and set it in the header
[Arguments] ${token}
Set Headers {"Authorization": "Bearer ${token}"}
${res}= GET /jwt
Output
Integer response status 200
String response body token
Set Headers {"Authorization": "Bearer ${res.token}"}
Logout
[Documentation] Logout the current user, only the local client is affected.
${res}= DELETE /sessions/current
Output
Integer response status 200
Set Headers {"Authorization": ""}

29
auth/robot/sessions.robot Normal file
View File

@ -0,0 +1,29 @@
*** Settings ***
Documentation Tests of the /sessions route.
Resource ../auth.resource
*** Test Cases ***
Bad Account
[Documentation] Login fails if user does not exist
POST /sessions {"login": "i-don-t-exist", "password": "pass"}
Output
Integer response status 403
Login
[Documentation] Create a new user and login in it
Register login-user
${res}= GET /users/me
Output
Integer response status 200
String response body username login-user
Logout
Login login-user
${me}= Get /users/me
Output
Output ${me}
Should Be Equal As Strings ${res["body"]} ${me["body"]}
[Teardown] DELETE /auth/me

33
auth/robot/users.robot Normal file
View File

@ -0,0 +1,33 @@
*** Settings ***
Documentation Tests of the /users route.
... Ensures that the user can authenticate on kyoo.
Resource ../auth.resource
*** Test Cases ***
Me cant be accessed without an account
Get /users/me
Output
Integer response status 401
Register
[Documentation] Create a new user and login in it
Register user-1
[Teardown] DELETE /users/me
Register Duplicates
[Documentation] If two users tries to register with the same username, it fails
Register user-duplicate
# We can't use the `Register` keyword because it assert for success
POST /auth/register {"username": "user-duplicate", "password": "pass", "email": "mail@zoriya.dev"}
Output
Integer response status 409
[Teardown] DELETE /users/me
Delete Account
[Documentation] Check if a user can delete it's account
Register I-should-be-deleted
DELETE /users/me
Output
Integer response status 200

View File

@ -80,4 +80,3 @@ Login
Should Be Equal As Strings ${res["body"]} ${me["body"]}
[Teardown] DELETE /auth/me

45
pyproject.toml Normal file
View File

@ -0,0 +1,45 @@
[tool.robotidy]
diff = false
overwrite = true
verbose = false
separator = "space"
spacecount = 2
line_length = 120
lineseparator = "native"
skip_gitignore = true
ignore_git_dir = true
configure = [
"AddMissingEnd:enabled=True",
"NormalizeSeparators:enabled=True",
"DiscardEmptySections:enabled=True",
"MergeAndOrderSections:enabled=True",
"RemoveEmptySettings:enabled=True",
"ReplaceEmptyValues:enabled=True",
"ReplaceWithVAR:enabled=False",
"NormalizeAssignments:enabled=True",
"GenerateDocumentation:enabled=False",
"OrderSettings:enabled=True",
"OrderSettingsSection:enabled=True",
"NormalizeTags:enabled=True",
"OrderTags:enabled=False",
"RenameVariables:enabled=False",
"IndentNestedKeywords:enabled=False",
"AlignSettingsSection:enabled=True",
"AlignVariablesSection:enabled=True",
"AlignTemplatedTestCases:enabled=False",
"AlignTestCasesSection:enabled=False",
"AlignKeywordsSection:enabled=False",
"NormalizeNewLines:enabled=True",
"NormalizeSectionHeaderName:enabled=True",
"NormalizeSettingName:enabled=True",
"ReplaceRunKeywordIf:enabled=True",
"SplitTooLongLine:enabled=True",
"SmartSortKeywords:enabled=False",
"RenameTestCases:enabled=False",
"RenameKeywords:enabled=False",
"ReplaceReturns:enabled=True",
"ReplaceBreakContinue:enabled=True",
"InlineIf:enabled=True",
"Translate:enabled=False",
"NormalizeComments:enabled=True",
]

View File

@ -40,6 +40,7 @@ in
go-migrate
sqlc
go-swag
robotframework-tidy
];
DOTNET_ROOT = "${dotnet}";