-
Notifications
You must be signed in to change notification settings - Fork 266
remove tryForCollectionName function #3456
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
Open
ayushaga14
wants to merge
3
commits into
feature/mini-runtime-release
Choose a base branch
from
mini-runtime-optimisations
base: feature/mini-runtime-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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
174 changes: 174 additions & 0 deletions
174
libs/dao/src/test/java/com/akto/dto/TestHeadersMapPerformance.java
This file contains hidden or 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,174 @@ | ||
| package com.akto.dto; | ||
|
|
||
| import org.junit.Test; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| public class TestHeadersMapPerformance { | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapBasic() { | ||
| String headersString = "{\"Content-Type\":\"application/json\",\"Host\":\"example.com\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals(2, headers.size()); | ||
| assertEquals("application/json", headers.get("content-type").get(0)); | ||
| assertEquals("example.com", headers.get("host").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithEscapedQuotes() { | ||
| String headersString = "{\"accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\",\"accept-encoding\":\"gzip, deflate, br, zstd\",\"accept-language\":\"en-GB,en;q=0.9\",\"cache-control\":\"max-age=0\",\"connection\":\"keep-alive\",\"host\":\"ayush.akto.example\",\"sec-ch-ua\":\"\\\"Not)A;Brand\\\";v=\\\"99\\\", \\\"Google Chrome\\\";v=\\\"127\\\", \\\"Chromium\\\";v=\\\"127\\\"\",\"sec-ch-ua-mobile\":\"?0\",\"sec-ch-ua-platform\":\"\\\"macOS\\\"\",\"sec-fetch-dest\":\"document\",\"sec-fetch-mode\":\"navigate\",\"sec-fetch-site\":\"none\",\"sec-fetch-user\":\"?1\",\"upgrade-insecure-requests\":\"1\",\"user-agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36\"}"; | ||
|
|
||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertTrue(headers.size() > 10); | ||
| assertEquals("ayush.akto.example", headers.get("host").get(0)); | ||
| assertEquals("\"Not)A;Brand\";v=\"99\", \"Google Chrome\";v=\"127\", \"Chromium\";v=\"127\"", headers.get("sec-ch-ua").get(0)); | ||
| assertEquals("\"macOS\"", headers.get("sec-ch-ua-platform").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapEmpty() { | ||
| Map<String, List<String>> headers1 = OriginalHttpRequest.buildHeadersMap(""); | ||
| Map<String, List<String>> headers2 = OriginalHttpRequest.buildHeadersMap(null); | ||
| Map<String, List<String>> headers3 = OriginalHttpRequest.buildHeadersMap("{}"); | ||
|
|
||
| assertNotNull(headers1); | ||
| assertTrue(headers1.isEmpty()); | ||
| assertNotNull(headers2); | ||
| assertTrue(headers2.isEmpty()); | ||
| assertNotNull(headers3); | ||
| assertTrue(headers3.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapCaseInsensitive() { | ||
| String headersString = "{\"Content-Type\":\"application/json\",\"HOST\":\"example.com\",\"Accept\":\"*/*\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("application/json", headers.get("content-type").get(0)); | ||
| assertEquals("example.com", headers.get("host").get(0)); | ||
| assertEquals("*/*", headers.get("accept").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithUnicodeAndSpecialChars() { | ||
| String headersString = "{\"X-Custom-Header\":\"Hello 世界 🌍\",\"Content-Type\":\"text/plain; charset=utf-8\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("Hello 世界 🌍", headers.get("x-custom-header").get(0)); | ||
| assertEquals("text/plain; charset=utf-8", headers.get("content-type").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithBackslashes() { | ||
| String headersString = "{\"X-Path\":\"C:\\\\Users\\\\test\\\\file.txt\",\"X-Regex\":\"\\\\d+\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("C:\\Users\\test\\file.txt", headers.get("x-path").get(0)); | ||
| assertEquals("\\d+", headers.get("x-regex").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithNewlinesAndTabs() { | ||
| String headersString = "{\"X-Multiline\":\"Line1\\nLine2\\nLine3\",\"X-Tab\":\"Col1\\tCol2\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("Line1\nLine2\nLine3", headers.get("x-multiline").get(0)); | ||
| assertEquals("Col1\tCol2", headers.get("x-tab").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithEmptyValues() { | ||
| String headersString = "{\"Empty\":\"\",\"Host\":\"example.com\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("", headers.get("empty").get(0)); | ||
| assertEquals("example.com", headers.get("host").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithNumericValues() { | ||
| String headersString = "{\"Content-Length\":12345,\"X-Rate-Limit\":100,\"X-Float\":3.14}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("12345", headers.get("content-length").get(0)); | ||
| assertEquals("100", headers.get("x-rate-limit").get(0)); | ||
| assertEquals("3.14", headers.get("x-float").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithBooleanAndNull() { | ||
| String headersString = "{\"X-Enabled\":true,\"X-Disabled\":false,\"X-Null\":null}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("true", headers.get("x-enabled").get(0)); | ||
| assertEquals("false", headers.get("x-disabled").get(0)); | ||
| assertEquals("null", headers.get("x-null").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithJsonInValue() { | ||
| // Edge case: nested JSON as a string value | ||
| String headersString = "{\"X-Json-Data\":\"{\\\"key\\\":\\\"value\\\"}\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("{\"key\":\"value\"}", headers.get("x-json-data").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithWhitespace() { | ||
| String headersString = "{ \"Host\" : \"example.com\" , \"Content-Type\" : \"application/json\" }"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("example.com", headers.get("host").get(0)); | ||
| assertEquals("application/json", headers.get("content-type").get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithInvalidJson() { | ||
| String headersString = "{\"Host\":\"example.com\" INVALID"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| // Should return empty map on parse failure | ||
| assertNotNull(headers); | ||
| assertTrue(headers.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapDuplicateKeys() { | ||
| // NOTE: In standard JSON, duplicate keys are not allowed, but if they occur, | ||
| // the last value typically wins. However, our implementation should handle this gracefully. | ||
| // Jackson will only see the last occurrence in the JSON string. | ||
| String headersString = "{\"Cookie\":\"session=abc\",\"Cookie\":\"user=123\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| // Jackson will parse and we'll see only one entry (the last one typically) | ||
| assertTrue(headers.containsKey("cookie")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildHeadersMapWithForwardSlashesAndUrls() { | ||
| String headersString = "{\"Referer\":\"https://example.com/path/to/page?query=value\",\"X-Forwarded-For\":\"192.168.1.1, 10.0.0.1\"}"; | ||
| Map<String, List<String>> headers = OriginalHttpRequest.buildHeadersMap(headersString); | ||
|
|
||
| assertNotNull(headers); | ||
| assertEquals("https://example.com/path/to/page?query=value", headers.get("referer").get(0)); | ||
| assertEquals("192.168.1.1, 10.0.0.1", headers.get("x-forwarded-for").get(0)); | ||
| } | ||
| } |
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 is the same alibaba library... if closing } is not found then infinite loop.