Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ ResponseEntity<Map<String, Object>> changeStudentPassword(Authentication auth,
return ResponseEntityGenerator.createError(passwordService.getErrors(newStudentPassword));
}
User studentUser = userService.retrieveById(studentId);
if (!run.isStudentAssociatedToThisRun(studentUser)) {
throw new AccessDeniedException(
"User does not have permission to change this student's password");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!run.isStudentAssociatedToThisRun(studentUser)) {
throw new AccessDeniedException(
"User does not have permission to change this student's password");
}

userService.updateUserPassword(studentUser, newStudentPassword);
return ResponseEntityGenerator.createSuccess("passwordUpdated");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ public void changeStudentPassword_InvalidPassword_ReturnError() throws Exception
verifyServices();
}

@Test
public void changeStudentPassword_StudentNotInRun_ThrowAccessDenied() throws Exception {
setupChangeStudentPasswordExpect();
expect(userService.isPasswordCorrect(teacher1, TEACHER_PASSWORD_CORRECT)).andReturn(true);
expect(userService.retrieveById(student2Id)).andReturn(student2);
replayServices();
try {
controller.changeStudentPassword(teacherAuth, runId1, student2Id, TEACHER_PASSWORD_CORRECT,
STUDENT_PASSWORD_VALID);
fail("Expected AccessDeniedException to be thrown");
} catch (AccessDeniedException e) {
}
verifyServices();
}

@Test
public void changeStudentPassword_TargetUserIsTeacher_ThrowAccessDenied() throws Exception {
setupChangeStudentPasswordExpect();
expect(userService.isPasswordCorrect(teacher1, TEACHER_PASSWORD_CORRECT)).andReturn(true);
expect(userService.retrieveById(teacher2Id)).andReturn(teacher2);
replayServices();
try {
controller.changeStudentPassword(teacherAuth, runId1, teacher2Id, TEACHER_PASSWORD_CORRECT,
STUDENT_PASSWORD_VALID);
fail("Expected AccessDeniedException to be thrown");
} catch (AccessDeniedException e) {
}
verifyServices();
}

@Test
public void changeStudentPassword_validTeacherPassword_ChangeStudentPassword() throws Exception {
setupChangeStudentPasswordExpect();
Expand Down
Loading