Skip to content

Commit 7b6057b

Browse files
authored
[#11206] Remove admin information from user cookie (#11207)
* Move isAdmin setting to strictly using APP_ADMINS value * Remove usage of sign in as administrator checkbox * Remove admin field from login cookie * Use proper user login instead of admin masquerade for E2E tests
1 parent 5ea6e19 commit 7b6057b

File tree

48 files changed

+139
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+139
-165
lines changed

docs/development.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ This instruction set applies for both dev server and production server, with sli
103103

104104
### As administrator
105105

106-
1. Go to any administrator page, e.g `/web/admin/home`.
107-
1. On the dev server, log in using any username, but remember to check the `Log in as administrator` check box. You will have the required access.
108-
1. On the production server, you will be granted the access only if your account has admin permission as defined in `build.properties`.
106+
1. Go to any administrator page, e.g `/web/admin/home`. You may be prompted to log in.
107+
You will be granted access only if your account has admin permission as defined in `build.properties`.
109108
1. When logged in as administrator, ***masquerade mode*** can also be used to impersonate instructors and students by adding `user=username` to the URL
110109
e.g `http://localhost:8080/web/student/home?user=johnKent`.
111110

src/e2e/java/teammates/e2e/cases/BaseE2ETestCase.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import teammates.common.util.JsonUtils;
2828
import teammates.common.util.StringHelper;
2929
import teammates.common.util.ThreadHelper;
30-
import teammates.e2e.pageobjects.AdminHomePage;
3130
import teammates.e2e.pageobjects.AppPage;
3231
import teammates.e2e.pageobjects.Browser;
3332
import teammates.e2e.pageobjects.DevServerLoginPage;
@@ -101,56 +100,45 @@ protected static AppUrl createUrl(String relativeUrl) {
101100
}
102101

103102
/**
104-
* Logs in a page using admin credentials (i.e. in masquerade mode).
103+
* Logs in to a page using the given credentials.
105104
*/
106-
protected <T extends AppPage> T loginAdminToPage(AppUrl url, Class<T> typeOfPage) {
105+
protected <T extends AppPage> T loginToPage(AppUrl url, Class<T> typeOfPage, String userId) {
107106
// When not using dev server, Google blocks log in by automation.
108107
// To work around that, we inject the user cookie directly into the browser session.
109108
if (!TestProperties.isDevServer()) {
110109
// In order for the cookie injection to work, we need to be in the domain.
111110
// Use the home page to minimize the page load time.
112111
browser.goToUrl(TestProperties.TEAMMATES_URL);
113112

114-
UserInfoCookie uic = new UserInfoCookie("devserver.admin.account", true);
113+
UserInfoCookie uic = new UserInfoCookie(userId);
115114
browser.addCookie(Const.SecurityConfig.AUTH_COOKIE_NAME, StringHelper.encrypt(JsonUtils.toCompactJson(uic)),
116115
true, true);
117116

118117
return getNewPageInstance(url, typeOfPage);
119118
}
120119

121-
if (browser.isAdminLoggedIn) {
122-
try {
123-
return getNewPageInstance(url, typeOfPage);
124-
} catch (Exception e) {
125-
//ignore and try to logout and login again if fail.
126-
}
127-
}
128-
129-
// logout and attempt to load the requested URL. This will be
130-
// redirected to a dev-server login page
131-
logout();
120+
// This will be redirected to the dev server login page.
132121
browser.goToUrl(url.toAbsoluteString());
133122

134-
// In dev server, any username is acceptable as admin
135-
String adminUsername = "devserver.admin.account";
136-
137123
DevServerLoginPage loginPage = AppPage.getNewPageInstance(browser, DevServerLoginPage.class);
138-
loginPage.loginAsAdmin(adminUsername);
124+
loginPage.loginAsUser(userId);
139125

140126
return getNewPageInstance(url, typeOfPage);
141127
}
142128

129+
/**
130+
* Logs in to a page using admin credentials.
131+
*/
132+
protected <T extends AppPage> T loginAdminToPage(AppUrl url, Class<T> typeOfPage) {
133+
return loginToPage(url, typeOfPage, TestProperties.TEST_ADMIN);
134+
}
135+
143136
/**
144137
* Equivalent to clicking the 'logout' link in the top menu of the page.
145138
*/
146139
protected void logout() {
147140
browser.goToUrl(createUrl(Const.WebPageURIs.LOGOUT).toAbsoluteString());
148141
AppPage.getNewPageInstance(browser, HomePage.class).waitForPageToLoad();
149-
browser.isAdminLoggedIn = false;
150-
}
151-
152-
protected AdminHomePage loginAdmin() {
153-
return loginAdminToPage(createUrl(Const.WebPageURIs.ADMIN_HOME_PAGE), AdminHomePage.class);
154142
}
155143

156144
/**

src/e2e/java/teammates/e2e/cases/BaseFeedbackQuestionE2ETest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,22 @@ public abstract class BaseFeedbackQuestionE2ETest extends BaseE2ETestCase {
3434

3535
protected InstructorFeedbackEditPage loginToFeedbackEditPage() {
3636
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_SESSION_EDIT_PAGE)
37-
.withUserId(instructor.googleId)
3837
.withCourseId(course.getId())
3938
.withSessionName(feedbackSession.getFeedbackSessionName());
4039

41-
return loginAdminToPage(url, InstructorFeedbackEditPage.class);
40+
return loginToPage(url, InstructorFeedbackEditPage.class, instructor.googleId);
4241
}
4342

4443
protected FeedbackSubmitPage loginToFeedbackSubmitPage() {
4544
AppUrl url = createUrl(Const.WebPageURIs.STUDENT_SESSION_SUBMISSION_PAGE)
46-
.withUserId(student.googleId)
4745
.withCourseId(student.course)
4846
.withSessionName(feedbackSession.getFeedbackSessionName());
4947

50-
return loginAdminToPage(url, FeedbackSubmitPage.class);
48+
return loginToPage(url, FeedbackSubmitPage.class, student.googleId);
5149
}
5250

5351
protected FeedbackSubmitPage getFeedbackSubmitPage() {
5452
AppUrl url = createUrl(Const.WebPageURIs.STUDENT_SESSION_SUBMISSION_PAGE)
55-
.withUserId(student.googleId)
5653
.withCourseId(student.course)
5754
.withSessionName(feedbackSession.getFeedbackSessionName());
5855

src/e2e/java/teammates/e2e/cases/FeedbackConstSumOptionQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected void prepareTestData() {
3333
@Override
3434
public void testAll() {
3535
testEditPage();
36+
logout();
3637
testSubmitPage();
3738
}
3839

src/e2e/java/teammates/e2e/cases/FeedbackConstSumRecipientQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected void prepareTestData() {
3434
@Override
3535
public void testAll() {
3636
testEditPage();
37+
logout();
3738
testSubmitPage();
3839
}
3940

src/e2e/java/teammates/e2e/cases/FeedbackContributionQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected void prepareTestData() {
3535
@Override
3636
public void testAll() {
3737
testEditPage();
38+
logout();
3839
testSubmitPage();
3940
}
4041

src/e2e/java/teammates/e2e/cases/FeedbackMcqQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected void prepareTestData() {
3434
@Override
3535
public void testAll() {
3636
testEditPage();
37+
logout();
3738
testSubmitPage();
3839
}
3940

src/e2e/java/teammates/e2e/cases/FeedbackMsqQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected void prepareTestData() {
3737
@Override
3838
public void testAll() {
3939
testEditPage();
40+
logout();
4041
testSubmitPage();
4142
}
4243

src/e2e/java/teammates/e2e/cases/FeedbackNumScaleQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected void prepareTestData() {
3131
@Override
3232
public void testAll() {
3333
testEditPage();
34+
logout();
3435
testSubmitPage();
3536
}
3637

src/e2e/java/teammates/e2e/cases/FeedbackRankOptionQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected void prepareTestData() {
3636
@Override
3737
public void testAll() {
3838
testEditPage();
39+
logout();
3940
testSubmitPage();
4041
}
4142

src/e2e/java/teammates/e2e/cases/FeedbackRankRecipientQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected void prepareTestData() {
3636
@Override
3737
public void testAll() {
3838
testEditPage();
39+
logout();
3940
testSubmitPage();
4041
}
4142

src/e2e/java/teammates/e2e/cases/FeedbackRubricQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected void prepareTestData() {
3535
@Override
3636
public void testAll() {
3737
testEditPage();
38+
logout();
3839
testSubmitPage();
3940
}
4041

src/e2e/java/teammates/e2e/cases/FeedbackSubmitPageE2ETest.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ protected void prepareTestData() {
4848
@Override
4949
public void testAll() {
5050
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_SESSION_SUBMISSION_PAGE)
51-
.withUserId(instructor.getGoogleId())
5251
.withCourseId(openSession.getCourseId())
5352
.withSessionName(openSession.getFeedbackSessionName());
54-
FeedbackSubmitPage submitPage = loginAdminToPage(url, FeedbackSubmitPage.class);
53+
FeedbackSubmitPage submitPage = loginToPage(url, FeedbackSubmitPage.class, instructor.googleId);
5554

5655
______TS("verify loaded session data");
5756
submitPage.verifyFeedbackSessionDetails(openSession);
@@ -61,7 +60,8 @@ public void testAll() {
6160
submitPage.verifyQuestionDetails(1, testData.feedbackQuestions.get("qn5InSession1"));
6261

6362
______TS("questions with giver type students");
64-
submitPage = loginAdminToPage(getStudentSubmitPageUrl(student, openSession), FeedbackSubmitPage.class);
63+
logout();
64+
submitPage = loginToPage(getStudentSubmitPageUrl(student, openSession), FeedbackSubmitPage.class, student.googleId);
6565

6666
submitPage.verifyNumQuestions(4);
6767
submitPage.verifyQuestionDetails(1, testData.feedbackQuestions.get("qn1InSession1"));
@@ -124,9 +124,21 @@ public void testAll() {
124124
submitPage.verifyNoCommentPresent(qnToComment, recipient);
125125
verifyAbsentInDatastore(getFeedbackResponseComment(responseId, comment));
126126

127+
______TS("preview as instructor");
128+
logout();
129+
url = createUrl(Const.WebPageURIs.INSTRUCTOR_SESSION_SUBMISSION_PAGE)
130+
.withCourseId(openSession.getCourseId())
131+
.withSessionName(openSession.getFeedbackSessionName())
132+
.withParam("previewas", instructor.getEmail());
133+
submitPage = loginToPage(url, FeedbackSubmitPage.class, instructor.googleId);
134+
135+
submitPage.verifyFeedbackSessionDetails(openSession);
136+
submitPage.verifyNumQuestions(1);
137+
submitPage.verifyQuestionDetails(1, testData.feedbackQuestions.get("qn5InSession1"));
138+
submitPage.verifyCannotSubmit();
139+
127140
______TS("preview as student");
128141
url = createUrl(Const.WebPageURIs.SESSION_SUBMISSION_PAGE)
129-
.withUserId(instructor.googleId)
130142
.withCourseId(openSession.getCourseId())
131143
.withSessionName(openSession.getFeedbackSessionName())
132144
.withParam("previewas", student.getEmail());
@@ -140,22 +152,8 @@ public void testAll() {
140152
submitPage.verifyQuestionDetails(4, testData.feedbackQuestions.get("qn4InSession1"));
141153
submitPage.verifyCannotSubmit();
142154

143-
______TS("preview as instructor");
144-
url = createUrl(Const.WebPageURIs.INSTRUCTOR_SESSION_SUBMISSION_PAGE)
145-
.withUserId(instructor.googleId)
146-
.withCourseId(openSession.getCourseId())
147-
.withSessionName(openSession.getFeedbackSessionName())
148-
.withParam("previewas", instructor.getEmail());
149-
submitPage = getNewPageInstance(url, FeedbackSubmitPage.class);
150-
151-
submitPage.verifyFeedbackSessionDetails(openSession);
152-
submitPage.verifyNumQuestions(1);
153-
submitPage.verifyQuestionDetails(1, testData.feedbackQuestions.get("qn5InSession1"));
154-
submitPage.verifyCannotSubmit();
155-
156155
______TS("moderating instructor cannot see questions without instructor visibility");
157156
url = createUrl(Const.WebPageURIs.SESSION_SUBMISSION_PAGE)
158-
.withUserId(instructor.googleId)
159157
.withCourseId(gracePeriodSession.getCourseId())
160158
.withSessionName(gracePeriodSession.getFeedbackSessionName())
161159
.withParam("moderatedperson", student.getEmail())
@@ -176,7 +174,6 @@ public void testAll() {
176174

177175
private AppUrl getStudentSubmitPageUrl(StudentAttributes student, FeedbackSessionAttributes session) {
178176
return createUrl(Const.WebPageURIs.STUDENT_SESSION_SUBMISSION_PAGE)
179-
.withUserId(student.googleId)
180177
.withCourseId(student.course)
181178
.withSessionName(session.getFeedbackSessionName());
182179
}

src/e2e/java/teammates/e2e/cases/FeedbackTextQuestionE2ETest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected void prepareTestData() {
3131
@Override
3232
public void testAll() {
3333
testEditPage();
34+
logout();
3435
testSubmitPage();
3536
}
3637

src/e2e/java/teammates/e2e/cases/InstructorAuditLogsPageE2ETest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ protected void prepareTestData() {
4444
@Test
4545
@Override
4646
public void testAll() {
47-
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_AUDIT_LOGS_PAGE).withUserId(instructor.googleId);
48-
InstructorAuditLogsPage auditLogsPage = loginAdminToPage(url, InstructorAuditLogsPage.class);
47+
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_AUDIT_LOGS_PAGE);
48+
InstructorAuditLogsPage auditLogsPage = loginToPage(url, InstructorAuditLogsPage.class, instructor.googleId);
4949

5050
______TS("verify default datetime");
5151
String currentLogsFromDate = auditLogsPage.getLogsFromDate();
@@ -72,16 +72,17 @@ public void testAll() {
7272
}
7373

7474
______TS("verify logs output");
75+
logout();
7576
AppUrl studentSubmissionPageUrl = createUrl(Const.WebPageURIs.STUDENT_SESSION_SUBMISSION_PAGE)
7677
.withCourseId(course.getId())
77-
.withUserId(student.googleId)
7878
.withSessionName(feedbackSession.getFeedbackSessionName());
79-
StudentFeedbackSubmissionPage studentSubmissionPage = loginAdminToPage(studentSubmissionPageUrl,
80-
StudentFeedbackSubmissionPage.class);
79+
StudentFeedbackSubmissionPage studentSubmissionPage = loginToPage(studentSubmissionPageUrl,
80+
StudentFeedbackSubmissionPage.class, student.googleId);
8181
studentSubmissionPage.populateResponse();
8282
studentSubmissionPage.submit();
8383

84-
auditLogsPage = loginAdminToPage(url, InstructorAuditLogsPage.class);
84+
logout();
85+
auditLogsPage = loginToPage(url, InstructorAuditLogsPage.class, instructor.googleId);
8586
auditLogsPage.setCourseId(course.getId());
8687
auditLogsPage.startSearching();
8788

src/e2e/java/teammates/e2e/cases/InstructorCourseDetailsPageE2ETest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void classSetup() {
4848
@Override
4949
public void testAll() {
5050
AppUrl detailsPageUrl = createUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_DETAILS_PAGE)
51-
.withUserId(testData.instructors.get("ICDet.instr").googleId)
5251
.withCourseId(course.getId());
53-
InstructorCourseDetailsPage detailsPage = loginAdminToPage(detailsPageUrl, InstructorCourseDetailsPage.class);
52+
InstructorCourseDetailsPage detailsPage = loginToPage(detailsPageUrl, InstructorCourseDetailsPage.class,
53+
testData.instructors.get("ICDet.instr").googleId);
5454

5555
______TS("verify loaded details");
5656
InstructorAttributes[] instructors = {

src/e2e/java/teammates/e2e/cases/InstructorCourseEditPageE2ETest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,19 @@ public void testAll() {
3636
______TS("verify cannot edit without privilege");
3737
// log in as instructor with no edit privilege
3838
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_EDIT_PAGE)
39-
.withUserId(instructors[2].googleId)
4039
.withCourseId(course.getId());
41-
InstructorCourseEditPage editPage = loginAdminToPage(url, InstructorCourseEditPage.class);
40+
InstructorCourseEditPage editPage = loginToPage(url, InstructorCourseEditPage.class, instructors[2].googleId);
4241

4342
editPage.verifyCourseNotEditable();
4443
editPage.verifyInstructorsNotEditable();
4544
editPage.verifyAddInstructorNotAllowed();
4645

4746
______TS("verify loaded data");
4847
// re-log in as instructor with edit privilege
48+
logout();
4949
url = createUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_EDIT_PAGE)
50-
.withUserId(instructors[3].googleId)
5150
.withCourseId(course.getId());
52-
editPage = getNewPageInstance(url, InstructorCourseEditPage.class);
51+
editPage = loginToPage(url, InstructorCourseEditPage.class, instructors[3].googleId);
5352

5453
editPage.verifyCourseDetails(course);
5554
editPage.verifyInstructorDetails(instructors[0]);

src/e2e/java/teammates/e2e/cases/InstructorCourseEnrollPageE2ETest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ protected void prepareTestData() {
2121
@Override
2222
public void testAll() {
2323
AppUrl url = createUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_ENROLL_PAGE)
24-
.withUserId(testData.instructors.get("ICEnroll.teammates.test").googleId)
2524
.withCourseId(testData.courses.get("ICEnroll.CS2104").getId());
26-
InstructorCourseEnrollPage enrollPage = loginAdminToPage(url, InstructorCourseEnrollPage.class);
25+
InstructorCourseEnrollPage enrollPage = loginToPage(url, InstructorCourseEnrollPage.class,
26+
testData.instructors.get("ICEnroll.teammates.test").googleId);
2727

2828
______TS("Add rows to enroll spreadsheet");
2929
int numRowsToAdd = 30;

src/e2e/java/teammates/e2e/cases/InstructorCourseJoinConfirmationPageE2ETest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ public void testAll() {
3131
String invalidEncryptedKey = "invalidKey";
3232
AppUrl joinLink = createUrl(Const.WebPageURIs.JOIN_PAGE)
3333
.withRegistrationKey(invalidEncryptedKey)
34-
.withEntityType(Const.EntityType.INSTRUCTOR)
35-
.withUserId(newInstructor.googleId);
36-
ErrorReportingModal errorPage = loginAdminToPage(joinLink, ErrorReportingModal.class);
34+
.withEntityType(Const.EntityType.INSTRUCTOR);
35+
ErrorReportingModal errorPage = loginToPage(joinLink, ErrorReportingModal.class, newInstructor.googleId);
3736

3837
errorPage.verifyErrorMessage("No instructor with given registration key: " + invalidEncryptedKey);
3938

@@ -42,9 +41,8 @@ public void testAll() {
4241
String instructorEmail = newInstructor.email;
4342
joinLink = createUrl(Const.WebPageURIs.JOIN_PAGE)
4443
.withRegistrationKey(getKeyForInstructor(courseId, instructorEmail))
45-
.withEntityType(Const.EntityType.INSTRUCTOR)
46-
.withUserId(newInstructor.googleId);
47-
CourseJoinConfirmationPage confirmationPage = loginAdminToPage(joinLink, CourseJoinConfirmationPage.class);
44+
.withEntityType(Const.EntityType.INSTRUCTOR);
45+
CourseJoinConfirmationPage confirmationPage = getNewPageInstance(joinLink, CourseJoinConfirmationPage.class);
4846

4947
confirmationPage.verifyJoiningUser(newInstructor.googleId);
5048
confirmationPage.confirmJoinCourse(InstructorHomePage.class);

src/e2e/java/teammates/e2e/cases/InstructorCourseStudentDetailsEditPageE2ETest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ protected void prepareTestData() {
3131
@Override
3232
public void testAll() {
3333
AppUrl editPageUrl = createUrl(Const.WebPageURIs.INSTRUCTOR_COURSE_STUDENT_DETAILS_EDIT_PAGE)
34-
.withUserId(testData.instructors.get("ICSDetEdit.instr").googleId)
3534
.withCourseId(course.getId())
3635
.withStudentEmail(student.email);
3736
InstructorCourseStudentDetailsEditPage editPage =
38-
loginAdminToPage(editPageUrl, InstructorCourseStudentDetailsEditPage.class);
37+
loginToPage(editPageUrl, InstructorCourseStudentDetailsEditPage.class,
38+
testData.instructors.get("ICSDetEdit.instr").googleId);
3939

4040
______TS("verify loaded data");
4141
editPage.verifyStudentDetails(student);

0 commit comments

Comments
 (0)