Skip to content
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

fix: invalid certificate uuid should raise 404 #2990

Merged
merged 3 commits into from
May 27, 2024

Conversation

asadali145
Copy link
Contributor

What are the relevant tickets?

Fixes Sentry error

Description (What does it do?)

Using an invalid UUID to get a course run or program certificate results in a 500 server error. It should return 404.

Steps to reproduce:

  • Checkout master branch
  • fetch /certificate/f5ab714b-a7ee-498f-bbec-/
  • It will raise a validation error

How can this be tested?

  • Create Course Certificate and Program Certificate Pages in CMS
  • Create Course Run Certificate and Program Certificate in Django Admin for a user
  • Fetch the course certificate at /certificate/<uuid>/ and the program certificate at /certificate/program/<uuid>/. You should see the valid certificates.
  • Now Fetch course and program certificate with invalid UUID i.e. f5ab714b-a7ee-498f-bbec-. You should see a 404 page.

Comment on lines 1795 to 1814
def test_course_run_certificate_get(user_client):
"""Test that course run certificate get is successful for a valid UUID and raises 404 for invalid UUID"""
certificate = CourseRunCertificateFactory.create()
resp = user_client.get(f"/certificate/{certificate.uuid}/")
assert resp.status_code == 200

invalid_uuid = str(certificate.uuid)[0:-12]
resp = user_client.get(f"/certificate/{invalid_uuid}/")
assert resp.status_code == 404


def test_program_certificate_get(user_client):
"""Test that program certificate get is successful for a valid UUID and raises 404 for invalid UUID"""
certificate = ProgramCertificateFactory.create()
resp = user_client.get(f"/certificate/program/{certificate.uuid}/")
assert resp.status_code == 200

invalid_uuid = str(certificate.uuid)[0:-12]
resp = user_client.get(f"/certificate/program/{invalid_uuid}/")
assert resp.status_code == 404
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We can refactor this in this way:

  1. A test only to check the valid certificate for both course and program certificate
  2. A parametrized test to check invalid certificates for both course & program certificate

We should check on multiple invalid UUIDs. Ideally making these tests parameterized for invalid e.g.

  1. Short string
  2. Empty String
  3. String longer than the length of UUID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were no existing tests so I just tried to put in some basic ones quickly but sure, I will add some more as you suggested.

Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Before merging this I would recommend:

  1. Checking the existing lengths of the certificate UUIDs on Prod
  2. Checking the existing lengths of the certificate UUIDs on RC

This way we'll make sure that this won't break on existing certificates.

@asadali145 asadali145 merged commit 98fe911 into master May 27, 2024
7 checks passed
@odlbot odlbot mentioned this pull request May 27, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants