Esempio n. 1
0
    def test_01__init(self):
        state = gpgpass.init('/tmp/gpgpasscfg.%s' % os.getpid(), '/tmp/gpgpasscfg-pwrepo.%s' % os.getpid())
        self.assertTrue(state)

        # Init again, to pick up the now created config.ini
        state = gpgpass.init('/tmp/gpgpasscfg.%s' % os.getpid(), '/tmp/gpgpasscfg-pwrepo.%s' % os.getpid())
        self.assertTrue(state)

        # Init with an invalid path
        with self.assertRaises(SystemExit) as cm:
            state = gpgpass.init('/tmp/gpgpasscfg-proc.%s' % os.getpid(), '/proc/foo')
        self.assertEqual(cm.exception.code, 1)

        # https://github.com/rvdh/gpgpass_passwords.git
        cfg = SafeConfigParser()
        cfg.read(os.path.join('/tmp/gpgpasscfg.%s' % os.getpid(), 'config.ini'))
        cfg.set('Passwords', 'passwordsRepositoryRemote', 'https://github.com/rvdh/gpgpass_passwords.git')
        with open(os.path.join('/tmp/gpgpasscfg.%s' % os.getpid(), 'config.ini'), 'wb') as fh:
            cfg.write(fh)

        # Run the test again, now with a remote
        state = gpgpass.init('/tmp/gpgpasscfg.%s' % os.getpid(), '/tmp/gpgpasscfg-pwrepo.%s' % os.getpid())
        self.assertTrue(state)

        # Remove the tmp config dir
        shutil.rmtree('/tmp/gpgpasscfg.%s' % os.getpid())
        shutil.rmtree('/tmp/gpgpasscfg-proc.%s' % os.getpid())
        shutil.rmtree('/tmp/gpgpasscfg-pwrepo.%s' % os.getpid())
Esempio n. 2
0
    def test_03__searchThruFiles(self):
        gpgpass.init('/tmp/gpgpasstest03.%s' % os.getpid(), '/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())
        cfg = SafeConfigParser()
        cfg.read(os.path.join('/tmp/gpgpasstest03.%s' % os.getpid(), 'config.ini'))
        cfg.set('Passwords', 'passwordsRepositoryRemote', 'https://github.com/rvdh/gpgpass_passwords.git')
        with open(os.path.join('/tmp/gpgpasstest03.%s' % os.getpid(), 'config.ini'), 'wb') as fh:
            cfg.write(fh)

        # Check out the repository
        gpgpass.init('/tmp/gpgpasstest03.%s' % os.getpid(), '/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())

        # Copy the test file
        #shutil.copyfile("/tmp/gpgpasstest03-pwrepo.%s/testfile.gpg" % os.getpid(), '/tmp/gpgpasstest03-pwrepo.%s/testfile.gpg' % os.getpid())

        self.assertTrue(gpgpass.searchThruFiles("search", False, os.path.join(os.path.dirname(os.path.realpath(__file__)), "gpg")))
        self.assertTrue(gpgpass.searchThruFiles("search", True, os.path.join(os.path.dirname(os.path.realpath(__file__)), "gpg")))

        # Test for whole file
        with self.assertRaises(SystemExit) as cm:
            gpgpass.searchThruFiles("testfile.gpg", True, os.path.join(os.path.dirname(os.path.realpath(__file__)), "gpg"))
        self.assertEqual(cm.exception.code, 0)

        # Remove the temp repo
        shutil.rmtree('/tmp/gpgpasstest03.%s' % os.getpid())
        shutil.rmtree('/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())
Esempio n. 3
0
    def test_03__searchThruFiles(self):
        from gpgpass import gpgpass
        gpgpass.init('/tmp/gpgpasstest03.%s' % os.getpid(),
                     '/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())
        cfg = SafeConfigParser()
        cfg.read(os.path.join('/tmp/gpgpasstest03.%s' % os.getpid(),
                              'config.ini'))
        cfg.set('Passwords', 'passwordsRepositoryRemote',
                'https://github.com/rvdh/gpgpass_passwords.git')
        with open(os.path.join('/tmp/gpgpasstest03.%s' % os.getpid(),
                               'config.ini'), 'wb') as fh:
            cfg.write(fh)

        # Check out the repository
        gpgpass.init('/tmp/gpgpasstest03.%s' % os.getpid(),
                     '/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())

        # Search for 'search'
        self.assertEqual(gpgpass.searchThruFiles("search", os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "gpg")), 0)

        # Display file
        self.assertEqual(gpgpass.displayFile("testfile.gpg", os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "gpg")), 0)

        # Remove the temp repo
        shutil.rmtree('/tmp/gpgpasstest03.%s' % os.getpid())
        shutil.rmtree('/tmp/gpgpasstest03-pwrepo.%s' % os.getpid())