Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Add property based testing to auth API using schemathesis
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <[email protected]>
  • Loading branch information
rodneyosodo committed Jan 25, 2024
1 parent 9b8cab7 commit e7048bb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ env:
USERS_URL: http://localhost:9002
THINGS_URL: http://localhost:9000
INVITATIONS_URL: http://localhost:9020
AUTH_URL: http://localhost:8189

jobs:
api-test:
Expand Down Expand Up @@ -166,6 +167,16 @@ jobs:
report: false
args: '--header "Authorization: Bearer ${{ env.USER_TOKEN }}" --contrib-unique-data --contrib-openapi-formats-uuid --hypothesis-suppress-health-check=filter_too_much --stateful=links'

- name: Run Auth API tests
if: steps.changes.outputs.auth == 'true'
uses: schemathesis/action@v1
with:
schema: api/openapi/auth.yml
base-url: ${{ env.AUTH_URL }}
checks: all
report: false
args: '--header "Authorization: Bearer ${{ env.USER_TOKEN }}" --contrib-unique-data --contrib-openapi-formats-uuid --hypothesis-suppress-health-check=filter_too_much --stateful=links'

- name: Stop containers
if: always()
run: make run down args="-v"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ endef
test_api_users: TEST_API_URL := http://localhost:9002
test_api_things: TEST_API_URL := http://localhost:9000
test_api_invitations: TEST_API_URL := http://localhost:9020
test_api_auth: TEST_API_URL := http://localhost:8189

$(TEST_API):
$(call test_api_service,$(@),$(TEST_API_URL))
Expand Down
20 changes: 19 additions & 1 deletion api/openapi/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ paths:
$ref: "#/components/responses/ServiceError"
/keys:
post:
operationId: issueKey
tags:
- Keys
summary: Issue API key
Expand All @@ -341,6 +342,7 @@ paths:

/keys/{keyID}:
get:
operationId: getKey
summary: Gets API key details.
description: |
Gets API key details for the given key.
Expand All @@ -355,10 +357,13 @@ paths:
description: Failed due to malformed query parameters.
"401":
description: Missing or invalid access token provided.
"404":
description: A non-existent entity request.
"500":
$ref: "#/components/responses/ServiceError"

delete:
operationId: revokeKey
summary: Revoke API key
description: |
Revoke API key identified by the given ID.
Expand All @@ -371,11 +376,14 @@ paths:
description: Key revoked.
"401":
description: Missing or invalid access token provided.
"404":
description: A non-existent entity request.
"500":
$ref: "#/components/responses/ServiceError"

/policies:
post:
operationId: addPolicies
summary: Creates new policies.
description: |
Creates new policies. Only admin can use this endpoint. Therefore, you need an authentication token for the admin.
Expand All @@ -393,6 +401,8 @@ paths:
description: Missing or invalid access token provided.
"403":
description: Unauthorized access token provided.
"404":
description: A non-existent entity request.
"409":
description: Failed due to using an existing email address.
"415":
Expand All @@ -402,6 +412,7 @@ paths:

/policies/delete:
post:
operationId: deletePolicies
summary: Deletes policies.
description: |
Deletes policies. Only admin can use this endpoint. Therefore, you need an authentication token for the admin.
Expand All @@ -415,6 +426,8 @@ paths:
description: Policies deleted.
"400":
description: Failed due to malformed JSON.
"404":
description: A non-existent entity request.
"409":
description: Failed due to using an existing email address.
"415":
Expand Down Expand Up @@ -867,11 +880,16 @@ components:
application/json:
schema:
$ref: "#/components/schemas/Key"
links:
revoke:
operationId: revokeKey
parameters:
keyID: $response.body#/id

HealthRes:
description: Service Health Check.
content:
application/json:
application/health+json:
schema:
$ref: "./schemas/HealthInfo.yml"

Expand Down

0 comments on commit e7048bb

Please sign in to comment.