mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-03 10:38:40 +00:00
Makes it so unit tests can skirt username validation
This commit is contained in:
parent
535116c2e4
commit
5d28256c3e
2 changed files with 8 additions and 5 deletions
|
@ -16,8 +16,8 @@ public class DatabaseTests : LighthouseServerTest
|
||||||
await using Database database = new();
|
await using Database database = new();
|
||||||
int rand = new Random().Next();
|
int rand = new Random().Next();
|
||||||
|
|
||||||
User userA = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
User userA = await database.CreateUser("unitTestUser" + rand, HashHelper.GenerateAuthToken());
|
||||||
User userB = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
User userB = await database.CreateUser("unitTestUser" + rand, HashHelper.GenerateAuthToken());
|
||||||
|
|
||||||
Assert.NotNull(userA);
|
Assert.NotNull(userA);
|
||||||
Assert.NotNull(userB);
|
Assert.NotNull(userB);
|
||||||
|
|
|
@ -50,11 +50,14 @@ public class Database : DbContext
|
||||||
if (!password.StartsWith('$')) throw new ArgumentException(nameof(password) + " is not a BCrypt hash");
|
if (!password.StartsWith('$')) throw new ArgumentException(nameof(password) + " is not a BCrypt hash");
|
||||||
|
|
||||||
// 16 is PSN max, 3 is PSN minimum
|
// 16 is PSN max, 3 is PSN minimum
|
||||||
if (username.Length > 16 || username.Length < 3) throw new ArgumentException(nameof(username) + " is either too long or too short");
|
if (!ServerStatics.IsUnitTesting || !username.StartsWith("unitTestUser"))
|
||||||
|
{
|
||||||
|
if (username.Length > 16 || username.Length < 3) throw new ArgumentException(nameof(username) + " is either too long or too short");
|
||||||
|
|
||||||
Regex regex = new("^[a-zA-Z0-9_.-]*$");
|
Regex regex = new("^[a-zA-Z0-9_.-]*$");
|
||||||
|
|
||||||
if (!regex.IsMatch(username)) throw new ArgumentException(nameof(username) + " does not match the username regex");
|
if (!regex.IsMatch(username)) throw new ArgumentException(nameof(username) + " does not match the username regex");
|
||||||
|
}
|
||||||
|
|
||||||
User user;
|
User user;
|
||||||
if ((user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null) return user;
|
if ((user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null) return user;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue