Skip to content

Commit 1255e64

Browse files
committed
Updated KPCLib to 2.0.3
1 parent a45f059 commit 1255e64

File tree

6 files changed

+347
-2
lines changed

6 files changed

+347
-2
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "PureOtp"]
2+
path = PureOtp
3+
url = https://github.com/shugaoye/PureOtp.git
4+
branch = passxyz

Notebook/passxyzlib.ipynb

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"text/html": "<table><thead><tr><th>Major</th><th>Minor</th><th>Build</th><th>Revision</th><th>MajorRevision</th><th>MinorRevision</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td><td><div class=\"dni-plaintext\">0</div></td></tr></tbody></table>"
11+
},
12+
"output_type": "unknown"
13+
}
14+
],
15+
"source": [
16+
"using System;\r\n",
17+
"using System.Reflection;\r\n",
18+
"\r\n",
19+
"Assembly.GetExecutingAssembly().FullName"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 1,
25+
"metadata": {
26+
"dotnet_interactive": {
27+
"language": "csharp"
28+
}
29+
},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": "There are 4 items.\r\n"
34+
},
35+
"output_type": "unknown"
36+
},
37+
{
38+
"data": {
39+
"text/plain": "item = home\r\n"
40+
},
41+
"output_type": "unknown"
42+
},
43+
{
44+
"data": {
45+
"text/plain": "item = data\r\n"
46+
},
47+
"output_type": "unknown"
48+
},
49+
{
50+
"data": {
51+
"text/plain": "last = src\r\n"
52+
},
53+
"output_type": "unknown"
54+
},
55+
{
56+
"data": {
57+
"text/plain": "False, src\r\n"
58+
},
59+
"output_type": "unknown"
60+
}
61+
],
62+
"source": [
63+
"using System;\r\n",
64+
"using System.Diagnostics;\r\n",
65+
"\r\n",
66+
"string testPath = \"/home/data/test/src\";\r\n",
67+
"\r\n",
68+
"\r\n",
69+
"string FindLastOne(string path = \"/\") \r\n",
70+
"{\r\n",
71+
" if (path == null) { return null; }\r\n",
72+
" string[] paths = path.Split('/');\r\n",
73+
" if(paths.Length > 0) \r\n",
74+
" {\r\n",
75+
" var i = 0;\r\n",
76+
" var item = \"\";\r\n",
77+
" Console.WriteLine($\"There are {paths.Length - 1} items.\");\r\n",
78+
" for (i = 0; i < paths.Length - 1; i++) \r\n",
79+
" { \r\n",
80+
" item = paths[i];\r\n",
81+
" if(!String.IsNullOrEmpty(item))\r\n",
82+
" {\r\n",
83+
" Console.WriteLine($\"item = {item}\");\r\n",
84+
" }\r\n",
85+
" }\r\n",
86+
" Console.WriteLine($\"last = {paths[paths.Length - 1]}\");\r\n",
87+
" }\r\n",
88+
" return paths[paths.Count() - 1];\r\n",
89+
"}\r\n",
90+
"\r\n",
91+
"var last = FindLastOne(testPath);\r\n",
92+
"// string path = \"/home/data/test/src\";\r\n",
93+
"\r\n",
94+
"/*\r\n",
95+
"foreach (var sub in subs)\r\n",
96+
"{\r\n",
97+
" Console.WriteLine($\"Substring: {sub}\");\r\n",
98+
"}*/\r\n",
99+
"\r\n",
100+
"Console.WriteLine($\"{testPath.EndsWith(\"/\")}, {last}\");"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 1,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"data": {
110+
"text/plain": "Key=1\r\n"
111+
},
112+
"output_type": "unknown"
113+
}
114+
],
115+
"source": [
116+
"public class NamedContainer<T>\r\n",
117+
"{\r\n",
118+
" public NamedContainer(T item, string name)\r\n",
119+
" {\r\n",
120+
" Item = item;\r\n",
121+
" Name = name;\r\n",
122+
" }\r\n",
123+
"\r\n",
124+
" public T Item { get; }\r\n",
125+
" public string Name { get; }\r\n",
126+
"}\r\n",
127+
"\r\n",
128+
"var nc = new NamedContainer<int>(1, \"Key\");\r\n",
129+
"Console.WriteLine($\"Key={nc.Item}\");"
130+
]
131+
}
132+
],
133+
"metadata": {
134+
"kernelspec": {
135+
"display_name": ".NET (C#)",
136+
"language": "C#",
137+
"metadata": {
138+
"interpreter": {
139+
"hash": "82a4497aa44a440fbfb1d441f8bbfbe94f1ccaaf7adaa9528d6a47a3b7658ad3"
140+
}
141+
},
142+
"name": ".net-csharp"
143+
},
144+
"language_info": {
145+
"name": "dotnet-interactive.csharp",
146+
"version": "3.8.5-final"
147+
},
148+
"orig_nbformat": 2
149+
},
150+
"nbformat": 4,
151+
"nbformat_minor": 2
152+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 PassXYZLib;
10+
11+
namespace xunit.PassXYZLib
12+
{
13+
public class PxEncryptionTest
14+
{
15+
[Theory]
16+
[InlineData("Hello World 11", "12345678901")]
17+
[InlineData("Hello World 12", "123456789012")]
18+
[InlineData("Hello World 13", "1234567890123")]
19+
[InlineData("Hello World 14", "12345678901234")]
20+
[InlineData("Hello World 15", "123456789012345")]
21+
public void EncryptStringTest(string secretMessage, string password)
22+
{
23+
string encryptedMessage = PxEncryption.EncryptWithPassword(secretMessage, password);
24+
string decryptedMessage = PxEncryption.DecryptWithPassword(encryptedMessage, password);
25+
Debug.WriteLine($"EncryptStringTest: PasswdLen={password.Length}, TextLen={encryptedMessage.Length}, {decryptedMessage}");
26+
Assert.Equal(secretMessage, decryptedMessage);
27+
}
28+
}
29+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
using Xunit;
5+
6+
using PassXYZLib;
7+
8+
namespace xunit.PassXYZLib
9+
{
10+
public class UserFixture : IDisposable
11+
{
12+
public User user;
13+
14+
public UserFixture()
15+
{
16+
user = new User
17+
{
18+
Username = "test1"
19+
};
20+
PxDb = new PxDatabase();
21+
}
22+
23+
public void Dispose()
24+
{
25+
PxDb.Close();
26+
}
27+
public PxDatabase PxDb { get; private set; }
28+
}
29+
30+
[CollectionDefinition("User collection")]
31+
public class UserCollection : ICollectionFixture<UserFixture>
32+
{
33+
// This class has no code, and is never created. Its purpose is simply
34+
// to be the place to apply [CollectionDefinition] and all the
35+
// ICollectionFixture<> interfaces.
36+
}
37+
38+
[Collection("User collection")]
39+
public class UserTests
40+
{
41+
readonly UserFixture userFixture;
42+
/// <summary>
43+
/// Three built-in users are:
44+
/// <c>test1</c> - user without Device Lock.
45+
/// <c>kpclibpy</c> - user with Device Lock.
46+
/// <c>user1</c> user with a normal key file.
47+
/// </summary>
48+
/// <param name="fixture"></param>
49+
public UserTests(UserFixture fixture)
50+
{
51+
this.userFixture = fixture;
52+
}
53+
54+
[Fact]
55+
public void MyDataPathTest()
56+
{
57+
userFixture.user.Username = "test1";
58+
Debug.Print($"DataFilePath={PxDataFile.DataFilePath}");
59+
Debug.Print($"FileName={userFixture.user.FileName}, LastAccessTime: {userFixture.user.LastAccessTime}");
60+
Assert.NotNull(PxDataFile.DataFilePath);
61+
//Assert.True(!userFixture.user.IsDeviceLockEnabled);
62+
}
63+
64+
[Fact]
65+
public void KeyPathTest()
66+
{
67+
userFixture.user.Username = "test1";
68+
Debug.Print($"DataFilePath={PxDataFile.KeyFilePath}");
69+
Assert.NotNull(PxDataFile.KeyFilePath);
70+
}
71+
72+
[Fact]
73+
public void GetUserNameTest()
74+
{
75+
var users = User.GetUsersList();
76+
foreach(var user in users)
77+
{
78+
Debug.WriteLine($"username={user}");
79+
}
80+
}
81+
82+
/// <summary>
83+
/// Testing <c>IsKeyFileExist</c> and <c>IsUserExist</c>
84+
/// </summary>
85+
[Fact]
86+
public void FileNameTest()
87+
{
88+
userFixture.user.Username = "kpclibpy";
89+
PxDataFile.DataFilePath = System.IO.Directory.GetCurrentDirectory();
90+
Debug.Print($"FileName={userFixture.user.FileName}");
91+
Assert.True(userFixture.user.IsKeyFileExist);
92+
Assert.True(userFixture.user.IsUserExist);
93+
if (userFixture.user.IsKeyFileExist)
94+
{
95+
Debug.WriteLine($"FileNameTest: Found key file {userFixture.user.KeyFileName}");
96+
}
97+
Assert.NotNull(userFixture.user.FileName);
98+
}
99+
100+
/// <summary>
101+
/// Testing a KeePass database with key file.
102+
/// </summary>
103+
[Fact]
104+
public void KeePassKeyFileTest()
105+
{
106+
PxDataFile.DataFilePath = System.IO.Directory.GetCurrentDirectory();
107+
userFixture.user.Username = "user1";
108+
userFixture.user.Password = "123123";
109+
Debug.WriteLine($"KeePassKeyFileTest: {userFixture.user.Path}");
110+
userFixture.PxDb.Open(userFixture.user);
111+
Assert.True(userFixture.PxDb.IsOpen);
112+
}
113+
}
114+
}

PassXYZLib.xunit/PureOtpTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
10+
using PureOtp;
11+
12+
namespace xunit.PureOtp
13+
{
14+
public class PureOtpTests
15+
{
16+
[Theory]
17+
[InlineData("/kpclibpy/Database/Oracle")]
18+
[InlineData("http://www.google.com/test?secret=JBSWY3DPEHPK3PXP")]
19+
[InlineData("otpauth://totp/test01%3Abad_url_test%40gmail.com?secret=098")]
20+
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com")]
21+
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP")]
22+
[InlineData("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP&issuer=Google")]
23+
public void RawUrlTest(string rawUrl)
24+
{
25+
try
26+
{
27+
var otp = KeyUrl.FromUrl(rawUrl);
28+
if (otp is Totp totp)
29+
{
30+
var url = new Uri(rawUrl);
31+
Assert.True(true);
32+
Debug.WriteLine($"{rawUrl} is a valid URL.");
33+
}
34+
else
35+
{
36+
Debug.WriteLine($"{rawUrl} is an invalid URL.");
37+
}
38+
}
39+
catch (Exception ex)
40+
{
41+
Debug.WriteLine($"{ex}");
42+
Assert.False(false);
43+
}
44+
}
45+
}
46+
}

PassXYZLib/PassXYZLib.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1919

20-
<Version>2.0.1-rc.3</Version>
20+
<Version>2.0.1</Version>
2121
<NeutralLanguage>en-US</NeutralLanguage>
2222
</PropertyGroup>
2323

2424
<ItemGroup>
2525
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
2626
<PackageReference Include="Markdig" Version="0.23.0" />
2727
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
28-
<PackageReference Include="PassXYZ" Version="2.1.5.25" />
28+
<PackageReference Include="PassXYZ" Version="2.1.5.28" />
2929
</ItemGroup>
3030

3131
<ItemGroup>

0 commit comments

Comments
 (0)