Skip to content

Commit

Permalink
Reorganize Token tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Sep 16, 2023
1 parent 01fb12f commit 9bb96d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,10 @@

namespace GuildWars2.Tests.Features.Tokens;

public class TokenProviderTest
public class SubtokenInfo
{
[Fact]
public async Task It_can_get_the_token_info_for_an_api_key()
{
var sut = Composer.Resolve<Gw2Client>();
var accessToken = Composer.Resolve<ApiKey>();

var actual = await sut.TokenProvider.GetTokenInfo(accessToken.Key);

var apiKey = Assert.IsType<ApiKeyInfo>(actual.Value);

Assert.NotEmpty(apiKey.Id);

// Your API key must be named GW2SDK-Full to pass this test
// This is not intended to improve account security, only to prevent key abuse
// The reason is that some services like GW2BLTC.com associate keys with logins but require you to use a key name of their choice
// If this key leaks to the outside world, it can't be (ab)used to login with GW2BLTC.com or similar sites
Assert.Equal("GW2SDK-Full", apiKey.Name);

var expectedPermissions = Enum.GetValues(typeof(Permission)).Cast<Permission>().ToHashSet();

Assert.Equal(expectedPermissions, apiKey.Permissions.ToHashSet());
}

[Fact]
public async Task It_can_get_the_token_info_for_a_subtoken()
public async Task Subtoken_has_info()
{
var sut = Composer.Resolve<Gw2Client>();
var accessToken = Composer.Resolve<ApiKey>();
Expand Down Expand Up @@ -71,7 +48,7 @@ public async Task It_can_get_the_token_info_for_a_subtoken()

var actual = await sut.TokenProvider.GetTokenInfo(createdSubtoken.Value.Subtoken);

var subtoken = Assert.IsType<SubtokenInfo>(actual.Value);
var subtoken = Assert.IsType<GuildWars2.Tokens.SubtokenInfo>(actual.Value);

Assert.NotEmpty(subtoken.Id);

Expand Down
34 changes: 34 additions & 0 deletions GW2SDK.Tests/Features/Tokens/TokenInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using GuildWars2.Tests.TestInfrastructure;
using GuildWars2.Tokens;
using Xunit;

namespace GuildWars2.Tests.Features.Tokens;

public class TokenInfo
{
[Fact]
public async Task Token_has_info()
{
var sut = Composer.Resolve<Gw2Client>();
var accessToken = Composer.Resolve<ApiKey>();

var actual = await sut.TokenProvider.GetTokenInfo(accessToken.Key);

var apiKey = Assert.IsType<ApiKeyInfo>(actual.Value);

Assert.NotEmpty(apiKey.Id);

// Your API key must be named GW2SDK-Full to pass this test
// This is not intended to improve account security, only to prevent key abuse
// The reason is that some services like GW2BLTC.com associate keys with logins but require you to use a key name of their choice
// If this key leaks to the outside world, it can't be (ab)used to login with GW2BLTC.com or similar sites
Assert.Equal("GW2SDK-Full", apiKey.Name);

var expectedPermissions = Enum.GetValues(typeof(Permission)).Cast<Permission>().ToHashSet();

Assert.Equal(expectedPermissions, apiKey.Permissions.ToHashSet());
}
}

0 comments on commit 9bb96d8

Please sign in to comment.