コード例 #1
0
    def test_gets_passwords_correctly(self, mock_post):
        pm = PasswordManager(key='tests/fixtures/privkey.pem')

        def encrypt_text(text):
            public_key = pm._rsa_verifier.public_key()
            encrypted_key = public_key.encrypt(text.encode('ascii'),
                                               padding.PKCS1v15())
            return base64.b64encode(bytes(encrypted_key))

        mock_response = Mock()
        mock_response.json.return_value = {
            'status': 'success',
            'password': {
                'url': encrypt_text('a'),
                'login': encrypt_text('b'),
                'passwd': encrypt_text('c'),
                'description': encrypt_text('d'),
            }
        }
        mock_post.return_value = mock_response

        passwords = pm.get_passwords('folder-name', 'password-name')

        self.assertEqual(passwords['password-name']['url'], 'a')
        self.assertEqual(passwords['password-name']['login'], 'b')
        self.assertEqual(passwords['password-name']['password'], 'c')
        self.assertEqual(passwords['password-name']['description'], 'd')
コード例 #2
0
    def test_request_to_get_password_returns_error(self, mock_post):
        mock_response = Mock()
        mock_response.json.return_value = {'status': 'error', 'password': ''}
        mock_post.return_value = mock_response
        pm = PasswordManager(key='tests/fixtures/privkey.pem')

        passwords = pm.get_passwords('folder-name', 'password-name')

        self.assertDictEqual(passwords, {})
コード例 #3
0
    def test_gets_passwords_correctly_vault_true(self, mock_post):
        pm = PasswordManager(key='tests/fixtures/privkey.pem')

        def b64_encode(text):
            return base64.b64encode(bytes(text, 'utf-8')).decode()

        mock_response = Mock()
        mock_response.json.return_value = {
            'status': 'success',
            'password': {
                'url': b64_encode('a'),
                'login': b64_encode('b'),
                'passwd': b64_encode('c'),
                'description': b64_encode('d'),
                'vault': True
            }
        }
        mock_post.return_value = mock_response

        passwords = pm.get_passwords('folder-name', 'password-name')
        self.assertEqual(passwords['password-name']['url'], 'a')
        self.assertEqual(passwords['password-name']['login'], 'b')
        self.assertEqual(passwords['password-name']['password'], 'c')
        self.assertEqual(passwords['password-name']['description'], 'd')
コード例 #4
0
    def test_try_to_get_password_but_password_name_is_not_passed(self):
        pm = PasswordManager(key='tests/fixtures/privkey.pem')

        passwords = pm.get_passwords('folder-name')

        self.assertDictEqual(passwords, {})