Skip to content

Commit

Permalink
Merge pull request #81 from jsmolar/reconciliation
Browse files Browse the repository at this point in the history
Add tests for API key Secret reconciliation
  • Loading branch information
pehala authored Sep 7, 2022
2 parents 9a082f3 + 2ea15db commit c45c025
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion testsuite/openshift/objects/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import base64

from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.objects import OpenShiftObject
from testsuite.openshift.objects import OpenShiftObject, modify


class APIKey(OpenShiftObject):
Expand Down Expand Up @@ -32,3 +32,8 @@ def create_instance(cls, openshift: OpenShiftClient, name, label, api_key):
}

return cls(model, context=openshift.context)

@modify
def update_api_key(self, api_key):
"""Updates API key Secret with new API key"""
self.model.data["api_key"] = base64.b64encode(api_key.encode("utf-8")).decode('ascii')
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests Secret reconciliation for API key identity verification & authentication"""
import pytest

from testsuite.httpx.auth import HeaderApiKeyAuth


@pytest.fixture(scope="function")
def api_key(create_api_key, module_label):
"""Creates API key Secret"""
api_key = "api_key_value"
return create_api_key("api-key", module_label, api_key)


@pytest.fixture(scope="function")
def auth(api_key):
"""Valid API Key Auth"""
return HeaderApiKeyAuth(api_key)


@pytest.fixture(scope="module")
def authorization(authorization, module_label):
"""Creates AuthConfig with API key identity"""
authorization.add_api_key_identity("api_key", match_label=module_label)
return authorization


def test_create_new_api_key(client, create_api_key, module_label):
"""Test reconciliation when API key Secret is freshly created with valid label"""
api_key = create_api_key("api-key", module_label, "new_api_key")
auth = HeaderApiKeyAuth(api_key)
response = client.get("/get", auth=auth)
assert response.status_code == 200


def test_delete_api_key(client, auth, api_key):
"""Test reconciliation when API key Secret is deleted"""
response = client.get("/get", auth=auth)
assert response.status_code == 200

api_key.delete()
response = client.get("/get", auth=auth)
assert response.status_code == 401


def test_update_api_key(client, auth, api_key):
"""Test reconciliation when API key Secret is updated"""
response = client.get("/get", auth=auth)
assert response.status_code == 200

api_key.update_api_key("update_api_key")
response = client.get("/get", auth=auth)
assert response.status_code == 401

auth = HeaderApiKeyAuth(api_key)
response = client.get("/get", auth=auth)
assert response.status_code == 200

0 comments on commit c45c025

Please sign in to comment.