aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs
blob: 4cea53bd3da945cb3fcaa36d6494814cf2b69526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using Jellyfin.Server.Implementations.Users;
using Xunit;

namespace Jellyfin.Server.Implementations.Tests.Users
{
    public class UserManagerTests
    {
        [Theory]
        [InlineData("this_is_valid")]
        [InlineData("this is also valid")]
        [InlineData("0@_-' .")]
        [InlineData("Aa0@_-' .+")]
        [InlineData("thisisa+testemail@test.foo")]
        [InlineData("------@@@--+++----@@--abcdefghijklmn---------@----_-_-___-_ .9foo+")]
        public void ThrowIfInvalidUsername_WhenValidUsername_DoesNotThrowArgumentException(string username)
        {
            var ex = Record.Exception(() => UserManager.ThrowIfInvalidUsername(username));
            Assert.Null(ex);
        }

        [Theory]
        [InlineData(" ")]
        [InlineData("")]
        [InlineData("special characters like & $ ? are not allowed")]
        [InlineData("thishasaspaceontheend ")]
        [InlineData(" thishasaspaceatthestart")]
        [InlineData(" thishasaspaceatbothends ")]
        [InlineData(" this has a space at both ends and inbetween ")]
        public void ThrowIfInvalidUsername_WhenInvalidUsername_ThrowsArgumentException(string username)
        {
            Assert.Throws<ArgumentException>(() => UserManager.ThrowIfInvalidUsername(username));
        }
    }
}