From f14ac4953dd90166d050136fc1a67aaaa88c45e5 Mon Sep 17 00:00:00 2001 From: mskor Date: Mon, 9 Dec 2024 23:47:55 +0000 Subject: [PATCH] Added (working) unit tests! --- Server/.idea/.idea.BackEnd/.idea/vcs.xml | 10 +- Server/Backend.Tests/Backend.Tests.csproj | 70 +++++----- Server/Backend.Tests/PasswordTests.cs | 150 +++++++++++----------- 3 files changed, 115 insertions(+), 115 deletions(-) diff --git a/Server/.idea/.idea.BackEnd/.idea/vcs.xml b/Server/.idea/.idea.BackEnd/.idea/vcs.xml index 6c0b863..2e3f692 100644 --- a/Server/.idea/.idea.BackEnd/.idea/vcs.xml +++ b/Server/.idea/.idea.BackEnd/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Server/Backend.Tests/Backend.Tests.csproj b/Server/Backend.Tests/Backend.Tests.csproj index a7691df..30f9db1 100644 --- a/Server/Backend.Tests/Backend.Tests.csproj +++ b/Server/Backend.Tests/Backend.Tests.csproj @@ -1,35 +1,35 @@ - - - - net7.0 - enable - enable - - false - true - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - Always - - - - + + + + net7.0 + enable + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + Always + + + + diff --git a/Server/Backend.Tests/PasswordTests.cs b/Server/Backend.Tests/PasswordTests.cs index c183750..fc0b935 100644 --- a/Server/Backend.Tests/PasswordTests.cs +++ b/Server/Backend.Tests/PasswordTests.cs @@ -1,76 +1,76 @@ -using back_end.Services; - -namespace Backend.Tests; - -public class PasswordTests -{ - private readonly PasswordService _passwordService; - - public PasswordTests() - { - _passwordService = new PasswordService(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"common-passwords.txt")); - } - - [Theory] - [InlineData("abcdefg",true)] - [InlineData("abcdef",false)] - [InlineData("abcdefghijklmn",true)] - [InlineData("abcdefghijklmno",false)] - public void PasswordLengthValid(string password, bool valid) - { - var check = _passwordService.IsPasswordLengthValid(password); - Assert.Equal(valid, check); - } - - [Theory] - [InlineData("password", false)] - [InlineData("password1", false)] - [InlineData("password!", false)] - [InlineData("password1!", true)] - public void PasswordContainsMinimumCharacters(string password, bool valid) - { - var check = _passwordService.IsPasswordContainingMinimumCharacters(password); - Assert.Equal(valid, check); - } - - [Theory] - [InlineData("password",true)] - [InlineData("password(",false)] - [InlineData("password\u00a9",false)] - public void PasswordContainsOnlyLegalCharacters(string password, bool valid) - { - var check = _passwordService.IsPasswordContainingOnlyLegalCharacters(password); - Assert.Equal(valid, check); - } - - // not sure why, however, 'password' on it's own is not considered a 'common' password - // As explained in the comments for the PasswordTree, for the '123!passwords' test, I feel like it should count - // as a common password but doesnt in this implementation! - [Theory] - [InlineData("123!passwords",false)] - [InlineData("password123!",true)] - [InlineData("123!haslo",false)] - [InlineData("haslo123!",false)] - [InlineData("passwords",true)] - [InlineData("haslo",false)] - public void PasswordIsCommon(string password, bool valid) - { - var check = _passwordService.IsPasswordCommon(password); - Assert.Equal(valid, check); - } - - [Theory] - [InlineData("123!passwords",true)] - [InlineData("password123!",true)] // this is a valid password, regardless of it being common - [InlineData("123!haslo",true)] - [InlineData("haslo123!",true)] - [InlineData("passwords",false)] - [InlineData("haslo",false)] - [InlineData("password\u00a9",false)] - public void PasswordIsValid(string password, bool valid) - { - // The logic here is hard to read, the test checks whether I am passing in a VALID password - var check = !(_passwordService.IsPasswordInvalid(password)); - Assert.Equal(valid, check); - } +using back_end.Services; + +namespace Backend.Tests; + +public class PasswordTests +{ + private readonly PasswordService _passwordService; + + public PasswordTests() + { + _passwordService = new PasswordService(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"common-passwords.txt")); + } + + [Theory] + [InlineData("abcdefg",true)] + [InlineData("abcdef",false)] + [InlineData("abcdefghijklmn",true)] + [InlineData("abcdefghijklmno",false)] + public void PasswordLengthValid(string password, bool valid) + { + var check = _passwordService.IsPasswordLengthValid(password); + Assert.Equal(valid, check); + } + + [Theory] + [InlineData("password", false)] + [InlineData("password1", false)] + [InlineData("password!", false)] + [InlineData("password1!", true)] + public void PasswordContainsMinimumCharacters(string password, bool valid) + { + var check = _passwordService.IsPasswordContainingMinimumCharacters(password); + Assert.Equal(valid, check); + } + + [Theory] + [InlineData("password",true)] + [InlineData("password(",false)] + [InlineData("password\u00a9",false)] + public void PasswordContainsOnlyLegalCharacters(string password, bool valid) + { + var check = _passwordService.IsPasswordContainingOnlyLegalCharacters(password); + Assert.Equal(valid, check); + } + + // not sure why, however, 'password' on it's own is not considered a 'common' password + // As explained in the comments for the PasswordTree, for the '123!passwords' test, I feel like it should count + // as a common password but doesnt in this implementation! + [Theory] + [InlineData("123!passwords",false)] + [InlineData("password123!",true)] + [InlineData("123!haslo",false)] + [InlineData("haslo123!",false)] + [InlineData("passwords",true)] + [InlineData("haslo",false)] + public void PasswordIsCommon(string password, bool valid) + { + var check = _passwordService.IsPasswordCommon(password); + Assert.Equal(valid, check); + } + + [Theory] + [InlineData("123!passwords",true)] + [InlineData("password123!",true)] // this is a valid password, regardless of it being common + [InlineData("123!haslo",true)] + [InlineData("haslo123!",true)] + [InlineData("passwords",false)] + [InlineData("haslo",false)] + [InlineData("password\u00a9",false)] + public void PasswordIsValid(string password, bool valid) + { + // The logic here is hard to read, the test checks whether I am passing in a VALID password + var check = !(_passwordService.IsPasswordInvalid(password)); + Assert.Equal(valid, check); + } } \ No newline at end of file