-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to block certain users from registering accounts (#380)
Closes #378
- Loading branch information
Showing
7 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Realms; | ||
|
||
namespace Refresh.GameServer.Types.UserData; | ||
|
||
public partial class DisallowedUser : IRealmObject | ||
{ | ||
[PrimaryKey] | ||
public string Username { get; set; } | ||
Check warning on line 8 in Refresh.GameServer/Types/UserData/DisallowedUser.cs GitHub Actions / Build, Test, and Upload Builds
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using Refresh.GameServer.Authentication; | ||
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes; | ||
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes.Errors; | ||
using Refresh.GameServer.Endpoints.ApiV3.DataTypes.Request.Authentication; | ||
using Refresh.GameServer.Endpoints.ApiV3.DataTypes.Response; | ||
using Refresh.GameServer.Types.UserData; | ||
using RefreshTests.GameServer.Extensions; | ||
|
@@ -22,6 +23,48 @@ public void GetsUserByUsername() | |
Assert.That(response, Is.Not.Null); | ||
response!.AssertErrorIsEqual(ApiNotFoundError.UserMissingError); | ||
} | ||
|
||
[Test] | ||
public void RegisterAccount() | ||
{ | ||
using TestContext context = this.GetServer(); | ||
|
||
const string username = "a_lil_guy"; | ||
|
||
ApiResponse<ApiAuthenticationResponse>? response = context.Http.PostData<ApiAuthenticationResponse>("/api/v3/register", new ApiRegisterRequest | ||
{ | ||
Username = username, | ||
EmailAddress = "[email protected]", | ||
PasswordSha512 = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", | ||
}); | ||
Assert.That(response, Is.Not.EqualTo(null)); | ||
|
||
context.Database.Refresh(); | ||
Assert.That(context.Database.GetUserByUsername(username), Is.Not.EqualTo(null)); | ||
} | ||
|
||
[Test] | ||
public void CannotRegisterAccountWithDisallowedUsername() | ||
{ | ||
using TestContext context = this.GetServer(); | ||
|
||
const string username = "a_lil_guy"; | ||
|
||
context.Database.DisallowUser(username); | ||
|
||
ApiResponse<ApiAuthenticationResponse>? response = context.Http.PostData<ApiAuthenticationResponse>("/api/v3/register", new ApiRegisterRequest | ||
{ | ||
Username = username, | ||
EmailAddress = "[email protected]", | ||
PasswordSha512 = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", | ||
}); | ||
Assert.That(response, Is.Not.EqualTo(null)); | ||
Assert.That(response.Error, Is.Not.EqualTo(null)); | ||
Assert.That(response.Error.Name, Is.EqualTo("ApiAuthenticationError")); | ||
|
||
context.Database.Refresh(); | ||
Assert.That(context.Database.GetUserByUsername(username), Is.EqualTo(null)); | ||
} | ||
|
||
[Test] | ||
public void GetsUserByUuid() | ||
|