Skip to content

Commit

Permalink
Add authN/authZ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim committed Oct 16, 2024
1 parent f2ef212 commit 3041388
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions LeaderboardBackend.Test/Leaderboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,41 @@ public async Task RestoreLeaderboard_OK()
res.DeletedAt.Should().BeNull();
}

[Test]
public async Task RestoreLeaderboard_Unauthenticated()
{
Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Put<LeaderboardViewModel>($"/leaderboard/100/restore", new()
{
Jwt = ""
});

await act.Should().ThrowAsync<RequestFailureException>().Where(e => e.Response.StatusCode == HttpStatusCode.Unauthorized);
}

[Test]
public async Task RestoreLeaderboard_Unauthorized()
{
IUserService userService = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<IUserService>();

RegisterRequest registerRequest = new()
{
Email = "[email protected]",
Password = "Passw0rd",
Username = "unauthorized"
};

await userService.CreateUser(registerRequest);

string jwt = (await _apiClient.LoginUser(registerRequest.Email, registerRequest.Password)).Token;

Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Put<LeaderboardViewModel>($"/leaderboard/100/restore", new()
{
Jwt = jwt,
});

await act.Should().ThrowAsync<RequestFailureException>().Where(e => e.Response.StatusCode == HttpStatusCode.Forbidden);
}

[Test]
public async Task RestoreLeaderboard_NotFound()
{
Expand Down

0 comments on commit 3041388

Please sign in to comment.