Esempio n. 1
0
    def test_misc_helper(self):
        good_path = OPENSSL
        with pytest.raises(RuntimeError):
            set_openssl('junk.glop')
        # TO-DO write a win32 version of this, eg .bat file
        if sys.platform != 'win32':
            with pytest.raises(RuntimeError):
                p = os.path.join(split(__file__)[0], 'openssl_version_97')
                set_openssl(p)
        set_openssl(good_path)
        if sys.platform in ['win32']:
            # exercise more code by forcing a reconstructon of the .bat files:
            if OPENSSL.endswith('.bat'):
                if bat_identifier in open(OPENSSL, 'rb').read():
                    os.unlink(OPENSSL)
            if DESTROY_EXE.endswith('.bat'):
                if bat_identifier in open(DESTROY_EXE, 'rb').read():
                    os.unlink(DESTROY_EXE)

        command_alias()
        set_openssl()
        set_destroy()
        sys.argv = [sys.executable, lib_path, '--verbose']
        args = _parse_args()
        logging = set_logging(True)
        logging.debug('test message')

        get_dropbox_path()
Esempio n. 2
0
    def test_misc_helper(self):
        good_path = OPENSSL
        with pytest.raises(RuntimeError):
            set_openssl('junk.glop')
        # TO-DO write a win32 version of this, eg .bat file
        if sys.platform != 'win32':
            with pytest.raises(RuntimeError):
                p = os.path.join(split(__file__)[0], 'openssl_version_97')
                set_openssl(p)
        set_openssl(good_path)
        if sys.platform in ['win32']:
            # exercise more code by forcing a reconstructon of the .bat files:
            if OPENSSL.endswith('.bat'):
                if bat_identifier in open(OPENSSL, 'rb').read():
                    os.unlink(OPENSSL)
            if DESTROY_EXE.endswith('.bat'):
                if bat_identifier in open(DESTROY_EXE, 'rb').read():
                    os.unlink(DESTROY_EXE)

        command_alias()
        set_openssl()
        set_destroy()
        sys.argv = [sys.executable, lib_path, '--verbose']
        args = _parse_args()
        logging = set_logging(True)
        logging.debug('test message')

        get_dropbox_path()
Esempio n. 3
0
    def test_GenRSA(self):
        GenRSA().check_entropy()

        # test dialog as pyfilesec.genrsa()
        pub, priv, pp = genrsa(interactive=False)
        assert exists(pub)
        assert exists(priv)
        assert len(pp) >= 16

        sys.argv = [__file__, 'genrsa', '--clipboard']
        args = _parse_args()
        assert args.clipboard
        # travis-ci builds on linux, needs xclip, else import will fail
        try:
            from pyfilesec.lib import _pyperclip
            GenRSA().dialog(interactive=False, args=args)
        except (RuntimeError, ImportError):
            with pytest.raises(RuntimeError):
                GenRSA().dialog(interactive=False, args=args)

        sys.argv = [__file__, 'genrsa', '--passfile']
        args = _parse_args()
        assert args.passfile
        GenRSA().dialog(interactive=False, args=args)

        # test pub priv name collision
        sys.argv = [__file__, 'genrsa', '--pub', 'pub', '--priv', 'pub']
        args = _parse_args()
        assert args.pub == args.priv
        GenRSA().dialog(interactive=False, args=args)

        # test detect existing priv?
        with open('priv.pem', write_mode) as fd:
            fd.write('x')
        assert exists('priv.pem')
        sys.argv = [__file__, 'genrsa', '--pub', 'pub', '--priv', 'priv.pem']
        args = _parse_args()
        GenRSA().dialog(interactive=False, args=args)

        # test cleanup
        pub, priv, pphr = GenRSA().demo_rsa_keys()
        GenRSA()._cleanup('test cleanup', pub, priv, pphr)
        assert not exists(pub)
        assert not exists(priv)
        assert not exists(pphr)
        GenRSA()._cleanup('test cleanup', '', '', '')
        assert GenRSA()._cleanup('test cleanup', 'x', 'x', 'x') == (None, ) * 3
