Example #1
0
def test_Vault_invalid_namespace(vault_pcw, monkeypatch):
    def with_errors(*args, **kargs):
        return MockResponse({'errors': ['bla CLEMIX', 'blub']},
                            status_code=404)

    monkeypatch.setattr(requests, "post", mock_post)
    monkeypatch.setattr(requests, 'get', with_errors)

    az = AzureCredential("does_not_exists")
    with pytest.raises(ConnectionError):
        az.getData()
Example #2
0
def test_http_response_with_json_error(monkeypatch):
    az = AzureCredential(namespace)
    monkeypatch.setattr(
        requests, "post", lambda *args, **kwargs: MockResponse(
            json_response={'errors': ['err1']}))
    with pytest.raises(ConnectionError):
        az.httpPost('foobar', data={})

    monkeypatch.setattr(
        requests, "get", lambda *args, **kwargs: MockResponse(
            json_response={'errors': ['err1']}))
    with pytest.raises(ConnectionError):
        az.httpGet('foobar')
Example #3
0
def test_http_response_no_json(monkeypatch):
    az = AzureCredential(namespace)
    monkeypatch.setattr(
        requests, "post",
        lambda *args, **kwargs: MockResponse(content_type='html/text'))
    with pytest.raises(ConnectionError):
        az.httpPost('foobar', data={})

    monkeypatch.setattr(
        requests, "get",
        lambda *args, **kwargs: MockResponse(content_type='html/text'))
    with pytest.raises(ConnectionError):
        az.httpGet('foobar')
Example #4
0
def test_Vault_revoke(monkeypatch):
    global leases
    set_pcw_ini()
    monkeypatch.setattr(requests, "post", mock_post)
    monkeypatch.setattr(requests, "get", mock_get)

    az = AzureCredential(namespace)
    az.getData()
    leases = list()
    az.revoke()

    az = AzureCredential(namespace)
    az.getData()
    monkeypatch.setattr(requests, 'post', lambda *args, **kwargs: 1 / 0)
    az.revoke()
    assert az.auth_json is None
    assert az.client_token is None
    assert az.client_token_expire is None
Example #5
0
def test_AzureCredential(monkeypatch):
    set_pcw_ini()
    monkeypatch.setattr(requests, "post", mock_post)
    monkeypatch.setattr(requests, "get", mock_get)

    az = AzureCredential(namespace)
    assert az.getAuthExpire() is None
    az.revoke()
    assert az.isClientTokenExpired() is True
    assert az.isExpired() is True

    client_id = az.getData()['client_id']
    assert client_id == az.getData()['client_id']
    assert az.getAuthExpire() > datetime.today()

    az.renew()
    assert client_id != az.getData()['client_id']
    az.revoke()
Example #6
0
def test_AzureCredential(vaultSetup):
    az = AzureCredential(namespace)
    assert az.getAuthExpire() is None
    az.revoke()
    assert az.isClientTokenExpired() is True
    assert az.isExpired() is True

    client_id = az.getData()['client_id']
    assert client_id == az.getData()['client_id']
    assert az.getAuthExpire() > datetime.today()

    az.renew()
    assert client_id != az.getData()['client_id']
    az.revoke()