-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: Improve SAML configuration checks and update warning messages #37377
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
base: master
Are you sure you want to change the base?
Conversation
2ba0539
to
3dd7d88
Compare
7ccd670
to
e00af91
Compare
why i change get_config() when use get_config(), it show many error, same error again again for missing metadata. So I have improved it to new logic |
d008425
to
c0f5c34
Compare
0dc6d82
to
e37bf16
Compare
a099247
to
6cf1af3
Compare
The Problem with get_config(): get_config() was mixing configuration validation with metadata validation. It was generating spam error messages about missing metadata ("No SAMLProviderData found"). It was checking both config AND metadata, but this command should only check config. Metadata checking belongs in the --pull command, not the config check command |
7de16fd
to
92dee4f
Compare
Proposed summary output:
|
0ab4058
to
93b9c21
Compare
@robrap I have updated the test cases and updated the saml config report for missing config one and kept it as warning only and added test case when it will give missing config
this will give missing config as |
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 didn't go through tests yet. This is a start. Thank you.
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
d5fb791
to
c2fcffa
Compare
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.
Some comments to help progress. I'm not sure what to do because we are clearly spinning on this PR, and there is a lot of code (especially test code) for something that we have lived without. On the one hand, I'd like to land this without putting in too much time. On the other hand, I don't want to dump in a bunch of a new code that needs to be maintained forever that isn't serving a real benefit.
It may make sense to simple drop the observability calls to simplify the code and tests a little. The point is that someone will run the command and you'll just use the output that gets reported. There will still be redundancy in the tests that could possibly get cleaned up, but this would remove some of it.
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
616df54
to
07a090f
Compare
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
85e9b5f
to
d277d54
Compare
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
f'has no direct SAML configuration and no matching default configuration was found.' | ||
) | ||
self.assertIn(expected_warning, output) | ||
self.assertIn('Missing configs: 2', output) # 1 from test + 1 from setUp |
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.
Comment can be removed.
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.
[inform] I did ask this comment to be restored, because it isn't obvious without the comment.
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
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.
Even though there are a bunch of comments, I think this is close. Thanks. The tests don't seem overly dense and redundant any longer.
self.stdout.write( | ||
f"[WARNING] {provider_info} " | ||
f"has SAML config (id={provider_config.saml_configuration_id}, enabled=False)." | ||
) |
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.
Is there supposed to be a count associated with this?
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 added the missing count tracking
"no matching default configuration was found." | ||
) | ||
null_config_count += 1 | ||
return null_config_count |
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 guess we can just go with the final return in this method.
return null_config_count |
with mock.patch('common.djangoapps.third_party_auth.models.SAMLConfiguration.current', | ||
return_value=None): |
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.
Why is this something that needs to be mocked? This is not a case we can get to with regular test data?
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.
Got it i have fixed that
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
Outdated
Show resolved
Hide resolved
f'has no direct SAML configuration and no matching default configuration was found.' | ||
) | ||
self.assertIn(expected_warning, output) | ||
self.assertIn('Missing configs: 2', output) |
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.
It may be useful to add (or restore) a quick comment about why this is 2 and not 1.
f'has no direct SAML configuration and no matching default configuration was found.' | ||
) | ||
self.assertIn(expected_warning, output) | ||
self.assertIn('Missing configs: 2', output) |
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.
Same note about the 2. You'll want a short comment explaining.
|
||
output = self._run_checks_command() | ||
|
||
self.assertIn('Missing configs: 1', output) |
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.
Assuming the following is accurate, you could add this test higher up in the file and then
you could note in comments where this goes from 1 to 2, that the setup data accounts for 1.
def test_run_checks_setup_test_data(self):
"""
Test the --run-checks command against initial setup test data.
"""
output = self._run_checks_command()
# The setup data includes a saml provider with a missing config
self.assertIn('Missing configs: 1', output)
UPDATE: This is optional. It could even check the warning. Or, you could leave this out if you appropriately comment the other 2s.
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.
Done! Added test_run_checks_setup_test_data to validate the baseline setup data. Updated all test assertions with clarifying comments - the setUp contributes 1 to "Disabled configs" (not "Missing configs" as I initially thought). All tests now pass and clearly show how counts change from the baseline.
f'has no direct SAML configuration and no matching default configuration was found.' | ||
) | ||
self.assertIn(expected_warning, output) | ||
self.assertIn('Missing configs: 2', output) # 1 from test + 1 from setUp |
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.
[inform] I did ask this comment to be restored, because it isn't obvious without the comment.
c9300d2
to
54fc1d9
Compare
Description
Improve SAML command to stop wrong warnings. Tests updated too.
Private Ticket
https://2u-internal.atlassian.net/jira/software/c/projects/BOMS/boards/3017?assignee=712020%3A61c35560-3472-4e12-b833-884e5c4bbff4&selectedIssue=BOMS-64
Related PR
#37330
Saml Configuration Report