Skip to content

Commit

Permalink
Merge pull request #1920 from openedx/asheehan-edx/surfacing-sp-metad…
Browse files Browse the repository at this point in the history
…ata-url-to-self-service

chore: returning SP metadata url from the sso orchestrator to the API…
  • Loading branch information
alex-sheehan-edx committed Oct 25, 2023
2 parents eca32b7 + 78ffebc commit c54ae9e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.6.9]
-------
chore: returning SP metadata url from the sso orchestrator to the API caller

[4.6.8]
-------
feat: truncate API Response before writing to the APIResponseRecord
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.6.8"
__version__ = "4.6.9"
14 changes: 8 additions & 6 deletions enterprise/api/v1/views/enterprise_customer_sso_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ def create(self, request, *args, **kwargs):
try:
with transaction.atomic():
new_record = EnterpriseCustomerSsoConfiguration.objects.create(**request_data)
new_record.submit_for_configuration()
sp_metadata_url = new_record.submit_for_configuration()
except (TypeError, SsoOrchestratorClientError) as e:
LOGGER.error(f'{CONFIG_CREATE_ERROR} {e}')
return Response({'error': f'{CONFIG_CREATE_ERROR} {e}'}, status=HTTP_400_BAD_REQUEST)

return Response({'data': new_record.pk}, status=HTTP_201_CREATED)
return Response({'record': new_record.pk, 'sp_metadata_url': sp_metadata_url}, status=HTTP_201_CREATED)

@permission_required(
'enterprise.can_access_admin_dashboard',
Expand Down Expand Up @@ -321,12 +321,14 @@ def update(self, request, *args, **kwargs):
try:
with transaction.atomic():
sso_configuration_record.update(**request_data)
sso_configuration_record.first().submit_for_configuration(updating_existing_record=True)
sp_metadata_url = sso_configuration_record.first().submit_for_configuration(
updating_existing_record=True
)
except (TypeError, FieldDoesNotExist, ValidationError, SsoOrchestratorClientError) as e:
LOGGER.error(f'{CONFIG_UPDATE_ERROR}{e}')
return Response({'error': f'{CONFIG_UPDATE_ERROR}{e}'}, status=HTTP_400_BAD_REQUEST)
LOGGER.error(f'{CONFIG_UPDATE_ERROR} {e}')
return Response({'error': f'{CONFIG_UPDATE_ERROR} {e}'}, status=HTTP_400_BAD_REQUEST)
serializer = self.serializer_class(sso_configuration_record.first())
return Response(serializer.data, status=HTTP_200_OK)
return Response({'record': serializer.data, 'sp_metadata_url': sp_metadata_url}, status=HTTP_200_OK)

@permission_required(
'enterprise.can_access_admin_dashboard',
Expand Down
5 changes: 3 additions & 2 deletions enterprise/api_client/sso_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _post(self, url, data=None):
f"Failed to make SSO Orchestrator API request: {response.status_code}",
response=response,
)
return response.status_code
return response.json()

def configure_sso_orchestration_record(
self,
Expand Down Expand Up @@ -131,4 +131,5 @@ def configure_sso_orchestration_record(
if is_sap or sap_config_data:
request_data['sapsfConfiguration'] = sap_config_data

return self._post(self._get_orchestrator_configure_url(), data=request_data)
response = self._post(self._get_orchestrator_configure_url(), data=request_data)
return response.get('samlServiceProviderInformation', {}).get('spMetadataUrl', {})
3 changes: 2 additions & 1 deletion enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4095,7 +4095,7 @@ def submit_for_configuration(self, updating_existing_record=False):
elif field_value := getattr(self, field):
config_data[utils.camelCase(field)] = field_value

EnterpriseSSOOrchestratorApiClient().configure_sso_orchestration_record(
sp_metadata_url = EnterpriseSSOOrchestratorApiClient().configure_sso_orchestration_record(
config_data=config_data,
config_pk=self.pk,
enterprise_data={
Expand All @@ -4109,3 +4109,4 @@ def submit_for_configuration(self, updating_existing_record=False):
)
self.submitted_at = localized_utcnow()
self.save()
return sp_metadata_url
10 changes: 5 additions & 5 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7529,8 +7529,8 @@ def test_sso_configuration_create(self):
response = self.post_new_sso_configuration(data)
assert response.status_code == status.HTTP_201_CREATED
assert len(EnterpriseCustomerSsoConfiguration.objects.all()) == 1
created_record = EnterpriseCustomerSsoConfiguration.objects.all().first().uuid
assert response.data['data'] == created_record
created_record_uuid = EnterpriseCustomerSsoConfiguration.objects.all().first().uuid
assert response.data['record'] == created_record_uuid

def test_sso_configuration_create_permissioning(self):
"""
Expand Down Expand Up @@ -7766,7 +7766,7 @@ def test_sso_configurations_update_submitted_config(self):
assert sent_body_params['requestIdentifier'] == str(config_pk)

@responses.activate
def test_sso_configuration_update_x(self):
def test_sso_configuration_update_success(self):
"""
Test expected response when successfully updating an existing sso configuration.
"""
Expand Down Expand Up @@ -7797,8 +7797,8 @@ def test_sso_configuration_update_x(self):
}
response = self.update_sso_configuration(config_pk, data)
assert response.status_code == status.HTTP_200_OK
assert response.json()['uuid'] == str(enterprise_sso_orchestration_config.uuid)
assert response.json()['metadata_url'] == "https://example.com/metadata_update.xml"
assert response.json()['record']['uuid'] == str(enterprise_sso_orchestration_config.uuid)
assert response.json()['record']['metadata_url'] == "https://example.com/metadata_update.xml"

enterprise_sso_orchestration_config.refresh_from_db()
assert enterprise_sso_orchestration_config.metadata_url == "https://example.com/metadata_update.xml"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_enterprise/api_client/test_sso_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def test_post_sso_configuration():
responses.add(
responses.POST,
SSO_ORCHESTRATOR_CONFIGURE_URL,
json={},
json={'samlServiceProviderInformation': {'spMetadataUrl': 'https://example.com'}},
)
client = sso_orchestrator.EnterpriseSSOOrchestratorApiClient()
actual_response = client.configure_sso_orchestration_record(
config_data={'uuid': TEST_ENTERPRISE_SSO_CONFIG_UUID},
config_pk=TEST_ENTERPRISE_SSO_CONFIG_UUID,
enterprise_data={'uuid': TEST_ENTERPRISE_ID, 'name': TEST_ENTERPRISE_NAME, 'slug': TEST_ENTERPRISE_NAME},
)
assert actual_response == 200
assert actual_response == 'https://example.com'
responses.assert_call_count(count=1, url=SSO_ORCHESTRATOR_CONFIGURE_URL)

sent_body_params = json.loads(responses.calls[0].request.body)
Expand Down

0 comments on commit c54ae9e

Please sign in to comment.