-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
llow direct communication to Openshift API through
get_federated_user
As the first step towards merging the account manager into our coldfront cloud plugin, the `get_federated_user` function in the Openshift allocator will now (through several functions) directly call the Openshift API. Much of the functions added are copied from the `moc_openshift` module in the account manager. Aside from copying some functions, implementation of this feature also involved: - A new resource attribute `Identity Name` for the Openshift idp - A new unit test for the `get_federated_user` function - Changes to the CI file to enable these new unit tests
- Loading branch information
Showing
6 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/coldfront_plugin_cloud/tests/unit/openshift/test_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from unittest import mock | ||
|
||
from coldfront_plugin_cloud.tests import base | ||
from coldfront_plugin_cloud.openshift import OpenShiftResourceAllocator | ||
|
||
|
||
class TestOpenshiftUser(base.TestBase): | ||
def setUp(self) -> None: | ||
mock_resource = mock.Mock() | ||
mock_allocation = mock.Mock() | ||
self.mock_openshift_allocator = OpenShiftResourceAllocator(mock_resource, mock_allocation) | ||
self.mock_openshift_allocator.id_provider = "fake_idp" | ||
self.mock_openshift_allocator.logger = mock.Mock() | ||
self.mock_openshift_allocator.k8_client = mock.Mock() | ||
|
||
def test_get_federated_user(self): | ||
fake_user = mock.Mock(spec=["to_dict"]) | ||
fake_user.to_dict.return_value = {"identities": ["fake_idp:fake_user"]} | ||
self.mock_openshift_allocator.k8_client.resources.get.return_value.get.return_value = fake_user | ||
|
||
output = self.mock_openshift_allocator.get_federated_user("fake_user") | ||
self.assertEqual(output, {"username": "fake_user"}) | ||
|
||
def test_get_federated_user(self): | ||
fake_user = mock.Mock(spec=["to_dict"]) | ||
fake_user.to_dict.return_value = {"identities": ["fake_idp:fake_user"]} | ||
self.mock_openshift_allocator.k8_client.resources.get.return_value.get.return_value = fake_user | ||
|
||
output = self.mock_openshift_allocator.get_federated_user("fake_user_2") | ||
self.assertEqual(output, None) | ||
self.mock_openshift_allocator.logger.info.assert_called_with("404: user (fake_user_2) does not exist") |