Skip to content

Commit

Permalink
Merge pull request #101 from JaurbanRH/anonymous
Browse files Browse the repository at this point in the history
Add test for anonymous identity
  • Loading branch information
pehala authored Sep 23, 2022
2 parents be41f04 + 4b1863d commit a97f6f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions testsuite/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def add_oidc_identity(self, name, endpoint):
def add_api_key_identity(self, name, all_namespaces, match_label, match_expression):
"""Adds API Key identity"""

@abc.abstractmethod
def add_anonymous_identity(self, name):
"""Adds anonymous identity"""

@abc.abstractmethod
def remove_all_identities(self):
"""Removes all identities from AuthConfig"""
Expand Down
6 changes: 6 additions & 0 deletions testsuite/openshift/objects/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def add_api_key_identity(self, name, all_namespaces: bool = False,
}
})

@modify
def add_anonymous_identity(self, name):
"""Adds anonymous identity"""
identities = self.model.spec.setdefault("identity", [])
identities.append({"name": name, "anonymous": {}})

@modify
def add_role_rule(self, name: str, role: str, path: str, metrics=False, priority=0):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Test for anonymous identity"""
import pytest


@pytest.fixture(scope="module")
def authorization(authorization, rhsso):
"""Add RHSSO identity"""
authorization.add_oidc_identity("rhsso", rhsso.well_known["issuer"])
return authorization


def test_anonymous_identity(client, auth, authorization):
"""
Setup:
- Create AuthConfig with RHSSO identity
Test:
- Send request with authentication
- Assert that response status code is 200
- Send request without authentication
- Assert that response status code is 401 (Unauthorized)
- Add anonymous identity
- Send request without authentication
- Assert that response status code is 200
"""
response = client.get("/get", auth=auth)
assert response.status_code == 200

response = client.get("/get")
assert response.status_code == 401

authorization.add_anonymous_identity("anonymous")

response = client.get("/get")
assert response.status_code == 200

0 comments on commit a97f6f6

Please sign in to comment.