-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
normalized input of parseStringOrThrowError method (#830)
* normalized input of parseStringOrThrowError method * cr * added throws * fixed code * cr * fixed tests * added tests for getQueryParamOrThrowError * added process killing in tests * fixed tests * jar * added latest jar build * removed old jar * reverted date
- Loading branch information
Showing
5 changed files
with
78 additions
and
8 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
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)); | ||
} | ||
} |