Skip to content

Commit 0b40dc1

Browse files
authored
Merge pull request #9 from shugaoye/master
KPCLib-1.3.0 build
2 parents 6e52d73 + 11d8d06 commit 0b40dc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2499
-598
lines changed

KPCLib.nuspec

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>KPCLib</id>
5-
<version>1.2.4.0</version>
5+
<version>1.3.0.0</version>
66
<authors>Roger Ye</authors>
77
<owners>Roger Ye</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
99
<license type="expression">LGPL-3.0-or-later</license>
1010
<projectUrl>https://github.com/passxyz/KPCLib</projectUrl>
1111
<description>This is the build of KeePassLib in Xamarin Portable Class Library. Three platforms, UWP, Android and iOS, are supported and tested.</description>
12-
<releaseNotes>- Support OTP</releaseNotes>
12+
<releaseNotes>
13+
- Updated to KeePass 2.48.1
14+
- Fixed an issue in CryptoRandom.cs
15+
</releaseNotes>
1316
<copyright>Dominik Reichl is the author of the original KeePassLib on Windows platform. Roger Ye updated and enhanced this library for .NET Standard.</copyright>
1417
<repository url="https://github.com/passxyz/KPCLib" />
1518
<dependencies>
1619
<group targetFramework=".NETStandard2.0">
17-
<dependency id="SkiaSharp" version="1.68.0" exclude="Build,Analyzers" />
20+
<dependency id="SkiaSharp" version="2.80.2" exclude="Build,Analyzers" />
21+
<dependency id="Svg.Skia" version="0.5.3" exclude="Build,Analyzers" />
1822
<dependency id="PureOtp" version="1.0.0.8" exclude="Build,Analyzers" />
1923
</group>
2024
</dependencies>
2125
<summary>KeePassLib built as .NET Standard Library</summary>
2226
</metadata>
2327
<files>
2428
<file src="PassXYZLib/bin/Release/netstandard2.0/KPCLib.dll" target="lib/netstandard2.0/KPCLib.dll" />
25-
<file src="PassXYZLib/bin/Release/netstandard2.0/PassXYZLib.dll" target="lib/netstandard2.0/PassXYZLib.dll" />
2629
</files>
2730
</package>

KPCLib.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KPCLib.xunit", "KPCLib.xuni
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PassXYZLib", "PassXYZLib\PassXYZLib.csproj", "{E6F6B65A-6474-4978-9F9C-F22194688240}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B5CFEC4A-7D25-4D24-B4F7-A568E1DF4750}"
13+
ProjectSection(SolutionItems) = preProject
14+
KPCLib.nuspec = KPCLib.nuspec
15+
PassXYZLib.nuspec = PassXYZLib.nuspec
16+
EndProjectSection
17+
EndProject
1218
Global
1319
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1420
Debug|Any CPU = Debug|Any CPU

KPCLib.xunit/GfxUtilTests.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
7+
using HtmlAgilityPack;
8+
using SkiaSharp;
9+
using Svg.Skia;
310

411
using Xunit;
12+
using PassXYZLib;
513
using KeePassLib.Utility;
614

715
// Need to turn off test parallelization so we can validate the run order
@@ -119,5 +127,70 @@ public void ScaleMultipleImages(int value)
119127
var resizedFile = "test" + value + ".png";
120128
SaveScaledImage(resizedFile, value, value);
121129
}
130+
131+
[Theory]
132+
[InlineData("http://github.com")]
133+
[InlineData("http://www.baidu.com")]
134+
[InlineData("https://www.bing.com/")]
135+
[InlineData("http://www.youdao.com")]
136+
[InlineData("https://www.dell.com")]
137+
[InlineData("http://www.cmbchina.com")]
138+
public void GetIconTest(string url)
139+
{
140+
var faviconUrl = ItemExtensions.RetrieveFavicon(url);
141+
if(faviconUrl != null)
142+
{
143+
var imageFolder = "images";
144+
try
145+
{
146+
DirectoryInfo di = new DirectoryInfo(imageFolder);
147+
try
148+
{
149+
// Determine whether the directory exists.
150+
if (!di.Exists)
151+
{
152+
di.Create();
153+
}
154+
}
155+
catch (Exception e)
156+
{
157+
Debug.WriteLine("The process failed: {0}", e.ToString());
158+
}
159+
160+
var uri = new Uri(faviconUrl);
161+
WebClient myWebClient = new WebClient();
162+
byte[] pb = myWebClient.DownloadData(faviconUrl);
163+
164+
if (faviconUrl.EndsWith(".ico") || faviconUrl.EndsWith(".png"))
165+
{
166+
GfxUtil.SaveImage(GfxUtil.ScaleImage(GfxUtil.LoadImage(pb), 128, 128), $"{imageFolder}/{uri.Host}.png");
167+
}
168+
else if (faviconUrl.EndsWith(".svg"))
169+
{
170+
GfxUtil.SaveImage(GfxUtil.LoadSvgImage(pb), $"{imageFolder}/{uri.Host}.png");
171+
}
172+
Debug.WriteLine($"{imageFolder}/{uri.Host}.png");
173+
}
174+
catch (System.Net.WebException ex)
175+
{
176+
Debug.WriteLine($"{ex}");
177+
}
178+
}
179+
Assert.NotNull(faviconUrl);
180+
}
181+
182+
[Theory]
183+
[InlineData("https://favicon.io/tutorials/what-is-a-favicon/")]
184+
public void NoFaviconTest(string url)
185+
{
186+
Assert.Null(ItemExtensions.RetrieveFavicon(url));
187+
}
188+
189+
[Fact]
190+
public void PrintImageFormat()
191+
{
192+
Debug.WriteLine($"The image format is {SKEncodedImageFormat.Png.ToString()}.");
193+
Debug.WriteLine($"The image format is {SKEncodedImageFormat.Ico.ToString()}.");
194+
}
122195
}
123196
}

