diff --git a/.github/workflows/robot_auth.yml b/.github/workflows/auth.yml similarity index 72% rename from .github/workflows/robot_auth.yml rename to .github/workflows/auth.yml index 9a821059..9d06b5e2 100644 --- a/.github/workflows/robot_auth.yml +++ b/.github/workflows/auth.yml @@ -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 diff --git a/auth/robot/auth.resource b/auth/robot/auth.resource deleted file mode 100644 index 2e469ecd..00000000 --- a/auth/robot/auth.resource +++ /dev/null @@ -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": ""} diff --git a/auth/robot/sessions.robot b/auth/robot/sessions.robot deleted file mode 100644 index 6f6b7f1b..00000000 --- a/auth/robot/sessions.robot +++ /dev/null @@ -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 diff --git a/auth/robot/users.robot b/auth/robot/users.robot deleted file mode 100644 index 603fd1ec..00000000 --- a/auth/robot/users.robot +++ /dev/null @@ -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 diff --git a/auth/tests/basic.hurl b/auth/tests/basic.hurl new file mode 100644 index 00000000..df70fa68 --- /dev/null +++ b/auth/tests/basic.hurl @@ -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 diff --git a/auth/tests/invalid-password.hurl b/auth/tests/invalid-password.hurl new file mode 100644 index 00000000..7c51f14b --- /dev/null +++ b/auth/tests/invalid-password.hurl @@ -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 diff --git a/auth/tests/users.hurl b/auth/tests/users.hurl new file mode 100644 index 00000000..8e840a12 --- /dev/null +++ b/auth/tests/users.hurl @@ -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 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index f9abbc78..00000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -robotframework -RESTinstance diff --git a/shell.nix b/shell.nix index b6a13543..b7ce3bfb 100644 --- a/shell.nix +++ b/shell.nix @@ -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}";