Skip to content

Commit

Permalink
[DMS-444] Allow validating empty request bodies, add E2E tests for re…
Browse files Browse the repository at this point in the history
…gistration (#376)

* Allow validating empty request bodies, add E2E tests for registration

* More E2E

* Add unique run id per scenario

* Improve E2E state management

* Rename feature
  • Loading branch information
simpat-adam authored Dec 19, 2024
1 parent 769826a commit 8c55963
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class ValidatorExtensions
{
public static async Task GuardAsync<TRequest>(this IValidator<TRequest> validator, TRequest request)
{
request ??= Activator.CreateInstance<TRequest>();
var validationResult = await validator.ValidateAsync(request);

if (!validationResult.IsValid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Applications endpoints
Background:
Given valid credentials
And token received
And vendor created
And a POST request is made to "/v2/vendors" with
"""
{
"company": "Test Vendor 0",
Expand Down Expand Up @@ -95,14 +95,14 @@ Feature: Applications endpoints
And the response headers include
"""
{
"location": "/v2/applications/{id}"
"location": "/v2/applications/{applicationId}"
}
"""
And the response body has key and secret
And the record can be retrieved with a GET request
"""
{
"id": {id},
"id": {applicationId},
"applicationName": "Demo application",
"vendorId": {vendorId},
"claimSetName": "Claim 06",
Expand All @@ -123,11 +123,11 @@ Feature: Applications endpoints
And the response headers include
"""
{
"location": "/v2/applications/{id}"
"location": "/v2/applications/{applicationId}"
}
"""
And the response body has key and secret
When a PUT request is made to "/v2/applications/{id}/reset-credential" with
When a PUT request is made to "/v2/applications/{applicationId}/reset-credential" with
"""
{}
"""
Expand All @@ -144,10 +144,10 @@ Feature: Applications endpoints
}
"""
Then it should respond with 201
When a PUT request is made to "/v2/applications/{id}" with
When a PUT request is made to "/v2/applications/{applicationId}" with
"""
{
"id": {id},
"id": {applicationId},
"vendorId": {vendorId},
"applicationName": "Demo application Update",
"claimSetName": "Claim Scenario 03 Update"
Expand All @@ -165,7 +165,7 @@ Feature: Applications endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/applications/{id}"
When a DELETE request is made to "/v2/applications/{applicationId}"
Then it should respond with 204

Scenario: 06 Verify error handling when trying to get an item that has already been deleted
Expand All @@ -178,9 +178,9 @@ Feature: Applications endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/applications/{id}"
When a DELETE request is made to "/v2/applications/{applicationId}"
Then it should respond with 204
When a GET request is made to "/v2/applications/{id}"
When a GET request is made to "/v2/applications/{applicationId}"
Then it should respond with 404

Scenario: 07 Verify error handling when trying to update an item that has already been deleted
Expand All @@ -193,12 +193,12 @@ Feature: Applications endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/applications/{id}"
When a DELETE request is made to "/v2/applications/{applicationId}"
Then it should respond with 204
When a PUT request is made to "/v2/applications/{id}" with
When a PUT request is made to "/v2/applications/{applicationId}" with
"""
{
"id": {id},
"id": {applicationId},
"vendorId": {vendorId},
"applicationName": "Delete application update",
"claimSetName": "Claim Scenario 07"
Expand All @@ -216,9 +216,9 @@ Feature: Applications endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/applications/{id}"
When a DELETE request is made to "/v2/applications/{applicationId}"
Then it should respond with 204
When a DELETE request is made to "/v2/applications/{id}"
When a DELETE request is made to "/v2/applications/{applicationId}"
Then it should respond with 404

Scenario: 09 Verify error handling when trying to get an application using a invalid id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
Feature: Connect endpoints

Scenario: 00 Verify register new client
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
| ClientId | _scenarioRunId |
| ClientSecret | Secr3t:) |
| DisplayName | E2E |
Then it should respond with 200
And the response body is
"""
{
"title": "Registered client {scenarioRunId} successfully.",
"status": 200
}
"""

Scenario: 01 Verify already registered clients return 400
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
| ClientId | _scenarioRunId |
| ClientSecret | Secr3t:) |
| DisplayName | E2E |
Then it should respond with 200
And the response body is
"""
{
"title": "Registered client {scenarioRunId} successfully.",
"status": 200
}
"""
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
| ClientId | _scenarioRunId |
| ClientSecret | Secr3t:) |
| DisplayName | E2E |
Then it should respond with 400
And the response body is
"""
{
"detail": "Data validation failed. See 'validationErrors' for details.",
"type": "urn:ed-fi:api:bad-request:data-validation-failed",
"title": "Data Validation Failed",
"status": 400,
"validationErrors": {
"ClientId": [
"Client with the same Client Id already exists. Please provide different Client Id."
]
},
"errors": []
}
"""

Scenario: 02 Verify password requirements
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
| ClientId | _scenarioRunId |
| ClientSecret | weak |
| DisplayName | _scenarioRunId |
Then it should respond with 400
And the response body is
"""
{
"detail": "Data validation failed. See 'validationErrors' for details.",
"type": "urn:ed-fi:api:bad-request:data-validation-failed",
"title": "Data Validation Failed",
"status": 400,
"validationErrors": {
"ClientSecret": [
"Client secret must contain at least one lowercase letter, one uppercase letter, one number, and one special character, and must be 8 to 12 characters long."
]
},
"errors": []
}
"""

Scenario: 03 Verify empty post failure
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
Then it should respond with 400
And the response body is
"""
{
"detail": "Data validation failed. See 'validationErrors' for details.",
"type": "urn:ed-fi:api:bad-request:data-validation-failed",
"title": "Data Validation Failed",
"status": 400,
"validationErrors": {
"ClientId": [
"'Client Id' must not be empty."
],
"ClientSecret": [
"'Client Secret' must not be empty."
],
"DisplayName": [
"'Display Name' must not be empty."
]
},
"errors": []
}
"""
Scenario: 04 Verify token creation with registered client
When a Form URL Encoded POST request is made to "/connect/register" with
| Key | Value |
| ClientId | _scenarioRunId |
| ClientSecret | Secr3t:) |
| DisplayName | _scenarioRunId |
Then it should respond with 200
And the response body is
"""
{
"title": "Registered client {scenarioRunId} successfully.",
"status": 200
}
"""
When a Form URL Encoded POST request is made to "/connect/token" with
| Key | Value |
| client_id | _scenarioRunId |
| client_secret | Secr3t:) |
| grant_type | client_credentials |
| scope | edfi_admin_api/full_access |
Then it should respond with 200
And the response body is
"""
{
"access_token": "{access_token}",
"expires_in": 1800,
"token_type": "Bearer"
}
"""
When a Form URL Encoded POST request is made to "/connect/token" with
| Key | Value |
| client_id | _scenarioRunId |
| client_secret | wrong |
| grant_type | client_credentials |
| scope | edfi_admin_api/full_access |
Then it should respond with 401
And the response body is
"""
{
"detail":"{\"error\":\"unauthorized_client\",\"error_description\":\"Invalid client or Invalid client credentials\"}",
"type":"urn:ed-fi:api:security:authentication",
"title":"Authentication Failed",
"status":401,
"validationErrors":{},
"errors":[]
}
"""

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Feature: Vendors endpoints
And the response headers include
"""
{
"location": "/v2/vendors/{id}"
"location": "/v2/vendors/{vendorId}"
}
"""
And the record can be retrieved with a GET request
Expand All @@ -71,7 +71,7 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a GET request is made to "/v2/vendors/{id}"
When a GET request is made to "/v2/vendors/{vendorId}"
Then it should respond with 200
And the response body is
"""
Expand All @@ -95,10 +95,10 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a PUT request is made to "/v2/vendors/{id}" with
When a PUT request is made to "/v2/vendors/{vendorId}" with
"""
{
"id": {id},
"id": {vendorId},
"company": "Test 18 updated",
"contactName": "Test",
"contactEmailAddress": "[email protected]",
Expand Down Expand Up @@ -128,7 +128,7 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/vendors/{id}"
When a DELETE request is made to "/v2/vendors/{vendorId}"
Then it should respond with 204

Scenario: 06 Verify error handling when trying to get an item that has already been deleted
Expand All @@ -142,9 +142,9 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/vendors/{id}"
When a DELETE request is made to "/v2/vendors/{vendorId}"
Then it should respond with 204
When a GET request is made to "/v2/vendors/{id}"
When a GET request is made to "/v2/vendors/{vendorId}"
Then it should respond with 404

Scenario: 07 Verify error handling when trying to update an item that has already been deleted
Expand All @@ -158,12 +158,12 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/vendors/{id}"
When a DELETE request is made to "/v2/vendors/{vendorId}"
Then it should respond with 204
When a PUT request is made to "/v2/vendors/{id}" with
When a PUT request is made to "/v2/vendors/{vendorId}" with
"""
{
"id": {id},
"id": {vendorId},
"company": "Test 21 updated",
"contactName": "Test",
"contactEmailAddress": "[email protected]",
Expand All @@ -183,9 +183,9 @@ Feature: Vendors endpoints
}
"""
Then it should respond with 201
When a DELETE request is made to "/v2/vendors/{id}"
When a DELETE request is made to "/v2/vendors/{vendorId}"
Then it should respond with 204
When a DELETE request is made to "/v2/vendors/{id}"
When a DELETE request is made to "/v2/vendors/{vendorId}"
Then it should respond with 404

Scenario: 09 Verify error handling when trying to get a vendor using a invalid id
Expand Down Expand Up @@ -303,7 +303,7 @@ Feature: Vendors endpoints
"""

Scenario: 16 Verify vendor applications endpoint
Given vendor created
Given a POST request is made to "/v2/vendors" with
"""
{
"company": "Scenario 16",
Expand Down
Loading

0 comments on commit 8c55963

Please sign in to comment.