KPCLib.xunit/KPCLib.xunit.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="HtmlAgilityPack" Version="1.11.34" />
1011
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
1112
<PackageReference Include="PassXYZ" Version="2.1.4.9" />
1213
<PackageReference Include="SkiaSharp" Version="2.80.2" />
1314
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
15+
<PackageReference Include="Svg.Skia" Version="0.5.3" />
1416
<PackageReference Include="xunit" Version="2.4.1" />
1517
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1618
<PrivateAssets>all</PrivateAssets>

KPCLib.xunit/PasswordDBTests.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
using Xunit;
9+
using KeePassLib;
10+
using KeePassLib.Keys;
11+
using KeePassLib.Serialization;
12+
using KeePassLib.Utility;
13+
using PassXYZLib;
14+
15+
namespace KPCLib.xunit
16+
{
17+
public class PasswordDBFixture : IDisposable
18+
{
19+
const string TEST_DB = "pass_d_E8f4pEk.xyz";
20+
const string TEST_DB_KEY = "12345";
21+
22+
public PasswordDBFixture()
23+
{
24+
PxDb = PasswordDb.Instance;
25+
PxDb.Open(TEST_DB, TEST_DB_KEY);
26+
}
27+
28+
public void Dispose()
29+
{
30+
PxDb.Close();
31+
}
32+
33+
public PasswordDb PxDb { get; private set; }
34+
public KPCLibLogger Logger { get; private set; }
35+
}
36+
37+
[CollectionDefinition("PasswordDB collection")]
38+
public class PasswordDBCollection : ICollectionFixture<PasswordDBFixture>
39+
{
40+
// This class has no code, and is never created. Its purpose is simply
41+
// to be the place to apply [CollectionDefinition] and all the
42+
// ICollectionFixture<> interfaces.
43+
}
44+
45+
[Collection("PasswordDB collection")]
46+
public class PasswordDBTests
47+
{
48+
PasswordDBFixture passxyz;
49+
50+
public PasswordDBTests(PasswordDBFixture passXYZFixture)
51+
{
52+
this.passxyz = passXYZFixture;
53+
}
54+
55+
[Fact]
56+
public void IsOpenDbTest()
57+
{
58+
Debug.WriteLine($"{passxyz.PxDb}");
59+
Assert.True((passxyz.PxDb.IsOpen));
60+
}
61+
62+
[Fact]
63+
public void ListItemsTests()
64+
{
65+
PwGroup pg = passxyz.PxDb.RootGroup;
66+
67+
List<Item> itemList = pg.GetItems();
68+
foreach (var item in itemList)
69+
{
70+
Debug.WriteLine($"\t{item.Name} : {item.ImgSource}");
71+
}
72+
Assert.NotNull(itemList);
73+
}
74+
75+
[Theory]
76+
[InlineData("http://github.com")]
77+
[InlineData("http://www.baidu.com")]
78+
[InlineData("http://www.youdao.com")]
79+
[InlineData("http://www.qq.com")]
80+
[InlineData("http://www.hp.com")]
81+
[InlineData("http://www.163.com")]
82+
[InlineData("http://www.bing.com")]
83+
public void CustomIconTests(string url)
84+
{
85+
var entry = new PwEntry();
86+
entry.AddNewIcon(url);
87+
PwCustomIcon icon = passxyz.PxDb.GetPwCustomIcon(entry.CustomIconUuid);
88+
entry.Name = icon.Name;
89+
Debug.WriteLine($"{icon.Name} is stored at {passxyz.PxDb.CurrentPath}");
90+
passxyz.PxDb.CurrentGroup.AddEntry(entry, true);
91+
passxyz.PxDb.Save(null);
92+
Assert.False(entry.CustomIconUuid.Equals(PwUuid.Zero));
93+
}
94+
95+
}
96+
}

KPCLib.xunit/PxDatabaseTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public void ListEntriesTests()
8484
}
8585
}
8686

