Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11878] Add SQL injection tests for AccountRequestsDb #13047

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
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
31 changes: 31 additions & 0 deletions src/it/java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public void testSqlInjectionInCreateAccountRequestInstituteField() throws Except
assertEquals(institute, actual.getInstitute());
}

@Test
public void testSqlInjectionInCreateAccountRequestCommentsField() throws Exception {
______TS("SQL Injection test in comments field");

// Attempt to use SQL commands in comments field
String comments = "comment'; DROP TABLE account_requests; --";
AccountRequest accountRequest =
new AccountRequest("test@gmail.com", "name", "institute", AccountRequestStatus.PENDING, comments);

// The system should treat the input as a plain text string
accountRequestDb.createAccountRequest(accountRequest);
AccountRequest actual = accountRequestDb.getAccountRequest(accountRequest.getId());
assertEquals(comments, actual.getComments());
}

@Test
public void testSqlInjectionInGetAccountRequestByRegistrationKey() throws Exception {
______TS("SQL Injection test in getAccountRequestByRegistrationKey");
Expand All @@ -171,6 +186,22 @@ public void testSqlInjectionInGetAccountRequestByRegistrationKey() throws Except
assertEquals(accountRequest, actual);
}

@Test
public void testSqlInjectionInGetApprovedAccountRequestsForEmail() throws Exception {
______TS("SQL Injection test in getApprovedAccountRequestsForEmail");

String email = "test@gmail.com";
AccountRequest accountRequest =
new AccountRequest(email, "name", "institute", AccountRequestStatus.APPROVED, "comments");
accountRequestDb.createAccountRequest(accountRequest);

// Attempt to use SQL commands in email field
String emailInjection = "email'/**/OR/**/1=1/**/@gmail.com";
List<AccountRequest> actualInjection = accountRequestDb.getApprovedAccountRequestsForEmail(emailInjection);
// The system should treat the input as a plain text string
assertEquals(0, actualInjection.size());
}

@Test
public void testSqlInjectionInUpdateAccountRequest() throws Exception {
______TS("SQL Injection test in updateAccountRequest");
Expand Down
Loading