-
Notifications
You must be signed in to change notification settings - Fork 547
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
normalized input of parseStringOrThrowError method #830
Merged
rishabhpoddar
merged 18 commits into
supertokens:email-auto-normalise
from
Taz03:normalize-input
Oct 15, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fecd7b6
normalized input of parseStringOrThrowError method
Taz03 7285ac6
cr
Taz03 16fab74
added throws
Taz03 9475fd8
fixed code
Taz03 ee5c404
cr
Taz03 01b5d40
Merge branch '7.0' into normalize-input
Taz03 777adca
fixed tests
Taz03 57d4374
added tests for getQueryParamOrThrowError
Taz03 62e3117
added process killing in tests
Taz03 73a0f95
fixed tests
Taz03 ae7d7ce
updated branch
Taz03 602b5ec
jar
Taz03 b8c5469
update branch
Taz03 6c62c9e
added latest jar build
Taz03 9d86429
removed old jar
Taz03 1f0b804
reverted date
Taz03 50c1cf2
update branch
Taz03 47c0f05
update branch
Taz03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import io.supertokens.pluginInterface.STORAGE_TYPE; | ||
import io.supertokens.storageLayer.StorageLayer; | ||
import io.supertokens.webserver.InputParser; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
|
@@ -30,6 +31,7 @@ | |
import jakarta.servlet.ServletException; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class InputParserTest { | ||
@Rule | ||
|
@@ -104,4 +106,51 @@ public void testParseStringOrJSONNullOrThrowError() throws Exception { | |
process.kill(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); | ||
} | ||
|
||
@Test | ||
public void testParseStringOrThrowError() throws Exception { | ||
String[] args = { "../" }; | ||
|
||
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
JsonObject json = new JsonObject(); | ||
json.addProperty("untrimed mixedcase email", "[email protected] "); | ||
json.addProperty("email", "[email protected]"); | ||
json.addProperty("untrimed mixedcase text", " TexT "); | ||
json.addProperty("mixedcase text", "TeXt"); | ||
|
||
assertEquals(InputParser.parseStringOrThrowError(json, "untrimed mixedcase email", false), "[email protected]"); | ||
assertEquals(InputParser.parseStringOrThrowError(json, "email", false), "[email protected]"); | ||
assertEquals(InputParser.parseStringOrThrowError(json, "untrimed mixedcase text", false), "TexT"); | ||
assertEquals(InputParser.parseStringOrThrowError(json, "mixedcase text", false), "TeXt"); | ||
assertNull(InputParser.parseStringOrThrowError(json, "undefined", true)); | ||
|
||
process.kill(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); | ||
} | ||
|
||
@Test | ||
public void testGetQueryParamOrThrowError() throws Exception { | ||
String[] args = { "../" }; | ||
|
||
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
|
||
when(request.getParameter("untrimed mixedcase email")).thenReturn("[email protected] "); | ||
when(request.getParameter("email")).thenReturn("[email protected]"); | ||
when(request.getParameter("untrimed mixedcase text")).thenReturn(" TexT "); | ||
when(request.getParameter("mixedcase text")).thenReturn("TeXt"); | ||
|
||
assertEquals(InputParser.getQueryParamOrThrowError(request, "untrimed mixedcase email", false), "[email protected]"); | ||
assertEquals(InputParser.getQueryParamOrThrowError(request, "email", false), "[email protected]"); | ||
assertEquals(InputParser.getQueryParamOrThrowError(request, "untrimed mixedcase text", false), "TexT"); | ||
assertEquals(InputParser.getQueryParamOrThrowError(request, "mixedcase text", false), "TeXt"); | ||
assertThrows(ServletException.class, () -> InputParser.getQueryParamOrThrowError(request, "undefined", false)); | ||
|
||
process.kill(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called for non GET request. We might want to add the trim and toLowerCase (in case of email), to the GET request equivalent as well. The functions are
getQueryParamOrThrowError
andgetCommaSeparatedStringArrayQueryParamOrThrowError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done