Mercurial > stress-tester
changeset 1268:f3ef02718781
flow - normalizePathSegments
author | Devel 1 |
---|---|
date | Thu, 02 Jul 2020 16:49:17 +0200 |
parents | 5e1269b93654 |
children | d7209c062524 |
files | stress-tester/src/main/java/com/passus/st/client/http/HttpUrlUtils.java stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java stress-tester/src/test/java/com/passus/st/client/http/HttpUrlUtilsTest.java |
diffstat | 3 files changed, 45 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpUrlUtils.java Thu Jul 02 16:49:17 2020 +0200 @@ -0,0 +1,20 @@ +package com.passus.st.client.http; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * + * @author mikolaj.podbielski + */ +public class HttpUrlUtils { + + public static String normalizePathSegments(String uri) { + try { + return new URI(uri).normalize().toString(); + } catch (URISyntaxException ignore) { + return null; + } + } + +}
--- a/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java Fri Jul 03 09:04:26 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java Thu Jul 02 16:49:17 2020 +0200 @@ -18,6 +18,7 @@ import com.passus.st.client.DataEvents; import com.passus.st.client.Event; import com.passus.st.client.SessionPayloadEvent; +import com.passus.st.client.http.HttpUrlUtils; import com.passus.st.metric.MetricSource; import com.passus.st.metric.MetricsContainer; import com.passus.st.plugin.PluginConstants; @@ -37,8 +38,6 @@ import static com.passus.st.config.CommonNodeDefs.FLOAT_GREATER_EQUAL_ZERO_DEF; import static com.passus.st.config.CommonNodeDefs.INT_GREATER_THAN_ZERO_DEF; import static com.passus.st.config.CommonNodeDefs.STRING_DEF; -import java.util.regex.Matcher; -import java.util.regex.Pattern; @Plugin(name = HttpUrlSequencePayloadAnalyzer.TYPE, category = PluginConstants.CATEGORY_SCANNER_ANALYZER) @NodeDefinitionCreate(HttpUrlSequencePayloadAnalyzer.NodeDefCreator.class) @@ -131,7 +130,7 @@ HttpResponse resp = (HttpResponse) event.getResponse(); if (req != null) { String uri = req.getUri().toString(); - // normalizacja URL + uri = HttpUrlUtils.normalizePathSegments(uri); String method = req.getMethod().toString(); String datetime = sdf.format(new Date(req.getTimestamp())); String userId = userIdExtractor.extract(event);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/http/HttpUrlUtilsTest.java Thu Jul 02 16:49:17 2020 +0200 @@ -0,0 +1,23 @@ +package com.passus.st.client.http; + +import static com.passus.st.client.http.HttpUrlUtils.normalizePathSegments; +import static org.testng.AssertJUnit.*; +import org.testng.annotations.Test; + +/** + * + * @author mikolaj.podbielski + */ +public class HttpUrlUtilsTest { + + @Test + public void testNormalizePathSegments() { + assertEquals("/user/check/login", normalizePathSegments("/user/check/./login")); + assertEquals("/user/login", normalizePathSegments("/user/check/../login")); + assertEquals("beta.bilkom.pl/user/check/login", normalizePathSegments("beta.bilkom.pl/user/check/./login")); + assertEquals("beta.bilkom.pl/user/login", normalizePathSegments("beta.bilkom.pl/user/check/../login")); + assertEquals("/stacje/szukaj/search?q=Czy%C5%BC", normalizePathSegments("/stacje/szukaj/./search?q=Czy%C5%BC")); + assertEquals("/stacje/search?q=Czy%C5%BC", normalizePathSegments("/stacje/szukaj/../search?q=Czy%C5%BC")); + } + +}