Esempio n. 4
0
 def test_logging(self):
     sys.argv = [__file__, '--pad', 'no file', '--verbose']
     args = _parse_args()
     log_test = set_logging()
     log_test.debug('trigger coverage of debug log')
Esempio n. 5
0
    def test_main(self):
        # similar to test_command_line (those do not count toward coverage)

        sys.argv = [__file__, '--help']
        with pytest.raises(SystemExit):
            args = _parse_args()

        sys.argv = [__file__, 'genrsa', '-a']
        with pytest.raises(SystemExit):
            main(_parse_args())

        tmp = 'tmp'
        with open(tmp, write_mode) as fd:
            fd.write('a')
        hmac = 'hmac'
        with open(hmac, write_mode) as fd:
            fd.write('hmac here')

        sys.argv = [__file__, '--pad', '-z', '0', tmp]
        main(_parse_args())

        pub, priv, pphr = _known_values()[:3]
        sys.argv = [
            __file__, '--encrypt', '--keep', '--pub', pub, '-z', '0', tmp
        ]
        main(_parse_args())
        sys.argv = [
            __file__, '--encrypt', '--keep', '--pub', pub, '-z', '0', '--hmac',
            hmac, '--nodate', '--nometa', tmp
        ]
        main(_parse_args())

        sys.argv = [
            __file__, '--decrypt', '--keep', '--priv', priv, '--pphr', pphr,
            tmp + ENC_EXT
        ]
        main(_parse_args())

        sys.argv = [
            __file__, '--rotate', '--pub', pub, '-z', '0', '--hmac', hmac,
            '--priv', priv, '--pphr', pphr, tmp + ENC_EXT
        ]
        out = main(_parse_args())
        assert 'hmac' in out

        sys.argv = [
            __file__, '--sign', tmp, '--priv', priv, '--pphr', pphr, '--out',
            'sig.cmdline'
        ]
        outs = main(_parse_args())
        contents = open(outs['out'], read_mode).read()
        if openssl_version < 'OpenSSL 1.0':
            assert "mrKDFi4NrfJVTm+RLB+dHuSHNImUl9" in outs['sig']
            assert "mrKDFi4NrfJVTm+RLB+dHuSHNImUl9" in contents
        else:
            assert 'An3qI8bOdvuKt9g7a+fdFoEdh79Iip' in outs['sig']
            assert "An3qI8bOdvuKt9g7a+fdFoEdh79Iip" in contents

        sys.argv = [
            __file__, '--verify', tmp, '--sig', outs['out'], '--pub', pub
        ]
        outv = main(_parse_args())
        assert outv['verified'] == True

        sys.argv = [__file__, '--pad', tmp + tmp]
        with pytest.raises(ArgumentError):  # no such file, bad name
            main(_parse_args())

        sys.argv = [__file__, '--pad', '-z', '-24', tmp]  # bad size
        with pytest.raises(ValueError):
            main(_parse_args())

        # misc coverage
        sys.argv = [__file__, tmp, '--unpad']
        main(_parse_args())
        sys.argv = [__file__, tmp, '--hardlinks']
        main(_parse_args())
        sys.argv = [__file__, tmp, '--tracked']
        main(_parse_args())
        sys.argv = [__file__, tmp, '--permissions']
        main(_parse_args())
        sys.argv = [__file__, tmp, '--dropbox']
        main(_parse_args())

        # no actual action:
        sys.argv = [__file__, '--nocheck', tmp]
        main(_parse_args())

        # destroy last
        sys.argv = [__file__, '--destroy', tmp]
        main(_parse_args())

        # check with missing arguments (from commandline get usage string)
        sys.argv = [__file__]
        with pytest.raises(SystemExit):
            main(_parse_args())
Esempio n. 6
0
 def test_logging(self):
     sys.argv = [__file__, '--pad', 'no file', '--verbose']
     args = _parse_args()
     log_test = set_logging()
     log_test.debug('trigger coverage of debug log')