aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_database_v1.py
blob: 8360c1dd494e4f102555e407548294985401fdc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from pwman_tstlib import *
initTest(__file__)

import pathlib
from libpwman.database import *

class Test_Database_v1(TestCase):
	"""Version 1 database format.
	"""
	def test_read_contents(self):
		db = PWManDatabase(filename=pathlib.Path("tests", "test_database_v1.db"),
				   passphrase="test")

		self.assertEqual(db.getCategoryNames(),
				 sorted([ "123",
					  "test2",
					  "testcat1" ]))

		self.assertEqual(db.getEntryTitles("123"),
				 sorted([ "4711",
					  "456" ]))
		self.assertEqual(db.getEntryTitles("test2"),
				 sorted([ "test2" ]))
		self.assertEqual(db.getEntryTitles("testcat1"),
				 sorted([ "testtitle1",
					  "testtitle2",
					  "test title3",
					  "test-title3",
					  "test title4",
					  "test title 5",
					  "test  title  6" ]))

		entry = db.getEntry("testcat1", "testtitle1")
		self.assertEqual(entry.user, "uuuuuuuuu")
		self.assertEqual(entry.pw, "pppppp")
		entryBulk = db.getEntryBulk(entry)
		self.assertEqual(entryBulk.data, "bbbbbbbb")
		entryAttr = db.getEntryAttr(entry, "AAAA")
		self.assertEqual(entryAttr.data, "BBBB")
		entryAttr = db.getEntryAttr(entry, "CCCC")
		self.assertEqual(entryAttr.data, "DDDDDDD")
		entryTotp = db.getEntryTotp(entry)
		self.assertEqual(entryTotp.key, "MZXW63YK")
		self.assertEqual(entryTotp.digits, 6)
		self.assertEqual(entryTotp.hmacHash, "SHA1")

		entry = db.getEntry("testcat1", "testtitle2")
		self.assertEqual(entry.user, "user")
		self.assertEqual(entry.pw, "pw")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)
		entryTotp = db.getEntryTotp(entry)
		self.assertEqual(entryTotp.key, "MJQXE4QK")
		self.assertEqual(entryTotp.digits, 8)
		self.assertEqual(entryTotp.hmacHash, "SHA256")

		entry = db.getEntry("testcat1", "test-title3")
		self.assertEqual(entry.user, "aa bb")
		self.assertEqual(entry.pw, "cc dd")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("testcat1", "test title3")
		self.assertEqual(entry.user, "xx yy")
		self.assertEqual(entry.pw, "oo pp")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("testcat1", "test title4")
		self.assertEqual(entry.user, "4")
		self.assertEqual(entry.pw, "44")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("testcat1", "test title 5")
		self.assertEqual(entry.user, "5")
		self.assertEqual(entry.pw, "55")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("testcat1", "test  title  6")
		self.assertEqual(entry.user, "6")
		self.assertEqual(entry.pw, "66")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("123", "4711")
		self.assertEqual(entry.user, "UUU")
		self.assertEqual(entry.pw, "password")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)
		entryAttr = db.getEntryAttr(entry, "git")
		self.assertEqual(entryAttr.data, "https://git.example.com")
		entryAttr = db.getEntryAttr(entry, "www")
		self.assertEqual(entryAttr.data, "https://www.example.com")

		entry = db.getEntry("123", "456")
		self.assertEqual(entry.user, "789")
		self.assertEqual(entry.pw, "")
		entryBulk = db.getEntryBulk(entry)
		self.assertIsNone(entryBulk)

		entry = db.getEntry("test2", "test2")
		self.assertEqual(entry.user, "TEST!")
		self.assertEqual(entry.pw, "TEST!!")
		entryBulk = db.getEntryBulk(entry)
		self.assertEqual(entryBulk.data, "TEST!!!")

	def test_legacy_pbkdf2(self):
		# Test legacy PBKDF2 read support.
		# Just check if we can open and decrypt it successfully.
		db = PWManDatabase(filename=pathlib.Path("tests", "test_database_v1_pbkdf2.db"),
				   passphrase="test")
		self.assertEqual(db.getCategoryNames(),
				 sorted([ "123", "test2", "testcat1" ]))
bues.ch cgit interface