Skip to content

Commit

Permalink
Move CredentialTests to TokenEndpointTests where appropriate, improve…
Browse files Browse the repository at this point in the history
… constructors by throwing exception when null is provided as argument
  • Loading branch information
RobinTTY committed Apr 20, 2024
1 parent c1f7ba7 commit 4f5f99c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
16 changes: 0 additions & 16 deletions src/RobinTTY.NordigenApiClient.Tests/LiveApi/CredentialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ public async Task MakeRequestWithInvalidCredentials()
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
var apiClient = new NordigenClient(httpClient, invalidCredentials);

// Returns BasicError
var agreementsResponse = await apiClient.AgreementsEndpoint.GetAgreements(10, 0);
Assert.Multiple(() =>
{
Assert.That(agreementsResponse.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
AssertErrorMatchesExpectation(agreementsResponse.Error!);
});

// Returns InstitutionsError
var institutionResponse = await apiClient.InstitutionsEndpoint.GetInstitutions();
Assert.Multiple(() =>
{
Assert.That(institutionResponse.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
AssertErrorMatchesExpectation(institutionResponse.Error!);
});

// Returns AccountsError
var balancesResponse = await apiClient.AccountsEndpoint.GetBalances(_secrets[9]);
Assert.Multiple(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,26 @@ public async Task ReuseExpiredToken()
var result = await apiClient.RequisitionsEndpoint.GetRequisitions(10, 0);
AssertionHelpers.AssertNordigenApiResponseIsSuccessful(result, HttpStatusCode.OK);
}

/// <summary>
/// Tests the failure of authentication when trying to get a new token pair.
/// </summary>
[Test]
public async Task GetTokenPairWithInvalidCredentials()
{
using var httpClient = new HttpClient();
var invalidCredentials = new NordigenClientCredentials("01234567-89ab-cdef-0123-456789abcdef",
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
var apiClient = new NordigenClient(httpClient, invalidCredentials);

// Returns BasicError
var agreementsResponse = await apiClient.AgreementsEndpoint.GetAgreements(10, 0);
Assert.Multiple(() =>
{
Assert.That(agreementsResponse.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
AssertionHelpers.AssertNordigenApiResponseIsUnsuccessful(agreementsResponse, HttpStatusCode.Unauthorized);
AssertionHelpers.AssertBasicResponseMatchesExpectations(agreementsResponse.Error, "Authentication failed",
"No active account found with the given credentials");
});
}
}
4 changes: 2 additions & 2 deletions src/RobinTTY.NordigenApiClient/Models/Jwt/JsonWebTokenPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class JsonWebTokenPair
[JsonConstructor]
public JsonWebTokenPair(JsonWebToken accessToken, JsonWebToken refreshToken, int accessExpires, int refreshExpires)
{
AccessToken = accessToken;
RefreshToken = refreshToken;
AccessToken = accessToken ?? throw new ArgumentNullException(nameof(accessToken));
RefreshToken = refreshToken ?? throw new ArgumentNullException(nameof(refreshToken));
AccessExpires = accessExpires;
RefreshExpires = refreshExpires;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class NordigenClientCredentials
/// <param name="secretKey">Secret Nordigen key.</param>
public NordigenClientCredentials(string secretId, string secretKey)
{
SecretId = secretId;
SecretKey = secretKey;
SecretId = secretId ?? throw new ArgumentNullException(nameof(secretId));
SecretKey = secretKey ?? throw new ArgumentNullException(nameof(secretKey));
}
}

0 comments on commit 4f5f99c

Please sign in to comment.