From 442e7706880bba9a95404b4d04972674ad65d085 Mon Sep 17 00:00:00 2001 From: cvium Date: Wed, 17 Feb 2021 11:30:14 +0100 Subject: Validate the new username when renaming --- .../Jellyfin.Server.Implementations.Tests.csproj | 1 + .../Users/UserManagerTests.cs | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs (limited to 'tests') diff --git a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj index 174f29b09a..c3b3155fe9 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj +++ b/tests/Jellyfin.Server.Implementations.Tests/Jellyfin.Server.Implementations.Tests.csproj @@ -39,6 +39,7 @@ + diff --git a/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs new file mode 100644 index 0000000000..9bcd43bc03 --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs @@ -0,0 +1,28 @@ +using System; +using Jellyfin.Server.Implementations.Users; +using Xunit; + +namespace Jellyfin.Server.Implementations.Tests.Users +{ + public class UserManagerTests + { + [Theory] + [InlineData("this_is_valid", true)] + [InlineData("this is also valid", true)] + [InlineData(" ", false)] + [InlineData("", false)] + [InlineData("0@_-' .", true)] + public void ThrowIfInvalidUsername_WhenInvalidUsername_ThrowsArgumentException(string username, bool isValid) + { + var ex = Record.Exception(() => UserManager.ThrowIfInvalidUsername(username)); + + var argumentExceptionNotThrown = ex is not ArgumentException; + if (ex != null) + { + Assert.Equal(typeof(ArgumentException), ex.GetType()); + } + + Assert.Equal(isValid, argumentExceptionNotThrown); + } + } +} -- cgit v1.2.3 From 2112d2a9a0004fc336345170f009fa843fe374e9 Mon Sep 17 00:00:00 2001 From: cvium Date: Wed, 17 Feb 2021 11:51:15 +0100 Subject: Restructure tests --- .../Users/UserManagerTests.cs | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs index 9bcd43bc03..867dda29d6 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Users/UserManagerTests.cs @@ -7,22 +7,22 @@ namespace Jellyfin.Server.Implementations.Tests.Users public class UserManagerTests { [Theory] - [InlineData("this_is_valid", true)] - [InlineData("this is also valid", true)] - [InlineData(" ", false)] - [InlineData("", false)] - [InlineData("0@_-' .", true)] - public void ThrowIfInvalidUsername_WhenInvalidUsername_ThrowsArgumentException(string username, bool isValid) + [InlineData("this_is_valid")] + [InlineData("this is also valid")] + [InlineData("0@_-' .")] + public void ThrowIfInvalidUsername_WhenValidUsername_DoesNotThrowArgumentException(string username) { var ex = Record.Exception(() => UserManager.ThrowIfInvalidUsername(username)); + Assert.Null(ex); + } - var argumentExceptionNotThrown = ex is not ArgumentException; - if (ex != null) - { - Assert.Equal(typeof(ArgumentException), ex.GetType()); - } - - Assert.Equal(isValid, argumentExceptionNotThrown); + [Theory] + [InlineData(" ")] + [InlineData("")] + [InlineData("special characters like & $ ? are not allowed")] + public void ThrowIfInvalidUsername_WhenInvalidUsername_ThrowsArgumentException(string username) + { + Assert.Throws(() => UserManager.ThrowIfInvalidUsername(username)); } } } -- cgit v1.2.3