Esempio n. 1
0
def test_repr():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    assert repr(cfg) == "<AzureKeyVaultConfiguration: 'vault URL'>"
Esempio n. 2
0
def test_load_dict():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault"
    )
    cfg._kv_client = FakeSecretClient(DICT)
    assert cfg["foo"] == "foo_val"
    assert cfg["with_underscore"] == "works"
    assert cfg.get("foo", "default") == "foo_val"
Esempio n. 3
0
def test_get_attr():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    assert cfg.foo == "foo_val"

    with raises(KeyError):
        assert cfg.foo_missing is KeyError
Esempio n. 4
0
def test_missing_key():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    with raises(KeyError):
        assert cfg["foo-missing"] is KeyError

    assert cfg.get("foo-missing", "default") == "default"
Esempio n. 5
0
def test_deletion():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    assert cfg["foo"] == "foo_val"
    assert "foo" in cfg._cache
    del d["foo"]

    with raises(KeyError):
        assert cfg["foo"] is KeyError
Esempio n. 6
0
def test_str():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    # str
    assert (
        str(cfg)
        == "{'bar': 'bar_val', 'foo': 'foo_val', 'password': '******', 'with-underscore': 'works'}"
    )
    assert cfg["password"] == "some passwd"
Esempio n. 7
0
def test_reload():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault"
    )
    cfg._kv_client = FakeSecretClient(DICT)
    assert cfg == config_from_dict(DICT)

    cfg._kv_client = FakeSecretClient(DICT2)
    cfg.reload()
    assert cfg == config_from_dict(DICT2)
Esempio n. 8
0
def test_dict():  # type: ignore
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    d = DICT.copy()
    cfg._kv_client = FakeSecretClient(d)

    assert sorted(cfg.keys()) == sorted(d.keys())
    assert sorted(cfg.values()) == sorted(d.values())
    assert sorted(cfg.items()) == sorted(d.items())
Esempio n. 9
0
def test_expiration(mocker):  # type: ignore
    # with cache
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault"
    )
    cfg._kv_client = FakeSecretClient(DICT)

    spy = mocker.spy(cfg._kv_client, "get_secret")
    assert cfg["foo"] == "foo_val"
    assert cfg["foo"] == "foo_val"
    assert spy.call_count == 1

    # without cache
    cfg = AzureKeyVaultConfiguration(
        "fake_id", "fake_secret", "fake_tenant", "fake_vault", cache_expiration=0
    )
    cfg._kv_client = FakeSecretClient(DICT)

    spy = mocker.spy(cfg._kv_client, "get_secret")
    assert cfg["foo"] == "foo_val"
    assert cfg["foo"] == "foo_val"  # this will ignore the cache
    assert spy.call_count == 2