87+
[Fact]
88+
public void ListItemsTests()
89+
{
90+
PwGroup pg = passxyz.PxDb.RootGroup;
91+
92+
List<Item> itemList = pg.GetItems();
93+
foreach (var item in itemList)
94+
{
95+
Debug.WriteLine($"\t{item.Name} : {item.ImgSource}");
96+
}
97+
Assert.NotNull(itemList);
98+
}
99+
87100
[Fact]
88101
public void DeleteEmptyEntryTest()
89102
{
@@ -379,7 +392,7 @@ public class PxLibInfoTests
379392
public void PxLibVersion()
380393
{
381394
Debug.WriteLine($"{PxLibInfo.Version}");
382-
Assert.Equal(PxLibInfo.Version, new System.Version("1.2.2.9"));
395+
Assert.Equal(PxLibInfo.Version, new System.Version("1.3.0.0"));
383396
}
384397

385398
[Fact]

KPCLib.xunit/PxEntryTests.cs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,121 @@
77

88
using Xunit;
99

10-
using PureOtp;
10+
using KeePassLib;
1111
using PassXYZLib;
1212

1313
namespace KPCLib.xunit
1414
{
15+
public class PxEntryFixture : IDisposable
16+
{
17+
const string TEST_DB = "pass_d_E8f4pEk.xyz";
18+
const string TEST_DB_KEY = "12345";
19+
20+
public PxEntryFixture()
21+
{
22+
PxDb = new PxDatabase();
23+
PxDb.Open(TEST_DB, TEST_DB_KEY);
24+
}
25+
26+
public void Dispose()
27+
{
28+
PxDb.Close();
29+
}
30+
31+
public PxDatabase PxDb { get; private set; }
32+
public KPCLibLogger Logger { get; private set; }
33+
34+
public string Username
35+
{
36+
get { return PxDefs.GetUserNameFromDataFile(TEST_DB); }
37+
}
38+
}
39+
40+
[CollectionDefinition("PxEntry collection")]
41+
public class PxEntryCollection : ICollectionFixture<PxEntryFixture>
42+
{
43+
// This class has no code, and is never created. Its purpose is simply
44+
// to be the place to apply [CollectionDefinition] and all the
45+
// ICollectionFixture<> interfaces.
46+
}
47+
48+
[Collection("PxEntry collection")]
1549
public class PxEntryTests
1650
{
51+
PxEntryFixture passxyz;
52+
53+
public PxEntryTests(PxEntryFixture fixture)
54+
{
55+
this.passxyz = fixture;
56+
}
57+
1758
[Fact]
1859
public void PxEntryInitTests()
1960
{
2061
var entry = new PxEntry();
2162
Assert.NotNull(entry);
2263
}
64+
65+
[Fact]
66+
public void PrintPxEntryTest()
67+
{
68+
Debug.WriteLine("*** PrintPxEntryTest ***");
69+
foreach (PwEntry entry in passxyz.PxDb.GetAllEntries())
70+
{
71+
if (entry.IsPxEntry())
72+
{
73+
Debug.WriteLine($"Title: {entry.Name}");
74+
Debug.WriteLine($"{entry.EncodeKey("TestKey")}");
75+
var fields = entry.GetFields();
76+
foreach (var field in fields) { Debug.WriteLine($"{field.EncodedKey}={field.Value}"); }
77+
Debug.WriteLine($"Notes: {entry.GetNotes()}");
78+
Assert.True(true);
79+
return;
80+
}
81+
}
82+
Debug.WriteLine("Cannot find PxEntry.");
83+
Assert.True(false);
84+
}
85+
86+
[Fact]
87+
public void PrintPwEntryTest()
88+
{
89+
Debug.WriteLine("*** PrintPwEntryTest ***");
90+
foreach (PwEntry entry in passxyz.PxDb.GetAllEntries())
91+
{
92+
if(!entry.IsNotes())
93+
{
94+
if (!entry.IsPxEntry())
95+
{
96+
Debug.WriteLine($"Title: {entry.Name}");
97+
var fields = entry.GetFields();
98+
foreach (var field in fields) { Debug.WriteLine($"{field.Key}={field.Value}"); }
99+
Debug.WriteLine($"Notes: {entry.GetNotes()}");
100+
Assert.True(true);
101+
return;
102+
}
103+
}
104+
}
105+
Debug.WriteLine("Cannot find PwEntry.");
106+
Assert.True(false);
107+
}
108+
109+
[Fact]
110+
public void PrintNotesTest()
111+
{
112+
Debug.WriteLine("*** PrintNotesTest ***");
113+
foreach (PwEntry entry in passxyz.PxDb.GetAllEntries())
114+
{
115+
if (entry.IsNotes())
116+
{
117+
Debug.WriteLine($"Title: {entry.Name}");
118+
Debug.WriteLine($"Notes: {entry.GetNotes()}");
119+
Assert.True(true);
120+
return;
121+
}
122+
}
123+
Debug.WriteLine("Cannot find Notes.");
124+
Assert.True(false);
125+
}
23126
}
24127
}

0 commit comments

Comments
 (0)