Skip to content

Commit

Permalink
Relaxed path requirements to KDBX file so it can live outside the ass…
Browse files Browse the repository at this point in the history
…embly execution directory.
  • Loading branch information
adamfisher committed Dec 8, 2021
1 parent 9ce2ec0 commit 82e5830
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

namespace KeePass.Extensions.Configuration.Tests
Expand Down Expand Up @@ -35,17 +36,22 @@ public KeePassConfigurationExtensionsTests()

#region Tests

[Fact]
public void AddKeePass_MapsKdbxPathToConnection()
[Theory]
[InlineData("KeePassTestDatabase.kdbx")]
[InlineData("../../../KeePassTestDatabase.kdbx")]
public void AddKeePass_MapsKdbxPathToConnection(string path)
{
Builder.AddKeePass("KeePassTestDatabase.kdbx");
Builder.AddKeePass(path);

Builder.Sources.Should().NotBeEmpty();
Builder.Sources.First().Should().BeOfType<KeePassConfigurationSource>();

var keePassSource = (KeePassConfigurationSource)Builder.Sources.First();
keePassSource.Path.Should().BeEquivalentTo("KeePassTestDatabase.kdbx");
keePassSource.Connection.Path.Should().BeEquivalentTo("KeePassTestDatabase.kdbx");
keePassSource.Path.Should().BeEquivalentTo(path);
keePassSource.Connection.Path.Should().BeEquivalentTo(path);

var provider = new KeePassConfigurationProvider(keePassSource);
provider.Invoking(x => x.Load()).Should().Throw<InvalidCompositeKeyException>();
}

[Fact]
Expand All @@ -61,9 +67,14 @@ public void AddKeePass_WithMasterPassword()
[Fact]
public void AddKeePass_WithWindowsAccount()
{
Builder.AddKeePass("KeePassTestDatabase.kdbx", useCurrentWindowsAccount: true);
var keePassSource = (KeePassConfigurationSource)Builder.Sources.First();
keePassSource.CompositeKey.GetUserKey(typeof(KcpUserAccount)).Should().NotBeNull();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Builder.AddKeePass("KeePassTestDatabase.kdbx", useCurrentWindowsAccount: true);
var keePassSource = (KeePassConfigurationSource)Builder.Sources.First();
keePassSource.CompositeKey.GetUserKey(typeof(KcpUserAccount)).Should().NotBeNull();
}

Assert.True(true);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Authors>Adam Fisher</Authors>
<Company>Octane Software, LLC</Company>
<Description>KeePass configuration provider implementation for Microsoft.Extensions.Configuration.</Description>
Expand All @@ -14,7 +14,7 @@
<PackageTags>keepass,configuration,Microsoft.Extensions.Configuration,config</PackageTags>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageIconUrl>https://raw.githubusercontent.com/adamfisher/KeePass.Extensions.Configuration/master/Images/keepass_512x512.png</PackageIconUrl>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public static IConfigurationBuilder AddKeePass(
if (provider == null && Path.IsPathRooted(path))
{
provider = new PhysicalFileProvider(Path.GetDirectoryName(path));
path = Path.GetFileName(path);
}

connection = connection ?? new IOConnectionInfo { Path = path };
Expand Down

0 comments on commit 82e5830

Please sign in to comment.