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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def can_create_at(cls, parent):
and not parent.get_children().type(cls).exists()
)

@route(r"^program/([A-Fa-f0-9-]+)/?$")
@route(r"^program/([A-Fa-f0-9-]{36})/?$")
def program_certificate(
self,
request,
Expand Down Expand Up @@ -677,7 +677,7 @@ def program_certificate(
certificate_page.certificate = certificate
return certificate_page.serve(request)

@route(r"^([A-Fa-f0-9-]+)/?$")
@route(r"^([A-Fa-f0-9-]{36})/?$")
def course_certificate(
self,
request,
Expand Down
36 changes: 35 additions & 1 deletion cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
UserTestimonialsPage,
WhoShouldEnrollPage,
)
from courses.factories import CourseFactory, CourseRunFactory
from courses.factories import (
CourseFactory,
CourseRunCertificateFactory,
CourseRunFactory,
ProgramCertificateFactory,
)

pytestmark = [pytest.mark.django_db]

Expand Down Expand Up @@ -1785,3 +1790,32 @@ def test_program_page_price_is_updated(superuser_client):
resp = superuser_client.post(path, data_to_post)
assert resp.status_code == 302
assert program.current_price == 999


def test_certificate_request_with_valid_uuid(user_client):
"""Test that certificate request is successful for course and program certificates."""
course_run_certificate = CourseRunCertificateFactory.create()
resp = user_client.get(f"/certificate/{course_run_certificate.uuid}/")
assert resp.status_code == 200

program_certificate = ProgramCertificateFactory.create()
resp = user_client.get(f"/certificate/program/{program_certificate.uuid}/")
assert resp.status_code == 200


@pytest.mark.parametrize(
"uuid_string",
[
"",
"1bebd843-ebf0-40c0-850e",
"1bebd843-ebf0-40c0-850e-fe73baa31b944444",
"1bebd843-ebf0-40c0-850e-fe73baa31b94-4ab4",
],
)
def test_certificate_request_with_invalid_uuid(user_client, uuid_string):
"""Test that course run and program certificate request returns a 404 for invalid uuids."""
program_certificate_resp = user_client.get(f"/certificate/program/{uuid_string}/")
assert program_certificate_resp.status_code == 404

course_certificate_resp = user_client.get(f"/certificate/{uuid_string}/")
assert course_certificate_resp.status_code == 404
Loading