示例#1
0
    def test_tagging(self):
        # Basic instance
        secret = Secret(
            name="LEGO",
            system="www.lego.com",
            sub_system="UI",
            type=Secret.TYPE_USER_PASS,
            data={'username': '******', 'password': '******'},
        )
        self.assertIsNotNone(secret.tags)
        self.assertIsInstance(secret.tags, set)
        self.assertEqual(len(secret.tags), 0)

        # Create with Tags
        secret.tag("lego")
        secret.tag("brick-by-brick")
        self.assertEqual(len(secret.tags), 2)
        self.assertIsInstance(list(secret.tags)[0], Tag)
        secret.save()

        # Retrieve has Tags
        secret2 = Secret(id=secret.id)
        secret2.load()
        self.assertIsNotNone(secret2.tags)
        self.assertIsInstance(secret2.tags, set)
        self.assertEqual(len(secret2.tags), 2)
        self.assertIsInstance(list(secret2.tags)[0], Tag)
        self.assertTrue(Tag(name="lego") in secret2.tags)

        # Update tags
        secret2.tag("studs-r-us")
        self.assertEqual(len(secret2.tags), 3)
        self.assertIsInstance(list(secret2.tags)[2], Tag)

        secret2.save()

        secret3 = Secret(id=secret2.id)
        secret3.load()
        self.assertIsNotNone(secret3.tags)
        self.assertIsInstance(secret3.tags, set)
        self.assertEqual(len(secret3.tags), 3)

        self.assertTrue(Tag(name="lego") in secret3.tags)
        self.assertTrue(Tag(name="brick-by-brick") in secret3.tags)
        self.assertTrue(Tag(name="studs-r-us") in secret3.tags)
示例#2
0
    def test_encryption(self):
        Secret.purge()

        stype = Secret.TYPE_USER_PASS
        username = '******'
        password = '******'
        secret = Secret(
            name="My Email Account",
            system="email.com",
            sub_system="UI",
            type=stype,
            data={'username': username, 'password': password},
            note="Personal Email **ONLY**"
        )

        self.assertEqual(secret.data['username'], username)
        self.assertEqual(secret.data['password'], password)

        secret.save()

        with open('tests/tmp/Secrets-test.json') as file:
            raw_data = json.load(file).get('_default', {}).get('1', {}).get('data')

        self.assertNotEqual(raw_data['username'], secret.data['username'])
        self.assertNotEqual(raw_data['password'], secret.data['password'])

        self.assertEqual(self.crypto.decrypt(raw_data['username']), secret.data['username'])
        self.assertEqual(self.crypto.decrypt(raw_data['password']), secret.data['password'])

        self.assertEqual(secret.data['username'], username)
        self.assertEqual(secret.data['password'], password)

        # Load and check stuff
        secret2 = Secret(id=1)
        secret2.load()

        self.assertEqual(secret2.type, stype)
        self.assertEqual(secret2.data['username'], username)
        self.assertEqual(secret2.data['password'], password)