Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CoinbaseAdvancedTradeClient.Authentication;
using CoinbaseAdvancedTradeClient.UnitTests.TestHelpers;
using Xunit;

namespace CoinbaseAdvancedTradeClient.UnitTests.Authentication
{
public class SecretApiKeyAuthenticatorTests
{
[Fact]
public void GenerateBearerJWT_ValidParameters_ReturnsJWT()
{
// Arrange
var testKeySecret = TestConfigHelper.GenerateTestKeySecret();

// Act & Assert - Should not throw exception
var jwt = SecretApiKeyAuthenticator.GenerateBearerJWT(
"test-key-name",
testKeySecret,
"GET",
"api.coinbase.com",
"/v1/test"
);

// Basic JWT format validation
Assert.NotNull(jwt);
Assert.Contains(".", jwt);
var parts = jwt.Split('.');
Assert.Equal(3, parts.Length); // header.payload.signature
}

[Fact]
public void GenerateBearerJWT_InvalidKeySecret_ThrowsArgumentException()
{
// Act & Assert
Assert.Throws<ArgumentException>(() =>
{
SecretApiKeyAuthenticator.GenerateBearerJWT(
"test-key-name",
"invalid-key-format",
"GET",
"api.coinbase.com",
"/v1/test"
);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CoinbaseAdvancedTradeClient.Models.Config;
using CoinbaseAdvancedTradeClient.UnitTests.TestHelpers;
using Xunit;

namespace CoinbaseAdvancedTradeClient.UnitTests
Expand All @@ -9,7 +10,7 @@ public class CoinbaseAdvancedTradeApiClientTests
public void Constructor_NullConfig_ThrowsArgumentNullException()
{
//Arrange
ApiClientConfig config = null;
SecretApiKeyConfig config = null;

//Act & Assert
Assert.Throws<ArgumentNullException>(() =>
Expand All @@ -27,10 +28,10 @@ public void Constructor_NullConfig_ThrowsArgumentNullException()
public void Constructor_EmptyConfigSetting_ThrowsArgumentException(string key, string secret)
{
//Arrange
ApiClientConfig config = new ApiClientConfig()
SecretApiKeyConfig config = new SecretApiKeyConfig()
{
ApiKey = key,
ApiSecret = secret
KeyName = key,
KeySecret = string.IsNullOrWhiteSpace(secret) ? secret : TestConfigHelper.GenerateTestKeySecret()
};

//Act & Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

<ItemGroup>
<PackageReference Include="FakeItEasy" Version="8.3.0" />
<PackageReference Include="Flurl.Http" Version="3.2.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading
Loading