From dfe06614098fd2f457df624331b796bbd5fe5080 Mon Sep 17 00:00:00 2001 From: MueezKhan246 <93375917+MueezKhan246@users.noreply.github.com> Date: Tue, 28 May 2024 17:50:47 +0500 Subject: [PATCH] Removed blackboard unencrypted columns from models ent8010 (#2096) feat: removed client_id and client_secret from db models --- CHANGELOG.rst | 6 +- enterprise/__init__.py | 2 +- .../migrations/0022_auto_20240507_1057.py | 21 +++++++ integrated_channels/blackboard/models.py | 22 -------- integrated_channels/blackboard/views.py | 4 +- tests/test_enterprise/api/test_views.py | 4 +- .../test_blackboard/test_client.py | 12 ++-- .../test_exporters/test_learner_data.py | 4 +- .../test_transmitters/test_learner_data.py | 4 +- .../test_blackboard/test_views.py | 55 ++++++++++++------- 10 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 integrated_channels/blackboard/migrations/0022_auto_20240507_1057.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0c50b715f0..70c463137e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,7 +17,11 @@ Unreleased ---------- * nothing unreleased -[4.18.4] +[4.19.5] +-------- +* feat: removed unencrypted columns of user data credentials in blackboard config ENT 8010 + +[4.19.4] -------- * feat: removed unencrypted columns of user data credentials in blackboard config ENT 8010 diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 5704233f8c..52b95d0652 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.19.4" +__version__ = "4.19.5" diff --git a/integrated_channels/blackboard/migrations/0022_auto_20240507_1057.py b/integrated_channels/blackboard/migrations/0022_auto_20240507_1057.py new file mode 100644 index 0000000000..1fffd54d78 --- /dev/null +++ b/integrated_channels/blackboard/migrations/0022_auto_20240507_1057.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.23 on 2024-05-07 10:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('blackboard', '0021_auto_20240423_1057'), + ] + + operations = [ + migrations.RemoveField( + model_name='blackboardenterprisecustomerconfiguration', + name='client_id', + ), + migrations.RemoveField( + model_name='blackboardenterprisecustomerconfiguration', + name='client_secret', + ), + ] diff --git a/integrated_channels/blackboard/models.py b/integrated_channels/blackboard/models.py index 982d8d29d6..7c906909d3 100644 --- a/integrated_channels/blackboard/models.py +++ b/integrated_channels/blackboard/models.py @@ -99,17 +99,6 @@ class BlackboardEnterpriseCustomerConfiguration(EnterpriseCustomerPluginConfigur The Enterprise-specific configuration we need for integrating with Blackboard. """ - client_id = models.CharField( - max_length=255, - blank=True, - default='', - verbose_name="API Client ID or Blackboard Application Key", - help_text=( - "The API Client ID provided to edX by the enterprise customer to be used to make API " - "calls on behalf of the customer. Called Application Key in Blackboard" - ) - ) - decrypted_client_id = EncryptedCharField( max_length=255, blank=True, @@ -143,17 +132,6 @@ def encrypted_client_id(self, value): """ self.decrypted_client_id = value - client_secret = models.CharField( - max_length=255, - blank=True, - default='', - verbose_name="API Client Secret or Application Secret", - help_text=( - "The API Client Secret provided to edX by the enterprise customer to be used to make " - " API calls on behalf of the customer. Called Application Secret in Blackboard" - ) - ) - decrypted_client_secret = EncryptedCharField( max_length=255, blank=True, diff --git a/integrated_channels/blackboard/views.py b/integrated_channels/blackboard/views.py index cdb5e1801a..1035f82556 100644 --- a/integrated_channels/blackboard/views.py +++ b/integrated_channels/blackboard/views.py @@ -194,7 +194,7 @@ def _create_auth_header(self, enterprise_config, blackboard_global_config): """ Auth header in oauth2 token format as per Blackboard doc """ - app_key = enterprise_config.client_id + app_key = enterprise_config.decrypted_client_id if not app_key: if not blackboard_global_config.app_key: raise NotFound( @@ -202,7 +202,7 @@ def _create_auth_header(self, enterprise_config, blackboard_global_config): HTTPStatus.INTERNAL_SERVER_ERROR.value ) app_key = blackboard_global_config.app_key - app_secret = enterprise_config.client_secret + app_secret = enterprise_config.decrypted_client_secret if not app_secret: if not blackboard_global_config.app_secret: raise NotFound( diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index 84ef46ade2..dd681a4069 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -1706,8 +1706,8 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews): 'enterprise_customer_id': FAKE_UUIDS[0], 'enterprise_customer__uuid': FAKE_UUIDS[0], 'blackboard_base_url': 'foobar', - 'client_id': 'client_id', - 'client_secret': 'client_secret', + 'decrypted_client_id': 'client_id', + 'decrypted_client_secret': 'client_secret', 'refresh_token': 'token', 'active': True, 'enterprise_customer__name': 'Test Enterprise Customer', diff --git a/tests/test_integrated_channels/test_blackboard/test_client.py b/tests/test_integrated_channels/test_blackboard/test_client.py index 654f2fe934..9f7ab56694 100644 --- a/tests/test_integrated_channels/test_blackboard/test_client.py +++ b/tests/test_integrated_channels/test_blackboard/test_client.py @@ -37,8 +37,8 @@ def setUp(self): self.token = 'token' self.global_config = BlackboardGlobalConfigurationFactory() self.enterprise_config = BlackboardEnterpriseCustomerConfigurationFactory( - client_id='id', - client_secret='secret', + decrypted_client_id='id', + decrypted_client_secret='secret', blackboard_base_url='https://base.url', refresh_token=self.token, ) @@ -78,8 +78,8 @@ def test_client_pulls_auth_creds_from_global_if_not_found(self): def test_oauth_absent_refresh_token_fails(self): enterprise_config = BlackboardEnterpriseCustomerConfigurationFactory( - client_id='id2', - client_secret='secret', + decrypted_client_id='id2', + decrypted_client_secret='secret', blackboard_base_url='https://base.url.2', refresh_token='', ) @@ -94,8 +94,8 @@ def test_oauth_valid_refresh_token_replaces_existing(self): a valid refresh_token is used to replace it, and access_token is obtained """ enterprise_config = BlackboardEnterpriseCustomerConfigurationFactory( - client_id='id3', - client_secret='secret', + decrypted_client_id='id3', + decrypted_client_secret='secret', blackboard_base_url='https://base.url.3', refresh_token='a-token', ) diff --git a/tests/test_integrated_channels/test_blackboard/test_exporters/test_learner_data.py b/tests/test_integrated_channels/test_blackboard/test_exporters/test_learner_data.py index 534fab40bc..5db1387af3 100644 --- a/tests/test_integrated_channels/test_blackboard/test_exporters/test_learner_data.py +++ b/tests/test_integrated_channels/test_blackboard/test_exporters/test_learner_data.py @@ -31,8 +31,8 @@ def setUp(self): self.config = factories.BlackboardEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, blackboard_base_url='foobar', - client_id='client_id', - client_secret='client_secret', + decrypted_client_id='client_id', + decrypted_client_secret='client_secret', refresh_token='token', ) diff --git a/tests/test_integrated_channels/test_blackboard/test_transmitters/test_learner_data.py b/tests/test_integrated_channels/test_blackboard/test_transmitters/test_learner_data.py index 0e64993d2e..3b3c350a7a 100644 --- a/tests/test_integrated_channels/test_blackboard/test_transmitters/test_learner_data.py +++ b/tests/test_integrated_channels/test_blackboard/test_transmitters/test_learner_data.py @@ -34,8 +34,8 @@ def setUp(self): self.enterprise_config = factories.BlackboardEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, blackboard_base_url='foobar', - client_id='client_id', - client_secret='client_secret', + decrypted_client_id='client_id', + decrypted_client_secret='client_secret', refresh_token='token', ) self.completion_payload = BlackboardLearnerDataTransmissionAudit( diff --git a/tests/test_integrated_channels/test_blackboard/test_views.py b/tests/test_integrated_channels/test_blackboard/test_views.py index 6d99f98448..76da76637b 100644 --- a/tests/test_integrated_channels/test_blackboard/test_views.py +++ b/tests/test_integrated_channels/test_blackboard/test_views.py @@ -56,25 +56,42 @@ def setUp(self): self.refresh_token = 'test-refresh-token' self.urlbase = reverse('blackboard-oauth-complete') - BlackboardEnterpriseCustomerConfiguration.objects.get_or_create( - uuid=SINGLE_CONFIG['uuid'], - client_id=SINGLE_CONFIG['client_id'], - client_secret=SINGLE_CONFIG['client_secret'], - blackboard_base_url=SINGLE_CONFIG['base_url'], - enterprise_customer=self.enterprise_customer, - active=True, - enterprise_customer_id=ENTERPRISE_ID, - ) - - BlackboardEnterpriseCustomerConfiguration.objects.get_or_create( - uuid=SECOND_CONFIG['uuid'], - client_id=SECOND_CONFIG['client_id'], - client_secret=SECOND_CONFIG['client_secret'], - blackboard_base_url=SECOND_CONFIG['base_url'], - enterprise_customer=self.enterprise_customer, - active=True, - enterprise_customer_id=ENTERPRISE_ID, - ) + try: + BlackboardEnterpriseCustomerConfiguration.objects.get( + uuid=SINGLE_CONFIG['uuid'], + blackboard_base_url=SINGLE_CONFIG['base_url'], + enterprise_customer=self.enterprise_customer, + active=True, + enterprise_customer_id=ENTERPRISE_ID, + ) + except BlackboardEnterpriseCustomerConfiguration.DoesNotExist: + BlackboardEnterpriseCustomerConfiguration.objects.create( + uuid=SINGLE_CONFIG['uuid'], + decrypted_client_id=SINGLE_CONFIG['client_id'], + decrypted_client_secret=SINGLE_CONFIG['client_secret'], + blackboard_base_url=SINGLE_CONFIG['base_url'], + enterprise_customer=self.enterprise_customer, + active=True, + enterprise_customer_id=ENTERPRISE_ID, + ) + try: + BlackboardEnterpriseCustomerConfiguration.objects.get( + uuid=SECOND_CONFIG['uuid'], + blackboard_base_url=SECOND_CONFIG['base_url'], + enterprise_customer=self.enterprise_customer, + active=True, + enterprise_customer_id=ENTERPRISE_ID, + ) + except BlackboardEnterpriseCustomerConfiguration.DoesNotExist: + BlackboardEnterpriseCustomerConfiguration.objects.create( + uuid=SECOND_CONFIG['uuid'], + decrypted_client_id=SECOND_CONFIG['client_id'], + decrypted_client_secret=SECOND_CONFIG['client_secret'], + blackboard_base_url=SECOND_CONFIG['base_url'], + enterprise_customer=self.enterprise_customer, + active=True, + enterprise_customer_id=ENTERPRISE_ID, + ) def test_successful_refresh_token_by_uuid_request(self): """