-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add AccountRequestStatus * Add AccountRequest status attribute * Add status to AccountRequest constructor * Add AccountRequest comments attribute * Add comments to AccountRequest constructor * Wrap lines * Remove mysterious unnecessary imports that appeared out of nowhere * Use non-null placeholder * Use literal placeholder
- Loading branch information
1 parent
395bdd7
commit fc1342f
Showing
12 changed files
with
125 additions
and
33 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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import teammates.client.connector.DatastoreClient; | ||
import teammates.client.util.ClientProperties; | ||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.util.HibernateUtil; | ||
import teammates.storage.entity.UsageStatistics; | ||
import teammates.storage.sqlentity.Notification; | ||
|
@@ -43,7 +44,9 @@ protected void verifySqlConnection() { | |
teammates.storage.sqlentity.AccountRequest newEntity = new teammates.storage.sqlentity.AccountRequest( | ||
"[email protected]", | ||
"dummy-teammates-account-request", | ||
"dummy-teammates-institute"); | ||
"dummy-teammates-institute", | ||
AccountRequestStatus.PENDING, | ||
"dummy-comments"); | ||
HibernateUtil.beginTransaction(); | ||
HibernateUtil.persist(newEntity); | ||
HibernateUtil.commitTransaction(); | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.exception.EntityAlreadyExistsException; | ||
import teammates.common.exception.EntityDoesNotExistException; | ||
import teammates.common.exception.InvalidParametersException; | ||
|
@@ -28,8 +29,10 @@ public void testResetAccountRequest() | |
String name = "name lee"; | ||
String email = "[email protected]"; | ||
String institute = "institute"; | ||
AccountRequestStatus status = AccountRequestStatus.PENDING; | ||
String comments = "comments"; | ||
|
||
AccountRequest toReset = accountRequestsLogic.createAccountRequest(name, email, institute); | ||
AccountRequest toReset = accountRequestsLogic.createAccountRequest(name, email, institute, status, comments); | ||
AccountRequestsDb accountRequestsDb = AccountRequestsDb.inst(); | ||
|
||
toReset.setRegisteredAt(Instant.now()); | ||
|
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.datatransfer.FeedbackParticipantType; | ||
import teammates.common.datatransfer.InstructorPermissionRole; | ||
import teammates.common.datatransfer.InstructorPrivileges; | ||
|
@@ -62,7 +63,7 @@ public void testCreateDataBundle_typicalValues_createdCorrectly() throws Excepti | |
|
||
AccountRequest actualAccountRequest = dataBundle.accountRequests.get("instructor1"); | ||
AccountRequest expectedAccountRequest = new AccountRequest("[email protected]", "Instructor 1", | ||
"TEAMMATES Test Institute 1"); | ||
"TEAMMATES Test Institute 1", AccountRequestStatus.REGISTERED, "These are some comments."); | ||
expectedAccountRequest.setId(actualAccountRequest.getId()); | ||
expectedAccountRequest.setRegisteredAt(Instant.parse("2015-02-14T00:00:00Z")); | ||
expectedAccountRequest.setRegistrationKey(actualAccountRequest.getRegistrationKey()); | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.AccountRequestStatus; | ||
import teammates.common.exception.EntityDoesNotExistException; | ||
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess; | ||
import teammates.storage.sqlapi.AccountRequestsDb; | ||
|
@@ -20,7 +21,8 @@ public class AccountRequestsDbIT extends BaseTestCaseWithSqlDatabaseAccess { | |
public void testCreateReadDeleteAccountRequest() throws Exception { | ||
______TS("Create account request, does not exists, succeeds"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
______TS("Read account request using the given email and institute"); | ||
|
@@ -53,7 +55,7 @@ public void testCreateReadDeleteAccountRequest() throws Exception { | |
______TS("Create account request, same email address and institute already exist, creates successfully"); | ||
|
||
AccountRequest identicalAccountRequest = | ||
new AccountRequest("[email protected]", "name", "institute"); | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
assertNotSame(accountRequest, identicalAccountRequest); | ||
|
||
accountRequestDb.createAccountRequest(identicalAccountRequest); | ||
|
@@ -74,7 +76,8 @@ public void testCreateReadDeleteAccountRequest() throws Exception { | |
public void testUpdateAccountRequest() throws Exception { | ||
______TS("Update account request, does not exists, exception thrown"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
|
||
assertThrows(EntityDoesNotExistException.class, | ||
() -> accountRequestDb.updateAccountRequest(accountRequest)); | ||
|
@@ -96,7 +99,8 @@ public void testSqlInjectionInCreateAccountRequestEmailField() throws Exception | |
|
||
// Attempt to use SQL commands in email field | ||
String email = "email'/**/OR/**/1=1/**/@gmail.com"; | ||
AccountRequest accountRequest = new AccountRequest(email, "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest(email, "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
|
||
// The system should treat the input as a plain text string | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
@@ -110,7 +114,8 @@ public void testSqlInjectionInCreateAccountRequestNameField() throws Exception { | |
|
||
// Attempt to use SQL commands in name field | ||
String name = "name'; SELECT * FROM account_requests; --"; | ||
AccountRequest accountRequest = new AccountRequest("[email protected]", name, "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", name, "institute", AccountRequestStatus.PENDING, "comments"); | ||
|
||
// The system should treat the input as a plain text string | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
@@ -124,7 +129,8 @@ public void testSqlInjectionInCreateAccountRequestInstituteField() throws Except | |
|
||
// Attempt to use SQL commands in institute field | ||
String institute = "institute'; DROP TABLE account_requests; --"; | ||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", institute); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", institute, AccountRequestStatus.PENDING, "comments"); | ||
|
||
// The system should treat the input as a plain text string | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
@@ -136,7 +142,8 @@ public void testSqlInjectionInCreateAccountRequestInstituteField() throws Except | |
public void testSqlInjectionInGetAccountRequest() throws Exception { | ||
______TS("SQL Injection test in getAccountRequest"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
String instituteInjection = "institute'; DROP TABLE account_requests; --"; | ||
|
@@ -151,7 +158,8 @@ public void testSqlInjectionInGetAccountRequest() throws Exception { | |
public void testSqlInjectionInGetAccountRequestByRegistrationKey() throws Exception { | ||
______TS("SQL Injection test in getAccountRequestByRegistrationKey"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
String regKeyInjection = "regKey'; DROP TABLE account_requests; --"; | ||
|
@@ -166,7 +174,8 @@ public void testSqlInjectionInGetAccountRequestByRegistrationKey() throws Except | |
public void testSqlInjectionInUpdateAccountRequest() throws Exception { | ||
______TS("SQL Injection test in updateAccountRequest"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
String nameInjection = "newName'; DROP TABLE account_requests; --"; | ||
|
@@ -181,13 +190,15 @@ public void testSqlInjectionInUpdateAccountRequest() throws Exception { | |
public void testSqlInjectionInDeleteAccountRequest() throws Exception { | ||
______TS("SQL Injection test in deleteAccountRequest"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
String emailInjection = "email'/**/OR/**/1=1/**/@gmail.com"; | ||
String nameInjection = "name'; DROP TABLE account_requests; --"; | ||
String instituteInjection = "institute'; DROP TABLE account_requests; --"; | ||
AccountRequest accountRequestInjection = new AccountRequest(emailInjection, nameInjection, instituteInjection); | ||
AccountRequest accountRequestInjection = new AccountRequest(emailInjection, nameInjection, instituteInjection, | ||
AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.deleteAccountRequest(accountRequestInjection); | ||
|
||
AccountRequest actual = accountRequestDb.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()); | ||
|
@@ -198,7 +209,8 @@ public void testSqlInjectionInDeleteAccountRequest() throws Exception { | |
public void testSqlInjectionSearchAccountRequestsInWholeSystem() throws Exception { | ||
______TS("SQL Injection test in searchAccountRequestsInWholeSystem"); | ||
|
||
AccountRequest accountRequest = new AccountRequest("[email protected]", "name", "institute"); | ||
AccountRequest accountRequest = | ||
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"); | ||
accountRequestDb.createAccountRequest(accountRequest); | ||
|
||
String searchInjection = "institute'; DROP TABLE account_requests; --"; | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
"name": "Instructor 1", | ||
"email": "[email protected]", | ||
"institute": "TEAMMATES Test Institute 1", | ||
"status": "REGISTERED", | ||
"comments": "These are some comments.", | ||
"registeredAt": "2015-02-14T00:00:00Z" | ||
} | ||
}, | ||
|
27 changes: 27 additions & 0 deletions
27
src/main/java/teammates/common/datatransfer/AccountRequestStatus.java
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package teammates.common.datatransfer; | ||
|
||
/** | ||
* The status of an account request. | ||
*/ | ||
public enum AccountRequestStatus { | ||
|
||
/** | ||
* The account request has not yet been processed by the admin. | ||
*/ | ||
PENDING, | ||
|
||
/** | ||
* The account request has been rejected by the admin. | ||
*/ | ||
REJECTED, | ||
|
||
/** | ||
* The account request has been approved by the admin but the instructor has not created an account yet. | ||
*/ | ||
APPROVED, | ||
|
||
/** | ||
* The account request has been approved by the admin and the instructor has created an account. | ||
*/ | ||
REGISTERED | ||
} |
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
Oops, something went wrong.