UserManagerTests.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using Jellyfin.Server.Implementations.Users;
  3. using Xunit;
  4. namespace Jellyfin.Server.Implementations.Tests.Users
  5. {
  6. public class UserManagerTests
  7. {
  8. [Theory]
  9. [InlineData("this_is_valid")]
  10. [InlineData("this is also valid")]
  11. [InlineData("0@_-' .")]
  12. [InlineData("Aa0@_-' .+")]
  13. [InlineData("thisisa+testemail@test.foo")]
  14. [InlineData("------@@@--+++----@@--abcdefghijklmn---------@----_-_-___-_ .9foo+")]
  15. public void ThrowIfInvalidUsername_WhenValidUsername_DoesNotThrowArgumentException(string username)
  16. {
  17. var ex = Record.Exception(() => UserManager.ThrowIfInvalidUsername(username));
  18. Assert.Null(ex);
  19. }
  20. [Theory]
  21. [InlineData(" ")]
  22. [InlineData("")]
  23. [InlineData("special characters like & $ ? are not allowed")]
  24. [InlineData("thishasaspaceontheend ")]
  25. [InlineData(" thishasaspaceatthestart")]
  26. [InlineData(" thishasaspaceatbothends ")]
  27. [InlineData(" this has a space at both ends and inbetween ")]
  28. public void ThrowIfInvalidUsername_WhenInvalidUsername_ThrowsArgumentException(string username)
  29. {
  30. Assert.Throws<ArgumentException>(() => UserManager.ThrowIfInvalidUsername(username));
  31. }
  32. }
  33. }