Search in sources :

Example 71 with AccountAttributes

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);
}
Also used : Account(teammates.storage.entity.Account) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 72 with AccountAttributes

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");
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 73 with AccountAttributes

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());
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) StudentProfilePictureAction(teammates.ui.controller.StudentProfilePictureAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 74 with AccountAttributes

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);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) Test(org.testng.annotations.Test)

Example 75 with AccountAttributes

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());
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) ShowPageResult(teammates.ui.controller.ShowPageResult) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorCourseJoinAction(teammates.ui.controller.InstructorCourseJoinAction) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)84 Test (org.testng.annotations.Test)53 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)28 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 ArrayList (java.util.ArrayList)13 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)11 HashMap (java.util.HashMap)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InvalidParametersException (teammates.common.exception.InvalidParametersException)6 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)5 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)4 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 EmailWrapper (teammates.common.util.EmailWrapper)4 RedirectResult (teammates.ui.controller.RedirectResult)4 List (java.util.List)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 AccountsDb (teammates.storage.api.AccountsDb)3 Account (teammates.storage.entity.Account)3 ShowPageResult (teammates.ui.controller.ShowPageResult)3