Skip to content

Commit

Permalink
Consumer API: Use Consumer API SDK for integration tests (#659)
Browse files Browse the repository at this point in the history
* fix: consumer SDK generating paths witl backslashes

* chore: merge main

* feat: add password helper

* chore: add basic AccountController

* feat: identity creation using consumer sdk

* refactor: format and extract classes

* feat: complete example for challenges integration tests

* chore: refactor

* fix: not using DI Factory

* fix: cannot parse body when there is no body to parse

* chore: remove unused method

* refactor: when string

* refactor: specify api version in each route

* feat: factory methods for consumer api Client

* feat: add challenges steps with SDK

* chore: fix merge

* chore: code review fixes

* fix: missing using

* chore: formatting

* chore: move PasswordHelper

* chore: remove accountController

* chore: identityPublicKey should be passed as a Bas64 string

* fix: using bad dsk method for challenge creation

* chore: ensure empty payloads do not break the sdk

* chore: code review changes

* refactor: use fluent assertion extensions and fix challenge creation with byte representation

* chore: remove unauthorized integration test

* refactor: GivenTheUserIsAuthenticated

* refactor: remove exception handling for response deserialization

* chore: revert changes to test appsettings

* chore: remove default _sdk variable for ChallengesApiStepDefinitions

* test: add consumer api integration tests with SDK

* fix: post merge fixes

* fix: add byte array converter to consumer api

* refactor: use UrlSafeBase64ToByteArrayJsonConverter and shift registration to building blocks SDK

* refactor: use null suppression for sdk

* refactor: use hardcoded password value

* ci: change publish pipeline name

* refactor: rename token response field in case of unauthorized error

* refactor: remove unused parameter

* fix: challenges test referencing non existent step definition

* refactor: rename step definition

* refactor: rename step definition for admin api integration tests

* refactor: reuse step definition with different regex to improve readability

* refactor: use regex to avoid multiple attributes

* refactor: introduce global constant for device password

* refactor: remove unused step definition

---------

Co-authored-by: Daniel Silva <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Timo Notheisen <[email protected]>
  • Loading branch information
4 people authored May 22, 2024
1 parent fec3d4c commit 70ac464
Show file tree
Hide file tree
Showing 67 changed files with 308 additions and 1,182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Helm Chart
name: Publish

on:
push:
Expand Down
2 changes: 0 additions & 2 deletions AdminApi.Sdk/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Backbone.AdminApi.Sdk.Endpoints.Relationships;
using Backbone.AdminApi.Sdk.Endpoints.Tiers;
using Backbone.BuildingBlocks.SDK.Endpoints.Common;
using Backbone.Tooling.JsonConverters;

namespace Backbone.AdminApi.Sdk;

Expand All @@ -21,7 +20,6 @@ private Client(HttpClient httpClient, string apiKey)
var authenticator = new XsrfAndApiKeyAuthenticator(apiKey, httpClient);

var jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
jsonSerializerOptions.Converters.Add(new UrlSafeBase64ToByteArrayJsonConverter());

var endpointClient = new EndpointClient(httpClient, authenticator, jsonSerializerOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Deleting a non-existent Client
Given a non-existent Client c
When a DELETE request is sent to the /Clients endpoint
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Scenario: Changing the client secret of an existing Client with an empty secret
Scenario: Changing the client secret of a non-existent Client
When a PATCH request is sent to the /Clients/{clientId}/ChangeSecret endpoint
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Scenario: Changing the default tier of an existing Client with a non-existent ti
Given a Client c
When a PUT request is sent to the /Clients/{c.ClientId} endpoint with a non-existent tier id
Then the response status code is 400 (Bad request)
And the response content includes an error with the error code "error.platform.validation.device.tierIdInvalidOrDoesNotExist"
And the response content contains an error with the error code "error.platform.validation.device.tierIdInvalidOrDoesNotExist"

Scenario: Changing the default tier of a non-existing Client
When a PUT request is sent to the /Clients/{c.clientId} endpoint with a non-existing clientId
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Scenario: There can only be one active deletion process
And an active deletion process for Identity i exists
When a POST request is sent to the /Identities/{i.id}/DeletionProcesses endpoint
Then the response status code is 400 (Bad Request)
And the response content includes an error with the error code "error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"
And the response content contains an error with the error code "error.platform.validation.device.onlyOneActiveDeletionProcessAllowed"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Deleting an inexistent Individual Quota
Given an Identity i
When a DELETE request is sent to the /Identities/{i.address}/Quotas/inexistentQuotaId endpoint
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Creating an Individual Quota for existing Identity
Scenario: Creating an Individual Quota for inexistent Identity
When a POST request is sent to the /Identity/{address}/Quotas endpoint with an inexistent identity address
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Scenario: Creating a Log
Scenario: Creating a Log with an invalid Log Level fails
When a POST request is sent to the /Logs endpoint with an invalid Log Level
Then the response status code is 400 (Bad Request)
And the response content includes an error with the error code "error.platform.validation.invalidPropertyValue"
And the response content contains an error with the error code "error.platform.validation.invalidPropertyValue"
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Scenario: Requesting an invalid type Message List of an Identity
Given an Identity i
When a GET request is sent to the /Messages endpoint with type 'InvalidType' and participant i.Address
Then the response status code is 400 (Bad request)
And the response content includes an error with the error code "error.platform.validation.invalidPropertyValue"
And the response content contains an error with the error code "error.platform.validation.invalidPropertyValue"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Deleting an inexistent Tier Quota
Given a Tier t
When a DELETE request is sent to the /Tiers/{t.id}/Quotas/{quotaId} endpoint with an inexistent quota id
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Creating a Tier Quota for existing Tier
Scenario: Creating a Tier Quota for inexistent Tier
When a POST request is sent to the /Tiers/{tierId}/Quotas endpoint with an inexistent tier id
Then the response status code is 404 (Not Found)
And the response content includes an error with the error code "error.platform.recordNotFound"
And the response content contains an error with the error code "error.platform.recordNotFound"
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Scenario: Creating a Tier with a name that already exists
Given a Tier t
When a POST request is sent to the /Tiers endpoint with the name t.Name
Then the response status code is 400 (Bad Request)
And the response content includes an error with the error code "error.platform.validation.device.tierNameAlreadyExists"
And the response content contains an error with the error code "error.platform.validation.device.tierNameAlreadyExists"
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void ThenTheResponseStatusCodeIs(int expectedStatusCode)
((int)_updateClientResponse!.Status).Should().Be(expectedStatusCode);
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
if (_getClientsResponse != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void ThenTheResponseStatusCodeIs(int expectedStatusCode)
((int)_identityDeletionProcessResponse!.Status).Should().Be(expectedStatusCode);
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
if (_identityResponse != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ThenTheResponseContainsAnIndividualQuota()
_createQuotaResponse.Should().ComplyWithSchema();
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
if (_createQuotaResponse != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void ThenTheResponseStatusCodeIs(int expectedStatusCode)
((int)_postResponse!.Status).Should().Be(expectedStatusCode);
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
_postResponse!.Error.Should().NotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void ThenTheResponseContainsAListOfMessages()
_messagesResponse.Should().ComplyWithSchema();
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
if (_messagesResponse != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void ThenTheResponseContainsATierQuotaDefinition()
_createTierQuotaResponse.Should().ComplyWithSchema();
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
if (_createTierQuotaResponse != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void ThenTheResponseStatusCodeIs(int expectedStatusCode)
((int)_deleteResponse!.Status).Should().Be(expectedStatusCode);
}

[Then(@"the response content includes an error with the error code ""([^""]+)""")]
[Then(@"the response content contains an error with the error code ""([^""]+)""")]
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode)
{
_tierResponse!.Error.Should().NotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.16" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tooling\Tooling.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using System.Web;
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types;
using Backbone.Tooling.JsonConverters;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace Backbone.BuildingBlocks.SDK.Endpoints.Common;
Expand Down Expand Up @@ -33,6 +34,7 @@ public EndpointClient(HttpClient httpClient, IAuthenticator authenticator, JsonS
_httpClient = httpClient;
_authenticator = authenticator;
_jsonSerializerOptions = jsonSerializerOptions;
jsonSerializerOptions.Converters.Add(new UrlSafeBase64ToByteArrayJsonConverter());
}

public async Task<ApiResponse<T>> Post<T>(string url, object? requestContent = null)
Expand Down
5 changes: 5 additions & 0 deletions ConsumerApi.Sdk/Endpoints/Tokens/TokensEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public async Task<ApiResponse<CreateTokenResponse>> CreateToken(CreateTokenReque
return await _client.Post<CreateTokenResponse>($"api/{API_VERSION}/Tokens", request);
}

public async Task<ApiResponse<EmptyResponse>> CreateTokenUnauthenticated(CreateTokenRequest request)
{
return await _client.PostUnauthenticated<EmptyResponse>($"api/{API_VERSION}/Tokens", request);
}

public async Task<ApiResponse<ListTokensResponse>> ListTokens(PaginationFilter? pagination = null)
{
return await _client.Get<ListTokensResponse>($"api/{API_VERSION}/Tokens", null, pagination);
Expand Down
150 changes: 0 additions & 150 deletions ConsumerApi.Tests.Integration/API/BaseApi.cs

This file was deleted.

13 changes: 0 additions & 13 deletions ConsumerApi.Tests.Integration/API/ChallengesApi.cs

This file was deleted.

23 changes: 0 additions & 23 deletions ConsumerApi.Tests.Integration/API/DevicesApi.cs

This file was deleted.

Loading

0 comments on commit 70ac464

Please sign in to comment.