Convert robot tests to hurl

This commit is contained in:
Zoe Roux 2025-04-04 23:28:03 +02:00
parent c5a676b2a5
commit 6d8697cd9d
No known key found for this signature in database
9 changed files with 120 additions and 133 deletions

View File

@ -1,4 +1,4 @@
name: RobotTests
name: HurlTests
on:
push:
branches:
@ -9,7 +9,7 @@ on:
jobs:
test:
name: Robot tests Auth
name: Hurl tests Auth
runs-on: ubuntu-latest
services:
postgres:
@ -27,13 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Robot cache
uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip'
- run: pip install -r requirements.txt
- uses: gacts/install-hurl@v1
- uses: actions/setup-go@v5
with:
@ -44,22 +38,18 @@ jobs:
working-directory: ./auth
run: |
go mod download
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go install github.com/swaggo/swag/cmd/swag@latest
- name: Build
working-directory: ./auth
run: |
sqlc generate
swag init --parseDependency
go build -o ./keibi
- name: Run robot tests
- name: Run hurl tests
working-directory: ./auth
run: |
./keibi > logs &
wget --retry-connrefused --retry-on-http-error=502 http://localhost:4568/health
robot -d out robot
hurl --variable host=http://localhost:4568 tests/*
env:
POSTGRES_SERVER: localhost

View File

@ -1,43 +0,0 @@
*** Settings ***
Documentation Common things to handle rest requests
Library REST http://localhost:4568
*** Keywords ***
Login
[Documentation] Shortcut to login with the given username for future requests
[Arguments] ${username}
&{res}= POST /sessions {"login": "${username}", "password": "password-${username}"}
Output
Integer response status 201
String response body 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.body.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": ""}

View File

@ -1,36 +0,0 @@
*** 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 404
Invalid password
[Documentation] Login fails if password is invalid
Register invalid-password-user
POST /sessions {"login": "invalid-password-user", "password": "pass"}
Output
Integer response status 403
[Teardown] DELETE /users/me
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 /users/me

View File

@ -1,33 +0,0 @@
*** 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 /users {"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

19
auth/tests/basic.hurl Normal file
View File

@ -0,0 +1,19 @@
# Bad Account (login fails if user does not exist)
POST {{host}}/sessions
{
"login": "i-don-t-exist",
"password": "pass"
}
HTTP 404
# Invalid password
POST {{host}}/sessions
{
"login": "invalid-password-user",
"password": "pass"
}
HTTP 403
# Me cant be accessed without an account
GET {{host}}/users/me
HTTP 401

View File

@ -0,0 +1,54 @@
# Register a user for invalid password test
POST {{host}}/users
{
"username": "login-user",
"password": "password-login-user",
"email": "invalid-password-user@zoriya.dev"
}
HTTP 201
[Captures]
token: jsonpath "$.token"
GET {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 200
[Captures]
jwt: jsonpath "$.token"
GET {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200
[Captures]
register_info: body
[Asserts]
jsonpath "$.username" == "login-user"
DELETE {{host}}/sessions/current
Authorization: Bearer {{jwt}}
HTTP 200
POST {{hosts}}/sessions
{
"login": "login-user",
"password": "password-login-user"
}
HTTP 201
[Captures]
jwt: jsonpath "$.token"
GET {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 200
[Captures]
jwt: jsonpath "$.token"
GET {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200
[Asserts]
jsonpath "$.username" == "login-user"
body == {{register_info}}
DELETE {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200

41
auth/tests/users.hurl Normal file
View File

@ -0,0 +1,41 @@
# Setup
POST {{host}}/users
{
"username": "user-1",
"password": "password-user-1",
"email": "user-1@zoriya.dev"
}
HTTP 201
[Captures]
token: jsonpath "$.token"
GET {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 200
[Captures]
jwt: jsonpath "$.token"
# Duplicates usernames
POST {{host}}/users
{
"username": "user-1",
"password": "password-user-duplicate",
"email": "user-duplicate@zoriya.dev"
}
HTTP 409
# Duplicates email
POST {{host}}/users
{
"username": "user-duplicate",
"password": "pass",
"email": "user-1@zoriya.dev"
}
HTTP 409
DELETE {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200

View File

@ -1,2 +0,0 @@
robotframework
RESTinstance

View File

@ -11,9 +11,6 @@
dataclasses-json
msgspec
langcodes
# robotframework
# restinstance needs to be packaged
]);
dotnet = with pkgs.dotnetCorePackages;
combinePackages [
@ -40,11 +37,11 @@ in
go-migrate
sqlc
go-swag
# robotframework-tidy
bun
pkg-config
node-gyp
vips
hurl
];
DOTNET_ROOT = "${dotnet}";