How to use keyring - 10 common examples

To help you get started, we’ve selected a few keyring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github easybuilders / easybuild-framework / test / framework / suite.py View on Github external
import test.framework.variables as v
import test.framework.yeb as y

# set plain text key ring to be used,
# so a GitHub token stored in it can be obtained without having to provide a password
try:
    # with recent versions of keyring, PlaintextKeyring comes from keyrings.alt
    import keyring
    from keyrings.alt.file import PlaintextKeyring
    keyring.set_keyring(PlaintextKeyring())
except ImportError as err:
    try:
        # with old versions of keyring, PlaintextKeyring comes from keyring.backends
        import keyring
        from keyring.backends.file import PlaintextKeyring
        keyring.set_keyring(PlaintextKeyring())
    except ImportError as err:
        pass

# disable all logging to significantly speed up tests
fancylogger.disableDefaultHandlers()
fancylogger.setLogLevelError()


# make sure temporary files can be created/used
try:
    set_tmpdir(raise_error=True)
except EasyBuildError, err:
    sys.stderr.write("No execution rights on temporary files, specify another location via $TMPDIR: %s\n" % err)
    sys.exit(1)

# initialize logger for all the unit tests
github and3rson / nineapi / keyring_tests.py View on Github external
from unittest import TestCase
from nineapi.client import Client, APIException
import os
import sys
import keyring

#While using the program the follwing command should be run only once,the system will store the creds.
username=""
password="" #This should be removed after setting the password
keyring.set_password('9gag',username,password)

class APITest(TestCase):
    def setUp(self):
        self.client = Client()
        self.username = username
        self.password = keyring.get_password('9gag',username)

    def test_log_in_good(self):
        response = self.client.log_in(self.username, self.password)
        self.assertEqual(response, True)

    def test_log_in_bad(self):
        self.assertRaises(APIException, lambda: self.client.log_in(self.username, self.password + 'wrong'))

    def test_get_posts(self):
        self.test_log_in_good()
github major / supernova / tests / test_credentials.py View on Github external
def test_reject_confirmation(self, monkeypatch):
        def mockreturn(path):
            return False
        monkeypatch.setattr(utils, "confirm_credential_display", mockreturn)
        keyring.set_keyring(TestKeyring())
        result = credentials.get_user_password('prod', 'prodpass')
        assert result is None
github major / supernova / tests / test_credentials.py View on Github external
def test_pull_env_credential_global(self):
        keyring.set_keyring(TestKeyring())
        result = credentials.pull_env_credential('prod',
                                                 'OS_PASSWORD',
                                                 'USE_KEYRING["prodpass"]'
                                                 )
        assert isinstance(result, tuple)
        assert result[0] == 'global:prodpass'
        if six.PY3:
            assert result[1] == b'password from TestKeyring'
        else:
            assert result[1] == 'password from TestKeyring'
github saltstack / salt / tests / unit / utils / test_cloud.py View on Github external
def supported(self):
            return 0

        def set_password(self, servicename, username, password):
            self.__storage.setdefault(servicename, {}).update({username: password})
            return 0

        def get_password(self, servicename, username):
            return self.__storage.setdefault(servicename, {}).get(username, None)

        def delete_password(self, servicename, username):
            self.__storage.setdefault(servicename, {}).pop(username, None)
            return 0

    # set the keyring for keyring lib
    keyring.set_keyring(TestKeyring())
    HAS_KEYRING = True
except ImportError:
    HAS_KEYRING = False

os.chdir(CODE_DIR)


class CloudUtilsTestCase(TestCase):

    def test_ssh_password_regex(self):
        '''Test matching ssh password patterns'''
        for pattern in ('Password for root@127.0.0.1:',
                        'root@127.0.0.1 Password:',
                        ' Password:'):
            self.assertNotEqual(
                cloud.SSH_PASSWORD_PROMP_RE.match(pattern), None
github major / supernova / tests / test_credentials.py View on Github external
def test_set_user_password(self):
        keyring.set_keyring(TestKeyring())
        environment = "prod"
        parameter = "prodpass"
        password = "supersecurepassword"
        result = credentials.set_user_password(environment, parameter,
                                               password)
        assert result
github major / supernova / tests / test_credentials.py View on Github external
def test_get_user_password(self):
        keyring.set_keyring(TestKeyring())
        result = credentials.get_user_password('prod', 'prodpass', force=True)
        assert result[0] == 'prod:prodpass'
        if six.PY3:
            assert result[1] == b'password from TestKeyring'
        else:
            assert result[1] == 'password from TestKeyring'
github major / supernova / tests / test_credentials.py View on Github external
import keyring.backend


import pytest


import six


from supernova import credentials, utils


class TestKeyring(keyring.backend.KeyringBackend):
    """A test keyring which always outputs same password
    """
    priority = 1

    def set_password(self, servicename, username, password):
        pass

    def get_password(self, servicename, username):
        return "password from TestKeyring"

    def delete_password(self, servicename, username, password):
        pass


class TestCredentials(object):
github blue-yonder / bonfire / tests / test_config.py View on Github external
@author = mharder
'''

from __future__ import division, print_function

from bonfire.utils import api_from_config

from bonfire.config import get_config, get_templated_option, get_password_from_keyring, store_password_in_keyring

import arrow
import keyring
import keyring.backend


class TestKeyring(keyring.backend.KeyringBackend):
    """A test keyring which always outputs same password
    """
    priority = 1

    def set_password(self, servicename, username, password):
        self.password = password

    def get_password(self, servicename, username):
        return self.password

    def delete_password(self, servicename, username, password):
        self.password = ""


keyring.set_keyring(TestKeyring())
github python-poetry / poetry / tests / utils / test_helpers_keyring.py View on Github external
self._storage[servicename] = dict()
        self._storage[servicename][username] = password

    def get_password(self, servicename, username):
        if servicename in self._storage:
            return self._storage[servicename].get(username)

    def delete_password(self, servicename, username):
        if servicename in self._storage:
            if username in self._storage[servicename]:
                del self._storage[servicename][username]
            if not self._storage[servicename]:
                del self._storage[servicename]


class BrokenKeyring(KeyringBackend):
    priority = 1

    def set_password(self, servicename, username, password):
        raise KeyringError()

    def get_password(self, servicename, username):
        raise KeyringError()

    def delete_password(self, servicename, username):
        raise KeyringError()


@pytest.fixture
def keyring():  # type: () -> KeyringBackend
    k = DictKeyring()
    set_keyring(k)