t/: Add a test suite.
[catacomb-python] / t / t-passphrase.py
1 ### -*-python-*-
2 ###
3 ### Testing (some) passsword management functionality
4 ###
5 ### (c) 2019 Straylight/Edgeware
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of the Python interface to Catacomb.
11 ###
12 ### Catacomb/Python is free software: you can redistribute it and/or
13 ### modify it under the terms of the GNU General Public License as
14 ### published by the Free Software Foundation; either version 2 of the
15 ### License, or (at your option) any later version.
16 ###
17 ### Catacomb/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
21 ###
22 ### You should have received a copy of the GNU General Public License
23 ### along with Catacomb/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 ### USA.
26
27 from __future__ import with_statement
28
29 ###--------------------------------------------------------------------------
30 ### Imported modules.
31
32 import catacomb as C
33 import errno as E
34 import unittest as U
35 import os as OS
36 import subprocess as SUB
37 import sys as SYS
38 import testutils as T
39 import time as TM
40
41 ###--------------------------------------------------------------------------
42 ### Running the pixie.
43
44 class PixieTestCase (U.TestCase):
45 def setUp(me):
46 pix = "pixie-py%d.%d%s" % (SYS.version_info[0],
47 SYS.version_info[1],
48 T.DEBUGP and "dbg" or "")
49 me.token = hex(C.rand.block(8))
50 try: OS.mkdir(OS.path.join("build", pix), int("700", 8))
51 except OSError:
52 if SYS.exc_info()[1].errno == E.EEXIST: pass
53 else: raise
54 me.sock = OS.path.join("build", pix, "sock")
55 OS.environ["CATACOMB_PIXIE_SOCKET"] = me.sock
56 with open(OS.path.join("build", pix, "log"), "a") as logf:
57 SUB.check_call(["pixie", "-dr", "-s" + me.sock,
58 "-c", "echo 'pp.%%t.%s'" % me.token], stderr = logf)
59 def tearDown(me):
60 SUB.check_call(["pixie", "-s" + me.sock, "-C", "quit"])
61
62 ###--------------------------------------------------------------------------
63 class TestPixie (PixieTestCase):
64
65 def test(me):
66 px = C.Pixie(socket = me.sock)
67
68 pp = T.bin("super secret")
69 pp1 = T.bin("pp.test1.%s" % me.token)
70 pp2 = T.bin("pp.test2.%s" % me.token)
71 px.set("test1", pp)
72 me.assertEqual(px.read("test1"), pp)
73 me.assertEqual(px.read("test1", C.PMODE_READ), pp)
74 me.assertEqual(px.read("test1", C.PMODE_VERIFY), pp1)
75 me.assertEqual(px.read("test1", C.PMODE_READ), pp1)
76 px.set("test1", pp)
77 me.assertEqual(px.read("test1", C.PMODE_READ), pp)
78 me.assertEqual(px.read("test2"), pp2)
79 px.cancel("test1")
80 me.assertEqual(px.read("test1"), pp1)
81
82 px.set("test1", pp)
83 me.assertEqual(C.ppread("test1"), pp)
84 C.ppcancel("test1")
85 me.assertEqual(px.read("test1"), pp1)
86 C.ppcancel("test1")
87
88 ###----- That's all, folks --------------------------------------------------
89
90 if __name__ == "__main__": U.main()