-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow direct communication to Openshift API through get_federated_user
#177
Open
QuanMPhm
wants to merge
1
commit into
nerc-project:main
Choose a base branch
from
QuanMPhm:175/merge_get_federated
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
29 changes: 29 additions & 0 deletions
29
src/coldfront_plugin_cloud/tests/unit/openshift/test_user.py
knikolla marked this conversation as resolved.
Show resolved
Hide resolved
|
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,29 @@ | ||
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.allocator = OpenShiftResourceAllocator(mock_resource, mock_allocation) | ||
self.allocator.id_provider = "fake_idp" | ||
self.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.allocator.k8_client.resources.get.return_value.get.return_value = fake_user | ||
|
||
output = self.allocator.get_federated_user("fake_user") | ||
self.assertEqual(output, {"username": "fake_user"}) | ||
|
||
def test_get_federated_user_not_exist(self): | ||
fake_user = mock.Mock(spec=["to_dict"]) | ||
fake_user.to_dict.return_value = {"identities": ["fake_idp:fake_user"]} | ||
self.allocator.k8_client.resources.get.return_value.get.return_value = fake_user | ||
|
||
output = self.allocator.get_federated_user("fake_user_2") | ||
self.assertEqual(output, None) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am uncomfortable that the code is "aware" of whether or not it's running under test. It seems like we should either be able to inject configuration in the tests to achieve the desired behavior, or we should be mocking out functionality as appropriate if we don't want it running during tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know from looking at git blame, this design choice was made a long time ago and is present is both the openshift and openstack allocators. I open could a new issue for this unless there were strong reasons why this design choice was made. @knikolla Do you have any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hindsight, I should have called that environment variable something like
INSECURE_HTTPS
because that's the only thing it allows AFAIK.@larsks do you want the env variable to be renamed to the above now or in a follow up patch? (there are other occurrences already present in the codebase in the other drivers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@knikolla A followup patch would be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that there's already a
OPENSHIFT_{self.safe_resource_name}_VERIFY
environment variable here, so we can rely on just that and remove the functional tests references in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The https check when making the openshift client will now only depend on
OPENSHIFT_{self.safe_resource_name}_VERIFY
. This lead to a small change in the CI fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsks are you concerns with this resolved? can you do another pass at reviewing the PR?