use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class AccountAttributesTest method testValueOf.
@Test
public void testValueOf() {
Account genericAccount = new Account("id", "Joe", true, "joe@example.com", "Teammates Institute");
AccountAttributes observedAccountAttributes = AccountAttributes.valueOf(genericAccount);
assertEquals(genericAccount.getGoogleId(), observedAccountAttributes.getGoogleId());
assertEquals(genericAccount.getName(), observedAccountAttributes.getName());
assertEquals(genericAccount.isInstructor(), observedAccountAttributes.isInstructor());
assertEquals(genericAccount.getEmail(), observedAccountAttributes.getEmail());
assertEquals(genericAccount.getInstitute(), observedAccountAttributes.getInstitute());
assertEquals(genericAccount.getCreatedAt(), observedAccountAttributes.createdAt);
assertEquals(genericAccount.getStudentProfile(), observedAccountAttributes.studentProfile);
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class StudentProfileEditSaveActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
AccountAttributes student = typicalBundle.accounts.get("student1InCourse1");
testActionWithInvalidParameters(student);
testActionSuccess(student, "Typical Case");
testActionInMasqueradeMode(student);
student = typicalBundle.accounts.get("student1InTestingSanitizationCourse");
// simulate sanitization that occurs before persistence
student.sanitizeForSaving();
testActionSuccess(student, "Typical case: attempted script injection");
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class StudentProfilePictureActionTest method testActionWithEmailAndCourseUnauthorisedInstructorOrStudent.
private void testActionWithEmailAndCourseUnauthorisedInstructorOrStudent() {
String[] submissionParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, StringHelper.encrypt(student.email), Const.ParamsNames.COURSE_ID, StringHelper.encrypt(student.course) };
______TS("Failure case: instructor not from same course");
AccountAttributes unauthInstructor = typicalBundle.accounts.get("instructor1OfCourse2");
gaeSimulation.loginAsInstructor(unauthInstructor.googleId);
StudentProfilePictureAction action = getAction(submissionParams);
try {
action.executeAndPostProcess();
signalFailureToDetectException("Unauthorised Access");
} catch (UnauthorizedAccessException uae) {
assertEquals("User is not in the course that student belongs to", uae.getMessage());
}
______TS("Failure case: instructor from same course with no 'viewing student' privilege");
unauthInstructor = typicalBundle.accounts.get("helperOfCourse1");
gaeSimulation.loginAsInstructor(unauthInstructor.googleId);
action = getAction(submissionParams);
try {
action.executeAndPostProcess();
signalFailureToDetectException("Unauthorised Access");
} catch (UnauthorizedAccessException uae) {
assertEquals("Instructor does not have enough privileges to view the photo", uae.getMessage());
}
______TS("Failure case: student not from same course");
AccountAttributes unauthStudent = typicalBundle.accounts.get("student1InArchivedCourse");
gaeSimulation.loginAsStudent(unauthStudent.googleId);
action = getAction(submissionParams);
try {
action.executeAndPostProcess();
signalFailureToDetectException("Unauthorised Access");
} catch (UnauthorizedAccessException uae) {
assertEquals("User is not in the course that student belongs to", uae.getMessage());
}
______TS("Failure case: student not from same team");
StudentAttributes studentFromDifferentTeam = typicalBundle.students.get("student5InCourse1");
gaeSimulation.loginAsStudent(studentFromDifferentTeam.googleId);
action = getAction(submissionParams);
try {
action.executeAndPostProcess();
signalFailureToDetectException("Unauthorised Access");
} catch (UnauthorizedAccessException uae) {
assertEquals("Student does not have enough privileges to view the photo", uae.getMessage());
}
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class StudentProfilePictureEditActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
AccountAttributes student = typicalBundle.accounts.get("student2InCourse1");
gaeSimulation.loginAsStudent(student.googleId);
testActionForEmptyLeftX(student);
testActionForEmptyRightY(student);
testActionForEmptyTopY(student);
testActionForEmptyBottomY(student);
testActionForEmptyHeight(student);
testActionForEmptyWidth(student);
testActionForZeroHeight(student);
testActionForZeroWidth(student);
testActionForNonExistentBlobKey(student);
}
use of teammates.common.datatransfer.attributes.AccountAttributes in project teammates by TEAMMATES.
the class InstructorCourseJoinActionTest method testExecuteAndPostProcess.
@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
InstructorsDb instrDb = new InstructorsDb();
// Reassign to let "key" variable in "instructor" not to be null
instructor = instrDb.getInstructorForGoogleId(instructor.courseId, instructor.googleId);
String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
gaeSimulation.loginAsInstructor(instructor.googleId);
______TS("Invalid key, redirect for confirmation again");
String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
InstructorCourseJoinAction confirmAction = getAction(submissionParams);
ShowPageResult pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "idOfInstructor1OfCourse1", invalidEncryptedKey), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
String expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + invalidEncryptedKey;
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Already registered instructor, redirect straight to authentication page");
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
confirmAction = getAction(submissionParams);
RedirectResult redirectResult = getRedirectResult(confirmAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN_AUTHENTICATED, StringHelper.encrypt(instructor.key), false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals("", redirectResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(instructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Typical case: unregistered instructor, redirect to confirmation page");
instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAT.instr@email.com").build();
InstructorsLogic.inst().createInstructor(instructor);
instructor.googleId = "ICJAT.instr";
AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
AccountsLogic.inst().createAccount(newInstructorAccount);
InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
gaeSimulation.loginUser(instructor.googleId);
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
confirmAction = getAction(submissionParams);
pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "ICJAT.instr", StringHelper.encrypt(newInstructor.key)), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(newInstructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
}
Aggregations