Adjust UnitTests namespace, add CSV importer unit tests (#542)

This commit is contained in:
Leendert de Borst
2025-03-24 17:19:05 +01:00
committed by Leendert de Borst
parent 634fc281a2
commit dc769bb5d4
18 changed files with 120 additions and 14 deletions

View File

@@ -53,6 +53,7 @@
<ProjectReference Include="..\..\Databases\AliasServerDb\AliasServerDb.csproj" />
<ProjectReference Include="..\..\Utilities\AliasVault.TotpGenerator\AliasVault.TotpGenerator.csproj" />
<ProjectReference Include="..\AliasVault.IntegrationTests\AliasVault.IntegrationTests.csproj" />
<ProjectReference Include="..\AliasVault.UnitTests\AliasVault.UnitTests.csproj" />
<ProjectReference Include="..\Server\AliasVault.E2ETests.Client.Server\AliasVault.E2ETests.Client.Server.csproj" />
</ItemGroup>

View File

@@ -7,7 +7,8 @@
// <auto-generated />
global using System.Threading.Tasks;
global using NUnit.Framework;
global using AliasVault.E2ETests.Infrastructure;
global using AliasVault.E2ETests.Common;
global using AliasVault.UnitTests.Common;
global using NUnit.Framework;
global using Microsoft.Playwright;

View File

@@ -1,6 +1,6 @@
This folder contains test data for the AliasVault.E2ETests project.
The build action of these is set to "Embedded resource" so that they can be accessed by the tests
using the `ResourceReaderUtility` class.
using the `AliasVault.UnitTests.ResourceReaderUtility` class.
Index:
- `AliasClientDb_encrypted_base64_1.0.0` - Encrypted vault blob with client db version 1.0.0 used to test client db upgrade paths. This vault contains two test credentials that are checked in the tests after local client db upgrade.

View File

@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>AliasVault.Tests</RootNamespace>
<RootNamespace>AliasVault.UnitTests</RootNamespace>
<LangVersion>13</LangVersion>
</PropertyGroup>
@@ -60,4 +60,11 @@
<ProjectReference Include="..\..\Utilities\AliasVault.TotpGenerator\AliasVault.TotpGenerator.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="TestData\Exports\bitwarden.csv" />
<EmbeddedResource Include="TestData\Exports\bitwarden.csv" />
<None Remove="TestData\Exports\keepass.kdbx.csv" />
<EmbeddedResource Include="TestData\Exports\keepass.kdbx.csv" />
</ItemGroup>
</Project>

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.E2ETests.Common;
namespace AliasVault.UnitTests.Common;
using System.IO;
using System.Reflection;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Generators;
namespace AliasVault.UnitTests.Generators;
using System.Net.Mail;
using AliasVault.Generators.Identity.Implementations.Factories;

View File

@@ -0,0 +1,6 @@
folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp
Business,,login,Item for business folder,,,0,,crisply,4CSp43uhSZri8A,
,,login,Test,,,0,,,,
,,login,Test,,,0,,test2,asdasd,
Business,,login,TutaNota,,,0,,avtest2@tutamail.com,blabla,otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30
Business,,login,Aliasvault.net,,,0,https://www.aliasvault.net,root,toor,
1 folder favorite type name notes fields reprompt login_uri login_username login_password login_totp
2 Business login Item for business folder 0 crisply 4CSp43uhSZri8A
3 login Test 0
4 login Test 0 test2 asdasd
5 Business login TutaNota 0 avtest2@tutamail.com blabla otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30
6 Business login Aliasvault.net 0 https://www.aliasvault.net root toor

View File

@@ -0,0 +1,10 @@
Title,Username,Email,Password,URL,OTPAuth,Notes
Sample,username,,&3V_$z?Aiw-_x+nbYj,https://strongboxsafe.com,,
Business1,username,,NYVqE8MpfnX#r+ukpE,,,
Business 2,username,,+jeN9dTLy4Ahh-C3fB,,,
Prive 1,username,,4c*Ksh??7Q_K#xKMLh,,,
Prive 2,username,,Ld6JsF^JXR7^8_F#Ad,,,
TutaNota,avtest2@tutamail.com,,blabla,,otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30,"Recovery code for main account: e45f a053 8b7e 127c 302b a816 abc2 739a 9b0c 7393 6adc 123a ff4e 084d 7798 ef26
Recovery code for 2FA:
e45f a053 8b7e 127c 302b a816 abc2 739a 9b0c 7393 6adc 123a ff4e 084d 7798 ef26"
1 Title Username Email Password URL OTPAuth Notes
2 Sample username &3V_$z?Aiw-_x+nbYj https://strongboxsafe.com
3 Business1 username NYVqE8MpfnX#r+ukpE
4 Business 2 username +jeN9dTLy4Ahh-C3fB
5 Prive 1 username 4c*Ksh??7Q_K#xKMLh
6 Prive 2 username Ld6JsF^JXR7^8_F#Ad
7 TutaNota avtest2@tutamail.com blabla otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30 Recovery code for main account: e45f a053 8b7e 127c 302b a816 abc2 739a 9b0c 7393 6adc 123a ff4e 084d 7798 ef26 Recovery code for 2FA: e45f a053 8b7e 127c 302b a816 abc2 739a 9b0c 7393 6adc 123a ff4e 084d 7798 ef26

View File

@@ -0,0 +1,6 @@
This folder contains test data for the AliasVault.UnitTests project.
The build action of these is set to "Embedded resource" so that they can be accessed by the tests
using the `ResourceReaderUtility` class.
Index:
- `Exports` Folder that contains export samples from other password managers to be used in import tests.

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
using System.Text.RegularExpressions;
using AliasVault.Shared.Utilities;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
/// <summary>
/// Tests for the AliasVault.FaviconExtractor class.

View File

@@ -5,10 +5,12 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
using AliasClientDb;
using AliasVault.ImportExport;
using AliasVault.ImportExport.Importers;
using AliasVault.UnitTests.Common;
/// <summary>
/// Tests for the AliasVault.ImportExport class.
@@ -102,4 +104,77 @@ public class ImportExportTests
Assert.That(importedPassword.UpdatedAt.ToString("yyyy-MM-dd"), Is.EqualTo(originalPassword.UpdatedAt.ToString("yyyy-MM-dd")));
});
}
/// <summary>
/// Test case for importing credentials from Bitwarden CSV and ensuring all values are present.
/// </summary>
/// <returns>Async task.</returns>
[Test]
public async Task ImportCredentialsFromBitwardenCsv()
{
// Arrange
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.bitwarden.csv");
// Act
var importedCredentials = await BitwardenImporter.ImportFromCsvAsync(fileContent);
// Assert
Assert.That(importedCredentials, Has.Count.EqualTo(5));
// Test specific entries
var tutaNotaCredential = importedCredentials.First(c => c.ServiceName == "TutaNota");
Assert.Multiple(() =>
{
Assert.That(tutaNotaCredential.ServiceName, Is.EqualTo("TutaNota"));
Assert.That(tutaNotaCredential.Username, Is.EqualTo("avtest2@tutamail.com"));
Assert.That(tutaNotaCredential.Password, Is.EqualTo("blabla"));
Assert.That(tutaNotaCredential.TwoFactorSecret, Is.EqualTo("otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30"));
});
var aliasVaultCredential = importedCredentials.First(c => c.ServiceName == "Aliasvault.net");
Assert.Multiple(() =>
{
Assert.That(aliasVaultCredential.ServiceName, Is.EqualTo("Aliasvault.net"));
Assert.That(aliasVaultCredential.ServiceUrl, Is.EqualTo("https://www.aliasvault.net"));
Assert.That(aliasVaultCredential.Username, Is.EqualTo("root"));
Assert.That(aliasVaultCredential.Password, Is.EqualTo("toor"));
});
}
/// <summary>
/// Test case for importing credentials from KeePass CSV and ensuring all values are present.
/// </summary>
/// <returns>Async task.</returns>
[Test]
public async Task ImportCredentialsFromKeePassCsv()
{
// Arrange
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.UnitTests.TestData.Exports.keepass.kdbx.csv");
// Act
var importedCredentials = await KeePassImporter.ImportFromCsvAsync(fileContent);
// Assert
Assert.That(importedCredentials, Has.Count.EqualTo(6));
// Test specific entries
var tutaNotaCredential = importedCredentials.First(c => c.ServiceName == "TutaNota");
Assert.Multiple(() =>
{
Assert.That(tutaNotaCredential.ServiceName, Is.EqualTo("TutaNota"));
Assert.That(tutaNotaCredential.Username, Is.EqualTo("avtest2@tutamail.com"));
Assert.That(tutaNotaCredential.Password, Is.EqualTo("blabla"));
Assert.That(tutaNotaCredential.TwoFactorSecret, Is.EqualTo("otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30"));
Assert.That(tutaNotaCredential.Notes, Does.Contain("Recovery code for main account"));
});
var sampleCredential = importedCredentials.First(c => c.ServiceName == "Sample");
Assert.Multiple(() =>
{
Assert.That(sampleCredential.ServiceName, Is.EqualTo("Sample"));
Assert.That(sampleCredential.ServiceUrl, Is.EqualTo("https://strongboxsafe.com"));
Assert.That(sampleCredential.Username, Is.EqualTo("username"));
Assert.That(sampleCredential.Password, Is.EqualTo("&3V_$z?Aiw-_x+nbYj"));
});
}
}

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
using System.Text.Json;
using AliasVault.Cryptography.Server;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
using System.Security.Cryptography;
using AliasVault.Cryptography.Client;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Utilities;
namespace AliasVault.UnitTests.Utilities;
/// <summary>
/// Tests for the TotpGeneratorTests class.

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Vault;
namespace AliasVault.UnitTests.Vault;
using AliasVault.Api.Helpers;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Vault.RetentionManager;
namespace AliasVault.UnitTests.Vault.RetentionManager;
using AliasServerDb;
using AliasVault.Api.Vault;

View File

@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
namespace AliasVault.Tests.Vault;
namespace AliasVault.UnitTests.Vault;
using AliasVault.Api.Helpers;