示例#1
0
    def test_generate_password_uses_correct_gpg_id(self):
        store = PasswordStore(self.dir)

        def get_gpg_ids_used(filename):
            gpg = subprocess.Popen(
                [GPG_BIN, '--list-packets',
                 os.path.join(self.dir, filename)],
                shell=False,
                stdout=subprocess.PIPE)
            gpg.wait()
            pubkeys = []
            for line in gpg.stdout.readlines():
                line = line.decode()
                if line.startswith(':pubkey'):
                    pubkeys.append(line.split()[-1])

            return pubkeys

        store.generate_password('should_use_main_key')
        pubkeys = get_gpg_ids_used('should_use_main_key.gpg')
        self.assertTrue(len(pubkeys) == 1)
        self.assertEqual(pubkeys[0], '6C8110881C10BC07')

        store.generate_password('Email/should_use_secondary_key')
        pubkeys = get_gpg_ids_used(
            os.path.join('Email', 'should_use_secondary_key.gpg'))
        self.assertTrue(len(pubkeys) == 1)
        self.assertEqual(pubkeys[0], '4B52397C4C1C5D70')
示例#2
0
    def test_get_decrypted_password_specific_entry(self):
        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        # When there is no 'password:'******'ELLO',
            store.get_decrypted_password('hello.com',
                                         entry=EntryType.password))

        store.insert_password('hello.com', 'sdfsdf\npassword: pwd')
        self.assertEqual(
            'pwd',
            store.get_decrypted_password('hello.com',
                                         entry=EntryType.password))

        store.insert_password(
            'hello', 'sdf\npassword: pwd\nusername: bob\nhost: salut.fr')
        self.assertEqual(
            'bob',
            store.get_decrypted_password('hello', entry=EntryType.username))
        self.assertEqual(
            'salut.fr',
            store.get_decrypted_password('hello', entry=EntryType.hostname))
示例#3
0
文件: main.py 项目: toXel/pass_export
def main():
    store = PasswordStore()
    entries = store.get_passwords_list()
    with open('pass.csv', 'w', newline='') as csvfile:
        csvwriter = csv.writer(csvfile)
        for entry in entries:
            csvwriter.writerow(parse(entry, store))
示例#4
0
 def test_get_decrypted_password_only_password(self):
     store = PasswordStore(self.dir)
     password = '******'
     store.insert_password('hello.com', password)
     self.assertEqual(
         'ELLO',
         store.get_decrypted_password('hello.com')
     )
示例#5
0
 def test_get_passwords_list(self):
     store = PasswordStore(self.dir)
     self.assertListEqual(
         sorted(store.get_passwords_list()),
         sorted([
             'test.com',
             'linux.ca',
             'passwordstore.org',
             'Email/email.com',
         ]))
示例#6
0
    def test_constructor(self):
        # Construct on properly initialized directory
        store = PasswordStore(self.dir)
        self.assertEqual(store._get_gpg_id(self.dir), '5C5833E3')
        self.assertFalse(store.uses_git)
        self.assertEqual(self.dir, store.path)

        # Fail gracefully on missing .gpg-id
        gpg_id_path = os.path.join(self.dir, '.gpg-id')
        os.remove(gpg_id_path)
        self.assertRaises(Exception, PasswordStore, self.dir)
示例#7
0
 def test_get_decrypted_password_deeply_nested(self):
     store = PasswordStore(self.dir)
     self.assertFalse(os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C')))
     store.insert_password('A/B/C/D/hello.com', 'Alice')
     store.insert_password('A/B/C/hello.com', 'Bob')
     self.assertEqual('Alice',
                      store.get_decrypted_password('A/B/C/D/hello.com'))
     self.assertEqual('Bob',
                      store.get_decrypted_password('A/B/C/hello.com'))
     self.assertTrue(
         os.path.isdir(os.path.join(self.dir, 'A', 'B', 'C', 'D')))
示例#8
0
    def test_encrypt_decrypt(self):
        self.assertFalse(
            os.path.isfile(os.path.join(self.dir, 'hello.com.gpg')))

        store = PasswordStore(self.dir)
        password = '******'
        store.insert_password('hello.com', password)

        self.assertTrue(os.path.isfile(os.path.join(self.dir,
                                                    'hello.com.gpg')))

        self.assertEqual(password, store.get_decrypted_password('hello.com'))
示例#9
0
    def test_generate_in_place(self):
        store = PasswordStore(self.dir)

        self.assertRaises(Exception,
                          store.generate_password,
                          'nope.org',
                          first_line_only=True)

        store.insert_password('nope.org', 'pw\nremains intact')
        store.generate_password('nope.org', length=3, first_line_only=True)

        new_content = store.get_decrypted_password('nope.org')
        new_password, _, remainder = new_content.partition('\n')
        self.assertNotEqual(new_password, 'pw')
        self.assertEqual(remainder, 'remains intact')
示例#10
0
    def test_generate_password(self):
        store = PasswordStore(self.dir)

        store.generate_password('letters.net', digits=False, symbols=False)
        only_letters = store.get_decrypted_password('letters.net')
        self.assertTrue(only_letters.isalpha())

        store.generate_password('alphanum.co.uk', digits=True, symbols=False)
        alphanum = store.get_decrypted_password('alphanum.co.uk')
        self.assertTrue(alphanum.isalnum())
        for char in alphanum:
            self.assertTrue(char not in string.punctuation)

        store.generate_password('hundred.org', length=100)
        length_100 = store.get_decrypted_password('hundred.org')
        self.assertEqual(len(length_100), 100)
示例#11
0
def main(ctx, password_store_dir, password_store_git, editor):

    # init does not need any of this.
    if ctx.invoked_subcommand == "init":
        return

    # Prepare the config file
    config = {
        'password_store':
        PasswordStore(path=password_store_dir, git_dir=password_store_git),
        'editor':
        editor
    }

    ctx.obj = config

    # By default, invoke ls
    if ctx.invoked_subcommand is None:
        ctx.invoke(ls)
示例#12
0
 def test_get_decrypted_password_doesnt_exist(self):
     store = PasswordStore(self.dir)
     self.assertRaises(Exception, store.get_decrypted_password, 'nope.com')
示例#13
0
 def test_constructor(self):
     store = PasswordStore(self.dir)
     self.assertEqual(store.gpg_id, '5C5833E3')
     self.assertFalse(store.uses_git)
     self.assertEqual(self.dir, store.path)