Example #1
0
    def test_generate_no_symbols(self):
        generate = self.run_cli(['generate', '-n', 'test.com'])
        password = generate.output.partition('\n')[2].strip()
        self.assertIsNotNone(re.match('[a-zA-Z0-9]{25}$', password))

        store = PasswordStore(self.dir)
        decoded = store.get_decrypted_password('test.com')
        self.assertEqual(decoded, password)
Example #2
0
    def test_grep(self):
        store = PasswordStore(self.dir)
        store.insert_password('grep_test.com', 'GREPME')

        grep_result = self.run_cli(['grep', 'GREPME'])
        self.assertEqual(
            grep_result.output,
            'grep_test.com:\nGREPME\n'
        )
Example #3
0
    def test_grep(self):
        store = PasswordStore(self.dir)
        store.insert_password('grep_test.com', 'GREPME')

        grep_result = self.run_cli(['grep', 'GREPME'])
        self.assertEqual(
            grep_result.output,
            'grep_test.com:\nGREPME\n'
        )
Example #4
0
    def test_edit(self):
        store = PasswordStore(self.dir)
        store.insert_password('test.com', 'editme')

        mock_editor = os.path.join(os.path.dirname(__file__), 'mock_editor.py')
        self.run_cli(['--EDITOR', mock_editor, 'edit', 'test.com'])

        edited_content = store.get_decrypted_password('test.com')
        self.assertEqual(edited_content, 'edited')
Example #5
0
    def test_show_clip(self):
        store = PasswordStore(self.dir)
        store.insert_password('clip_test', 'clipme999\nbutnotthisnewline\nfff')

        show_result = self.run_cli(['show', '-c', 'clip_test'])

        self.assertEqual(show_result.output,
                         'Copied clip_test to clipboard.\n')

        # Check if the password is in the clipoard
        xclip = subprocess.Popen(['xclip', '-o', '-selection', 'clipboard'],
                                 stdout=subprocess.PIPE)
        xclip.wait()
        self.assertEqual(xclip.stdout.read().decode('utf8'), 'clipme999')
Example #6
0
    def test_show_clip(self):
        store = PasswordStore(self.dir)
        store.insert_password('clip_test', 'clipme999\nbutnotthisnewline\nfff')

        show_result = self.run_cli(['show', '-c', 'clip_test'])

        self.assertEqual(
            show_result.output,
            'Copied clip_test to clipboard.\n'
        )

        # Check if the password is in the clipoard
        xclip = subprocess.Popen(
            ['xclip', '-o', '-selection', 'clipboard'],
            stdout=subprocess.PIPE)
        xclip.wait()
        self.assertEqual(xclip.stdout.read().decode('utf8'), 'clipme999')
Example #7
0
    def test_generate_in_place(self):
        self.run_cli(['git', 'init'])
        store = PasswordStore(self.dir)

        generate = self.run_cli(['generate', '-i', 'in-place.com'],
                                expect_failure=True)
        self.assertNotEqual(generate.exit_code, 0)

        store.insert_password('in-place.com', 'first\nsecond')
        self.run_cli(['generate', '-i', 'in-place.com', '10'])

        self.assertLastCommitMessage(
            'Replace generated password for in-place.com.')

        new_content = store.get_decrypted_password('in-place.com')
        new_password, _, remainder = new_content.partition('\n')
        self.assertEqual(len(new_password), 10)
        self.assertEqual(remainder, 'second')
Example #8
0
    def test_insert(self):
        # Multiline input should end at EOF
        self.run_cli(['insert', '-m', 'test.com'], input='first\nsecond\n')

        store = PasswordStore(self.dir)
        content = store.get_decrypted_password('test.com')
        self.assertEqual(content, 'first\nsecond\n')

        # Echo the password and ask for it only once
        insert2 = self.run_cli(['insert', '-e', 'test2.com'], input='oneLine')

        self.assertEqual(insert2.output,
                         'Enter password for test2.com: oneLine\n')

        content2 = store.get_decrypted_password('test2.com')
        self.assertEqual(content2, 'oneLine')

        # Mismatching inputs should cause abort
        insert3 = self.run_cli(['insert', 'test3.com'],
                               input='aWildPassword\nDoesntMatch',
                               expect_failure=True)
        self.assertNotEqual(insert3.exit_code, 0)