Skip to content

Commit

Permalink
fix: fixed the failing test cases for the canvas views
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeramin committed Aug 28, 2024
1 parent 3cb417d commit 401cf73
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
11 changes: 0 additions & 11 deletions enterprise/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,6 @@ def generate_default_orchestration_record_display_name(sender, instance, **kwarg
instance.display_name = f'SSO-config-{instance.identity_provider}-{num_records_for_customer + 1}'


@receiver(pre_save, sender=CanvasEnterpriseCustomerConfiguration)
def mirror_id_and_secret_to_decrypted_fields(sender, instance, **kwargs): # pylint: disable=unused-argument
"""
Mirror the client_id and client_secret to the decrypted fields.
"""
if instance.client_id != instance.decrypted_client_id:
instance.decrypted_client_id = instance.client_id
if instance.client_secret != instance.decrypted_client_secret:
instance.decrypted_client_secret = instance.client_secret


# Don't connect this receiver if we dont have access to CourseEnrollment model
if CourseEnrollment is not None:
post_save.connect(create_enterprise_enrollment_receiver, sender=CourseEnrollment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def populate_decrypted_client_id_and_secret(apps, schema_editor): # pragma: no cover
"""
Populate the decrypted_client_id and decrypted_client_secret fields for all
Populate the decrypted_client_id and decrypted_client_secret fields for all
existing CanvasEnterpriseCustomerConfiguration
"""
CanvasEnterpriseCustomerConfiguration = apps.get_model('canvas', 'CanvasEnterpriseCustomerConfiguration')
Expand Down
8 changes: 4 additions & 4 deletions integrated_channels/canvas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ def oauth_authorization_url(self):
obj: The instance of CanvasEnterpriseCustomerConfiguration
being rendered with this admin form.
"""
if self.canvas_base_url and self.client_id:
if self.canvas_base_url and self.decrypted_client_id:
return (f'{self.canvas_base_url}/login/oauth2/auth'
f'?redirect_uri={LMS_OAUTH_REDIRECT_URL}&'
f'response_type=code&'
f'client_id={self.client_id}&state={self.uuid}')
f'client_id={self.decrypted_client_id}&state={self.uuid}')
else:
return None

Expand All @@ -196,9 +196,9 @@ def is_valid(self):
"""
missing_items = {'missing': []}
incorrect_items = {'incorrect': []}
if not self.client_id:
if not self.decrypted_client_id:
missing_items.get('missing').append('client_id')
if not self.client_secret:
if not self.decrypted_client_secret:
missing_items.get('missing').append('client_secret')
if not self.canvas_base_url:
missing_items.get('missing').append('canvas_base_url')
Expand Down
4 changes: 2 additions & 2 deletions integrated_channels/canvas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def get(self, request, *args, **kwargs):

access_token_request_params = {
'grant_type': 'authorization_code',
'client_id': enterprise_config.client_id,
'client_secret': enterprise_config.client_secret,
'client_id': enterprise_config.decrypted_client_id,
'client_secret': enterprise_config.decrypted_client_secret,
'redirect_uri': settings.LMS_INTERNAL_ROOT_URL + "/canvas/oauth-complete",
'code': client_code,
}
Expand Down
60 changes: 40 additions & 20 deletions tests/test_integrated_channels/test_canvas/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,47 @@ def setUp(self):
self.refresh_token = 'test-refresh-token'
self.urlbase = reverse('canvas-oauth-complete')

CanvasEnterpriseCustomerConfiguration.objects.get_or_create(
uuid=SINGLE_CANVAS_CONFIG['uuid'],
decrypted_client_id=SINGLE_CANVAS_CONFIG['client_id'],
decrypted_client_secret=SINGLE_CANVAS_CONFIG['client_secret'],
canvas_account_id=SINGLE_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SINGLE_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)
try:
CanvasEnterpriseCustomerConfiguration.objects.get(
uuid=SINGLE_CANVAS_CONFIG['uuid'],
canvas_account_id=SINGLE_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SINGLE_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)
except CanvasEnterpriseCustomerConfiguration.DoesNotExist:
CanvasEnterpriseCustomerConfiguration.objects.create(
uuid=SINGLE_CANVAS_CONFIG['uuid'],
decrypted_client_id=SINGLE_CANVAS_CONFIG['client_id'],
decrypted_client_secret=SINGLE_CANVAS_CONFIG['client_secret'],
canvas_account_id=SINGLE_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SINGLE_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)

CanvasEnterpriseCustomerConfiguration.objects.get_or_create(
uuid=SECOND_CANVAS_CONFIG['uuid'],
decrypted_client_id=SECOND_CANVAS_CONFIG['client_id'],
decrypted_client_secret=SECOND_CANVAS_CONFIG['client_secret'],
canvas_account_id=SECOND_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SECOND_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)
try:
CanvasEnterpriseCustomerConfiguration.objects.get(
uuid=SECOND_CANVAS_CONFIG['uuid'],
canvas_account_id=SECOND_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SECOND_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)
except CanvasEnterpriseCustomerConfiguration.DoesNotExist:
CanvasEnterpriseCustomerConfiguration.objects.create(
uuid=SECOND_CANVAS_CONFIG['uuid'],
decrypted_client_id=SECOND_CANVAS_CONFIG['client_id'],
decrypted_client_secret=SECOND_CANVAS_CONFIG['client_secret'],
canvas_account_id=SECOND_CANVAS_CONFIG['canvas_account_id'],
canvas_base_url=SECOND_CANVAS_CONFIG['canvas_base_url'],
enterprise_customer=self.enterprise_customer,
active=True,
enterprise_customer_id=ENTERPRISE_ID,
)

def test_successful_refresh_token_by_uuid_request(self):
"""
Expand Down

0 comments on commit 401cf73

Please sign in to comment.