Added (working) unit tests!
This commit is contained in:
parent
b8afed8ac1
commit
f14ac4953d
3 changed files with 115 additions and 115 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,35 +1,35 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BackEnd\BackEnd.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="common-passwords.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BackEnd\BackEnd.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="common-passwords.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue