Beispiel #1
0
    def test_decrypt(self, mock_run):
        mock_run.return_value = mock_run
        mock_run.__enter__.return_value = mock_run
        mock_run.stdout = [
            b'*** 1/2: foo.txt\n',
            b'*** 2/2: bar.txt\n',
        ]

        cli = PogCli()
        cli.set_keyfiles('foo.decrypt')
        res = list(cli.decrypt('my.mfn'))
        self.assertEqual(res, [{
            'current': 1,
            'filename': 'foo.txt',
            'total': 2
        }, {
            'current': 2,
            'filename': 'bar.txt',
            'total': 2
        }])

        env = dict(environ)
        env['PYTHONPATH'] = POG_ROOT
        mock_run.assert_called_once_with(
            [
                'python', '-u', '-m', 'pog.pog', '--decrypt', 'my.mfn',
                '--decryption-keyfile=foo.decrypt'
            ],
            env=env,
            stdout=PIPE,
        )
Beispiel #2
0
    def test_encrypt(self, mock_run):
        mock_run.return_value = mock_run
        mock_run.__enter__.return_value = mock_run
        mock_run.stdout = [
            b'*** 1/2: foo.txt\n',
            b'12345abcdefh\n',
            b'*** 2/2: bar.txt\n',
            b'abcdefg12345\n',
        ]

        cli = PogCli()
        cli.set_keyfiles('foo.decrypt', 'foo.encrypt')
        res = list(
            cli.encrypt(['foo.txt', 'bar.txt'], ['b2://bucket', 's3:bucket']))
        self.assertEqual(res, [{
            'current': 1,
            'filename': 'foo.txt',
            'total': 2
        }, {
            'current': 2,
            'filename': 'bar.txt',
            'total': 2
        }])

        env = dict(environ)
        env['PYTHONPATH'] = POG_ROOT
        mock_run.assert_called_once_with(
            [
                'python', '-u', '-m', 'pog.pog',
                '--save-to=b2://bucket,s3:bucket', 'foo.txt', 'bar.txt',
                '--encryption-keyfile=foo.encrypt'
            ],
            env=env,
            stdout=PIPE,
        )
Beispiel #3
0
    def test_keyfiles(self):
        cli = PogCli()

        # pick decryption file
        for i in range(3):
            cli.set_keyfiles('foo.encrypt', 'foo.decrypt', 'other.keyfile')
            self.assertEqual(cli.config.get('decryption-keyfile'),
                             'foo.decrypt')
            self.assertEqual(cli.config.get('encryption-keyfile'),
                             'foo.encrypt')
            self.assertEqual(cli.config.get('keyfile'), None)

        cli.set_keyfiles('foo.encrypt', 'other.keyfile')
        self.assertEqual(cli.config.get('decryption-keyfile'), None)
        self.assertEqual(cli.config.get('encryption-keyfile'), 'foo.encrypt')
        self.assertEqual(cli.config.get('keyfile'), None)

        cli.set_keyfiles('other.keyfile', 'second.keyfile')
        self.assertEqual(cli.config.get('decryption-keyfile'), None)
        self.assertEqual(cli.config.get('encryption-keyfile'), None)
        self.assertEqual(cli.config.get('keyfile'), 'other.keyfile')

        # clear
        cli.set_keyfiles()
        self.assertEqual(cli.config.get('decryption-keyfile'), None)
        self.assertEqual(cli.config.get('encryption-keyfile'), None)
        self.assertEqual(cli.config.get('keyfile'), None)
Beispiel #4
0
class TestDirMixin():
    def setUp(self):
        self.input_dir = TemporaryDirectory()

        self.tiny_sample = path.join(self.input_dir.name, 'tiny_sample.txt')
        with open(self.tiny_sample, 'wb') as f:
            f.write(b'aaaabbbb')
        utime(self.tiny_sample, times=(SAMPLE_TIME1, SAMPLE_TIME1))

        self.another_sample = path.join(self.input_dir.name,
                                        'another_sample.txt')
        with open(self.another_sample, 'wb') as f:
            f.write(b'0123456789')
        utime(self.another_sample, times=(SAMPLE_TIME2, SAMPLE_TIME2))

        self.working_dir = TemporaryDirectory()

        script = getattr(self, 'script', 'pog.pog')
        self.cli = PogCli(pog_cmd=_program_args(script))
        super().setUp()

    def tearDown(self):
        super().tearDown()
        with self.input_dir, self.working_dir:
            pass

    def run_command(self, *args, **kwargs):
        kwargs['cwd'] = self.working_dir.name
        return self.cli.run_command(*args, **kwargs)
Beispiel #5
0
    def setUp(self):
        self.input_dir = TemporaryDirectory()

        self.tiny_sample = path.join(self.input_dir.name, 'tiny_sample.txt')
        with open(self.tiny_sample, 'wb') as f:
            f.write(b'aaaabbbb')
        utime(self.tiny_sample, times=(SAMPLE_TIME1, SAMPLE_TIME1))

        self.another_sample = path.join(self.input_dir.name,
                                        'another_sample.txt')
        with open(self.another_sample, 'wb') as f:
            f.write(b'0123456789')
        utime(self.another_sample, times=(SAMPLE_TIME2, SAMPLE_TIME2))

        self.working_dir = TemporaryDirectory()

        script = getattr(self, 'script', 'pog.pog')
        self.cli = PogCli(pog_cmd=_program_args(script))
        super().setUp()
Beispiel #6
0
    def test_dump_manifest_index(self, mock_run):
        mock_run.return_value = mock_run
        mock_run.__enter__.return_value = mock_run
        mock_run.stdout = [
            b'abcdef12345\n',
            b'fghjkl34567\n',
        ]

        cli = PogCli()
        cli.set_keyfiles('foo.encrypt')
        res = list(cli.dumpManifestIndex('my.mfn'))
        self.assertEqual(res, ['abcdef12345', 'fghjkl34567'])

        env = dict(environ)
        env['PYTHONPATH'] = POG_ROOT
        mock_run.assert_called_once_with(
            [
                'python', '-u', '-m', 'pog.pog', '--dump-manifest-index',
                'my.mfn', '--encryption-keyfile=foo.encrypt'
            ],
            env=env,
            stdout=PIPE,
        )
Beispiel #7
0
 def _cli(self):
     cli = PogCli()
     cli.set_keyfiles(*self.config.get('keyfiles', []))
     return cli
Beispiel #8
0
def get_blobs(local_mfn, config):
    cl = PogCli(config)
    return set(cl.dumpManifestIndex(local_mfn))