-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add endpoint for retiring personally-identifiable information * Add logic for clearing user information from exam attempts * Add logic for clearing user information from student allowances * Add VS Code settings to gitignore
- Loading branch information
Showing
8 changed files
with
192 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,9 @@ tramp | |
*.swp | ||
*.swo | ||
|
||
# VS Code | ||
.vscode | ||
|
||
# Mac | ||
.DS_Store | ||
._* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
from edx_proctoring.api import ( | ||
_calculate_allowed_mins, | ||
add_allowance_for_user, | ||
create_exam, | ||
create_exam_attempt, | ||
get_backend_provider, | ||
|
@@ -34,7 +35,13 @@ | |
ProctoredExamPermissionDenied, | ||
StudentExamAttemptDoesNotExistsException | ||
) | ||
from edx_proctoring.models import ProctoredExam, ProctoredExamStudentAllowance, ProctoredExamStudentAttempt | ||
from edx_proctoring.models import ( | ||
ProctoredExam, | ||
ProctoredExamStudentAllowance, | ||
ProctoredExamStudentAllowanceHistory, | ||
ProctoredExamStudentAttempt, | ||
ProctoredExamStudentAttemptHistory | ||
) | ||
from edx_proctoring.runtime import get_runtime_service, set_runtime_service | ||
from edx_proctoring.serializers import ProctoredExamSerializer | ||
from edx_proctoring.statuses import ProctoredExamStudentAttemptStatus | ||
|
@@ -2847,3 +2854,114 @@ def test_no_access(self): | |
|
||
response = self.client.post(deletion_url) | ||
assert response.status_code == 403 | ||
|
||
|
||
class TestUserRetirement(LoggedInTestCase): | ||
""" | ||
Tests for deleting user PII for proctoring | ||
""" | ||
def setUp(self): | ||
super(TestUserRetirement, self).setUp() | ||
self.user.is_staff = True | ||
self.user.save() | ||
self.user_to_retire = User(username='tester2', email='[email protected]') | ||
self.user_to_retire.save() | ||
self.client.login_user(self.user) | ||
self.deletion_url = reverse('edx_proctoring:user_retirement_api', kwargs={'user_id': self.user_to_retire.id}) | ||
|
||
def _create_proctored_exam(self): | ||
""" Create a mock proctored exam with common values """ | ||
return ProctoredExam.objects.create( | ||
course_id='a/b/c', | ||
content_id='test_content', | ||
exam_name='Test Exam', | ||
external_id='123aXqe3', | ||
is_proctored=True, | ||
is_active=True, | ||
time_limit_mins=90, | ||
backend='test' | ||
) | ||
|
||
def test_retire_no_access(self): | ||
""" A user without retirement permissions should not be able to retire other users """ | ||
self.client.login_user(self.user_to_retire) | ||
deletion_url = reverse('edx_proctoring:user_retirement_api', kwargs={'user_id': self.user.id}) | ||
|
||
response = self.client.post(deletion_url) | ||
assert response.status_code == 403 | ||
|
||
def test_retire_user_no_data(self): | ||
""" | ||
Attempting to retire an unknown user or user with no proctored attempts | ||
returns 204 but does not carry out a retirment | ||
""" | ||
response = self.client.post(self.deletion_url) | ||
|
||
assert response.status_code == 204 | ||
|
||
def test_retire_user_exam_attempt(self): | ||
""" Retiring a user should obfuscate PII for exam attempts and return a 204 status """ | ||
# Create an exam attempt | ||
proctored_exam = self._create_proctored_exam() | ||
ProctoredExamStudentAttempt.objects.create( | ||
proctored_exam=proctored_exam, | ||
user=self.user_to_retire, | ||
student_name='me', | ||
last_poll_ipaddr='127.0.0.1' | ||
) | ||
|
||
# Run the retirement command | ||
deletion_url = reverse('edx_proctoring:user_retirement_api', kwargs={'user_id': self.user_to_retire.id}) | ||
response = self.client.post(deletion_url) | ||
assert response.status_code == 204 | ||
|
||
retired_attempt = ProctoredExamStudentAttempt.objects.filter(user_id=self.user_to_retire.id).first() | ||
assert retired_attempt.student_name == '' | ||
assert retired_attempt.last_poll_ipaddr is None | ||
|
||
def test_retire_user_exam_attempt_history(self): | ||
""" Retiring a user should obfuscate PII for exam attempt history and return a 204 status """ | ||
# Create and archive an exam attempt so it appears in the history table | ||
proctored_exam = self._create_proctored_exam() | ||
ProctoredExamStudentAttemptHistory.objects.create( | ||
proctored_exam=proctored_exam, | ||
user=self.user_to_retire, | ||
student_name='me', | ||
last_poll_ipaddr='127.0.0.1' | ||
) | ||
|
||
# Run the retirement command | ||
response = self.client.post(self.deletion_url) | ||
assert response.status_code == 204 | ||
|
||
retired_attempt_history = ProctoredExamStudentAttemptHistory \ | ||
.objects.filter(user_id=self.user_to_retire.id).first() | ||
assert retired_attempt_history.student_name == '' | ||
assert retired_attempt_history.last_poll_ipaddr is None | ||
|
||
def test_retire_user_allowances(self): | ||
""" Retiring a user should delete their allowances and return a 204 """ | ||
proctored_exam = self._create_proctored_exam() | ||
add_allowance_for_user(proctored_exam.id, self.user_to_retire.id, 'a_key', 30) | ||
|
||
# Run the retirement command | ||
response = self.client.post(self.deletion_url) | ||
assert response.status_code == 204 | ||
|
||
retired_allowance = ProctoredExamStudentAllowance \ | ||
.objects.filter(user=self.user_to_retire.id).first() | ||
assert retired_allowance.value == '' | ||
|
||
def test_retire_user_allowances_history(self): | ||
""" Retiring a user should delete their allowances and return a 204 """ | ||
proctored_exam = self._create_proctored_exam() | ||
add_allowance_for_user(proctored_exam.id, self.user_to_retire.id, 'a_key', 30) | ||
add_allowance_for_user(proctored_exam.id, self.user_to_retire.id, 'a_key', 60) | ||
|
||
# Run the retirement command | ||
response = self.client.post(self.deletion_url) | ||
assert response.status_code == 204 | ||
|
||
retired_allowance_history = ProctoredExamStudentAllowanceHistory \ | ||
.objects.filter(user=self.user_to_retire.id).first() | ||
assert retired_allowance_history.value == '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters