X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/e91150b266bbd768905258166601fdf333d3d987..553d59fec08fd9102b21fd0dc83ba708862a6090:/t/t-passphrase.py diff --git a/t/t-passphrase.py b/t/t-passphrase.py new file mode 100644 index 0000000..9cc80a9 --- /dev/null +++ b/t/t-passphrase.py @@ -0,0 +1,90 @@ +### -*-python-*- +### +### Testing (some) passsword management functionality +### +### (c) 2019 Straylight/Edgeware +### + +###----- Licensing notice --------------------------------------------------- +### +### This file is part of the Python interface to Catacomb. +### +### Catacomb/Python is free software: you can redistribute it and/or +### modify it under the terms of the GNU General Public License as +### published by the Free Software Foundation; either version 2 of the +### License, or (at your option) any later version. +### +### Catacomb/Python is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +### General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with Catacomb/Python. If not, write to the Free Software +### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +### USA. + +from __future__ import with_statement + +###-------------------------------------------------------------------------- +### Imported modules. + +import catacomb as C +import errno as E +import unittest as U +import os as OS +import subprocess as SUB +import sys as SYS +import testutils as T +import time as TM + +###-------------------------------------------------------------------------- +### Running the pixie. + +class PixieTestCase (U.TestCase): + def setUp(me): + pix = "pixie-py%d.%d%s" % (SYS.version_info[0], + SYS.version_info[1], + T.DEBUGP and "dbg" or "") + me.token = hex(C.rand.block(8)) + try: OS.mkdir(OS.path.join("build", pix), int("700", 8)) + except OSError: + if SYS.exc_info()[1].errno == E.EEXIST: pass + else: raise + me.sock = OS.path.join("build", pix, "sock") + OS.environ["CATACOMB_PIXIE_SOCKET"] = me.sock + with open(OS.path.join("build", pix, "log"), "a") as logf: + SUB.check_call(["pixie", "-dr", "-s" + me.sock, + "-c", "echo 'pp.%%t.%s'" % me.token], stderr = logf) + def tearDown(me): + SUB.check_call(["pixie", "-s" + me.sock, "-C", "quit"]) + +###-------------------------------------------------------------------------- +class TestPixie (PixieTestCase): + + def test(me): + px = C.Pixie(socket = me.sock) + + pp = T.bin("super secret") + pp1 = T.bin("pp.test1.%s" % me.token) + pp2 = T.bin("pp.test2.%s" % me.token) + px.set("test1", pp) + me.assertEqual(px.read("test1"), pp) + me.assertEqual(px.read("test1", C.PMODE_READ), pp) + me.assertEqual(px.read("test1", C.PMODE_VERIFY), pp1) + me.assertEqual(px.read("test1", C.PMODE_READ), pp1) + px.set("test1", pp) + me.assertEqual(px.read("test1", C.PMODE_READ), pp) + me.assertEqual(px.read("test2"), pp2) + px.cancel("test1") + me.assertEqual(px.read("test1"), pp1) + + px.set("test1", pp) + me.assertEqual(C.ppread("test1"), pp) + C.ppcancel("test1") + me.assertEqual(px.read("test1"), pp1) + C.ppcancel("test1") + +###----- That's all, folks -------------------------------------------------- + +if __name__ == "__main__": U.main()