67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using Helpdesk.Application.Auth;
|
|||
|
|
using Helpdesk.Domain;
|
||
|
|
using Helpdesk.Domain.Auth;
|
||
|
|
using Helpdesk.Domain.Users;
|
||
|
|
|
||
|
|
namespace Helpdesk.UnitTests;
|
||
|
|
|
||
|
|
public class EnumCodeTests
|
||
|
|
{
|
||
|
|
[Theory]
|
||
|
|
[InlineData(UserRole.Student, "STUDENT")]
|
||
|
|
[InlineData(UserRole.FacilityManager, "FACILITY_MANAGER")]
|
||
|
|
[InlineData(UserRole.Management, "MANAGEMENT")]
|
||
|
|
public void UserRole_ma_kod_odpovidajici_check_omezeni(UserRole role, string code)
|
||
|
|
{
|
||
|
|
Assert.Equal(code, role.ToCode());
|
||
|
|
Assert.Equal(role, EnumCode.Parse<UserRole>(code));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Theory]
|
||
|
|
[InlineData(TokenType.EmailConfirm, "EMAIL_CONFIRM")]
|
||
|
|
[InlineData(TokenType.PasswordReset, "PASSWORD_RESET")]
|
||
|
|
[InlineData(RevokeReason.ReuseDetected, "REUSE_DETECTED")]
|
||
|
|
[InlineData(RevokeReason.LogoutAll, "LOGOUT_ALL")]
|
||
|
|
public void Kody_tokenu_odpovidaji_check_omezeni(object value, string code)
|
||
|
|
{
|
||
|
|
var actual = value switch
|
||
|
|
{
|
||
|
|
TokenType t => t.ToCode(),
|
||
|
|
RevokeReason r => r.ToCode(),
|
||
|
|
_ => throw new ArgumentException(null, nameof(value)),
|
||
|
|
};
|
||
|
|
Assert.Equal(code, actual);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Neznamy_kod_neprojde() => Assert.False(EnumCode.TryParse<UserRole>("SUPERUSER", out _));
|
||
|
|
}
|
||
|
|
|
||
public class UserTests
|
|||
{
|
|||
|
|
[Fact]
|
||
|
|
public void Email_se_normalizuje_pro_jednoznacne_vyhledani() =>
|
||
Assert.Equal("[email protected]", User.Create("[email protected]", "hash", "Jan", "Novák", UserRole.Student).EmailNormalized);
|
|||
}
|
|||
|
|
|
||
|
|
public class RegistrationRoleTests
|
||
|
|
{
|
||
|
|
private readonly RegistrationOptions _options = new()
|
||
|
|
{
|
||
|
|
StudentEmailDomains = ["student.univerzita.cz"],
|
||
|
|
TeacherEmailDomains = ["univerzita.cz"],
|
||
|
|
};
|
||
|
|
|
||
|
|
[Theory]
|
||
|
|
[InlineData("[email protected]", UserRole.Student)]
|
||
|
|
[InlineData("[email protected]", UserRole.Teacher)]
|
||
|
|
[InlineData("[email protected]", UserRole.Teacher)]
|
||
|
|
public void Role_se_urci_podle_domeny(string email, UserRole expected) =>
|
||
|
|
Assert.Equal(expected, _options.ResolveRole(email));
|
||
|
|
|
||
|
|
[Theory]
|
||
|
|
[InlineData("[email protected]")]
|
||
|
|
[InlineData("[email protected]")]
|
||
|
|
[InlineData("bez-zavinace")]
|
||
|
|
public void Cizi_domena_registraci_neumozni(string email) => Assert.Null(_options.ResolveRole(email));
|
||
|
|
}
|