Skip to content

Conversation

@ktyagiapphelix2u
Copy link
Contributor

@ktyagiapphelix2u ktyagiapphelix2u commented Jun 26, 2025

Description

Issue
When a new version of a SAMLConfiguration was created, the related SAMLProviderConfig (which depends on it) still pointed to the old version. This caused problems because the provider was using outdated SAML settings. Updating it required manual work, which sometimes led to mistakes in production.

Solution
This update changes the logic so that whenever a new SAMLConfiguration is created, a new SAMLProviderConfig is also created. The new provider config automatically points to the latest SAML configuration. This avoids manual updates and makes sure provider configs always use the most recent SAML settings.

Testing
You can test the changes in SQL Workbench using these queries:

View all SAML configurations:
SELECT * FROM edxapp.third_party_auth_samlconfiguration;

View all SAML provider configs:
SELECT * FROM edxapp.third_party_auth_samlproviderconfig;

(Optional) Delete all provider configs:
SET sql_safe_updates = 0;
DELETE FROM edxapp.third_party_auth_samlproviderconfig;

Private Ticket Link

BOMS-64

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not really get a chance to review. Just one comment you can adjust before I get to this. Thank you.

@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from 4f7fd1b to 76e98a2 Compare June 27, 2025 05:52
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not review tests, but you are free to get them working. As noted, I don't think you manually tested yet, right?


# Fall back to default configuration
try:
default_config = SAMLConfiguration.current(self.site_id, 'default')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this fail, or does it just return None? I think SAMLConfiguration.current(self.site_id, 'default') was used in the legacy implementation outside of a try block, correct?

@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from 5f96401 to cad5278 Compare July 7, 2025 08:47
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, but I did not review tests yet. I made some proposals for some big simplifications, and we can discuss as needed. I also tried to provide some help learning how to avoid unnecessary comments, and how to better handle custom attributes.

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I just provided some high-level comments for unit tests, because other adjustments need to happen first.
  2. I'm guessing this didn't go through a thorough local re-review before getting to me. I don't know what the right balance is. On the one hand, you are responding to my comments, so I make sense as the re-reviewer. On the other hand, we are trying to get your team up-to-speed enough where US reviews are either not needed, or just light confirmations at the end. If your team doesn't get a chance to do these re-reviews before getting to me, it will make this process take longer overall, even though a single PR might go faster. FYI: @vgulati-apphelix

Thanks.

@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from 92eb914 to 0cca2ec Compare July 28, 2025 06:16
@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from d53c193 to 0b7cd8b Compare July 28, 2025 07:46
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was noted in Slack that I should re-review this, but I don't see anyone on this PR from AppHelix that gave a thumbs up from an internal review. I went ahead and reviewed.

Also, I appreciate when you respond to each of my comments like you mostly did. Some did not have a comment though. I have mostly marked old comments as Resolved.

self.provider_config.refresh_from_db()
self.assertEqual(self.provider_config.saml_configuration_id, old_config.id)

def setUp(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If you add a setUp function, it should be first in the class to help the reader.
  2. Compare this to the other setUp method. Why are factory methods used elsewhere? See https://github.com/openedx/edx-platform/blob/0b7cd8bc0923161a620bb648339ecbb35980eb95/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py#L71-L72.



@ddt.ddt
class TestSAMLConfigurationManagementCommand(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what TestSAMLCommand is for? Aren't we just adding additional tests for the same command? Is it possible to reuse its setup?

@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch 2 times, most recently from 7550a83 to a4324ca Compare August 1, 2025 08:26
@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from c519c44 to 9b085b2 Compare August 1, 2025 12:47
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to get to through this review, but posting what little I added.

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: All my comments are nits at this point. Feel free to update what you will and we should try to go over and merge in the morning. Thanks.

Comment on lines 106 to 113
error_calls = [
call for call in mock_set_custom_attribute.mock_calls
if call[1][0] == 'saml_config_signal.error_message'
]
assert error_calls, (
f"Expected 'saml_config_signal.error_message' call for {description}, "
f"got: {mock_set_custom_attribute.mock_calls}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like assert_has_call (or calls?) would be more clean, but maybe I'm missing something? Maybe this is all setup for the following assertion, which may be unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@ktyagiapphelix2u ktyagiapphelix2u force-pushed the ktyagi/enahnce_saml_config_2 branch from 6dffd6b to d003083 Compare August 12, 2025 06:50
@robrap robrap merged commit 14cdbc8 into openedx:master Aug 12, 2025
49 checks passed
@ktyagiapphelix2u ktyagiapphelix2u deleted the ktyagi/enahnce_saml_config_2 branch August 12, 2025 14:40
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants