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

[#12901] Added the check for search service and moved the method to the correct file #13021

Closed
wants to merge 6 commits into from
Closed

[#12901] Added the check for search service and moved the method to the correct file #13021

wants to merge 6 commits into from

Conversation

traitsisgiorgos
Copy link

@traitsisgiorgos traitsisgiorgos commented Apr 14, 2024

I added the check to ensure the search service is on in the "testSqlInjectionSearchAccountRequestsInWholeSystem()" and i moved the method to the AccountRequestSearchIT.java.
fix for #12901

Copy link

Hi @traitsisgiorgos, thank you for your interest in contributing to TEAMMATES!
However, your PR does not appear to follow our contribution guidelines:

  • Title must start with the issue number the PR is fixing in square brackets, e.g. [#<issue-number>]
  • Description must reference the issue number the PR is fixing, e.g. Fixes #<issue-number> (or Part of #<issue-number> if the PR does not address the issue fully)

Please address the above before we proceed to review your PR.

@traitsisgiorgos traitsisgiorgos changed the title [ #12901] Added the check for search service and moved the method to the correct file [#12901] Added the check for search service and moved the method to the correct file Apr 14, 2024
Copy link

Hi @traitsisgiorgos, thank you for your interest in contributing to TEAMMATES!
However, your PR does not appear to follow our contribution guidelines:

  • Description must reference the issue number the PR is fixing, e.g. Fixes #<issue-number> (or Part of #<issue-number> if the PR does not address the issue fully)

Please address the above before we proceed to review your PR.

Copy link
Contributor

@mingyuanc mingyuanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks good but could you fix the lint errors? You can run ./gradlew lint to test the lint locally


String searchInjection = "institute'; DROP TABLE account_requests; --";
List<AccountRequest> actualInjection = accountRequestsDb.searchAccountRequestsInWholeSystem(searchInjection);
assertEquals(0, actualInjection.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the component test is failing here where 0 is expected whereas actual is 11, maybe you could check why is it returning such a value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i am trying to fix it. Thanks for the feedback

Copy link
Contributor

@jayasting98 jayasting98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes may be necessary. In addition, like @mingyuanc said, we may want to run lint and fix the errors. Also, let's fix the merge conflicts with the master branch.


String searchInjection = "institute'; DROP TABLE account_requests; --";
List<AccountRequest> actualInjection = accountRequestsDb.searchAccountRequestsInWholeSystem(searchInjection);
assertEquals(typicalBundle.accountRequests.size(), actualInjection.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the expected size still be zero though? I understand that it was changed because the assertion was failing. However, I feel like this search term should not result in some account request being returned, much less all of them. In other words, I feel like the assertion was failing because the actual value might be the one that is wrong, not the initial expected value of zero which seems correct to me.

Still, I am not very familiar with the search functionality. Perhaps another reviewer who is more familiar can chime in.

Comment on lines 187 to 190




Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These empty lines seem like they were not added intentionally. Similarly for the other added empty lines which can be found elsewhere. Can we have this removed?

@@ -15,6 +15,7 @@
import teammates.test.AssertHelper;
import teammates.test.TestProperties;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -10,6 +10,7 @@
import teammates.storage.sqlapi.AccountRequestsDb;
import teammates.storage.sqlentity.AccountRequest;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 170 to 174
______TS("SQL Injection test in searchAccountRequestsInWholeSystem");

if (!TestProperties.isSearchServiceActive()) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have the test segment divider after the check. If the search service is not active, we would not want it to display the string when the test is not going to execute anyway.

Also, we should not have any trailing spaces.

Suggested change
______TS("SQL Injection test in searchAccountRequestsInWholeSystem");
if (!TestProperties.isSearchServiceActive()) {
return;
}
if (!TestProperties.isSearchServiceActive()) {
return;
}
______TS("SQL Injection test in searchAccountRequestsInWholeSystem");

…searchAccountRequests method to escape special characters in the query string. Also expected value has been set to 0
Copy link
Contributor

@jayasting98 jayasting98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update your branch. Also, here are some more comments.

assertEquals(accountRequest, actual);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ensure the files have trailing newlines. That means also for the AccountRequestSearchIT.java file.

Comment on lines +54 to +57
// Escape special characters in the query string
String escapedQueryString = ClientUtils.escapeQueryChars(queryString);

SolrQuery query = getBasicQuery(escapedQueryString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting solution. From what I know, the only special characters here are the two - characters at the end (the SQL comment), so it is weird that it does anything to escape them. Does this actually get the tests to pass? I cannot tell because the GitHub Actions do not seem to be running. I suspect this is because of the conflicting files. Let's update this branch to the latest commit on the master branch and handle the conflicting files.

Regardless, I am also not sure if this can be accepted. Wouldn't this prevent a user from using those special characters when using the search functionality? We may want to see if we can find an alternative way to solve this instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, it isn't passing the tests. if I update it all the changes will be lost

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the comment have been escaped, it shouldn't return 0 responses?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the response is an error the list size should be 0, but what if in our case we don't check it and it accepts the error as a response? That would cause a non-empty-list

Copy link
Contributor

@jayasting98 jayasting98 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I update it all the changes will be lost

We cannot merge this into the master branch unless this is updated and there are no more conflicts. If the changes are lost when it is updated, then the changes should be made again after updating. Please update your branch by merging the master branch (up to the most recent commit) into your branch.

@traitsisgiorgos traitsisgiorgos deleted the #branch_for_12901 branch June 13, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants