Example #1
0
def test_get_secret_password():
    """Verify expected secret token is returned."""
    password = '******'
    user = '******'

    test_data = {
        'items': [{
            'data': {
                'password':
                base64.b64encode(password.encode('utf-8')).decode('utf-8'),
                'username':
                base64.b64encode(user.encode('utf-8')).decode('utf-8'),
            }
        }]
    }
    secrets = json.dumps(test_data).encode('utf-8')

    # non-existent secret should return None
    with mock.patch(
            'lib.charms.layer.kubernetes_master.kubernetes_common.kubectl',
            return_value=secrets):
        assert charmlib.get_secret_password('missing') is None

    # known user should return our test data
    with mock.patch(
            'lib.charms.layer.kubernetes_master.kubernetes_common.kubectl',
            return_value=secrets):
        assert charmlib.get_secret_password(user) == password
def test_get_secret_password():
    """Verify expected secret token is returned."""
    password = "******"
    user = "******"

    test_data = {
        "items": [{
            "data": {
                "password":
                base64.b64encode(password.encode("utf-8")).decode("utf-8"),
                "username":
                base64.b64encode(user.encode("utf-8")).decode("utf-8"),
            }
        }]
    }
    secrets = json.dumps(test_data).encode("utf-8")

    # non-existent secret should return None
    with mock.patch(
            "lib.charms.layer.kubernetes_master.kubernetes_common.kubectl",
            return_value=secrets,
    ):
        assert charmlib.get_secret_password("missing") is None

    # known user should return our test data
    with mock.patch(
            "lib.charms.layer.kubernetes_master.kubernetes_common.kubectl",
            return_value=secrets,
    ):
        assert charmlib.get_secret_password(user) == password