changeset 1292:78e67587e149

SequenceConverter - bugfixes, cmd switches
author Devel 1
date Wed, 15 Jul 2020 11:58:35 +0200
parents 610c12a93ee7
children 4304b8e547bf
files stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java
diffstat 1 files changed, 54 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java	Tue Jul 14 16:53:23 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java	Wed Jul 15 11:58:35 2020 +0200
@@ -28,25 +28,23 @@
 public class SequenceConverter {
 
     enum IdType {
-        IP, Cookie, Header
+        None, IP, Cookie, Header
     }
 
-    IdType idType = IdType.IP;
+    IdType idType = IdType.None;
     String idKey;
-    int multiplier = 7;
-    int maxRepeats = 100;
+    int multiplier = 10;
+    int maxRepeats = 10;
 
     static Map<String, Object> prepareMatchFilter(List<String> ignoredUrls) {
         List<Map<String, Object>> matches = new ArrayList<>(ignoredUrls.size());
         for (String ignoredUrl : ignoredUrls) {
-            matches.add(smap("@req.uri", ignoredUrl));
+            matches.add(smap("@req.url.path", smap("$contains", ignoredUrl)));
         }
         return lmap(
                 e("type", "matcher"),
-                //e("acceptOnMatch", true),
-                e("matches", matches)
+                e("matches", smap("$or", matches))
         );
-
     }
 
     Map<String, Object> prepareSequenceFilter(List<String> steps) {
@@ -58,6 +56,8 @@
                 first = false;
             } else {
                 switch (idType) {
+                    case None:
+                        break;
                     case IP:
                         matcher.put("@context.session.srcIp", "@_i0.context.session.srcIp");
                         break;
@@ -100,10 +100,47 @@
         }
     }
 
+    void resolveUserIdSpec(String spec) {
+        int idx = spec.indexOf(':');
+        String type;
+        String arg;
+        if (idx < 0) {
+            type = spec;
+            arg = null;
+        } else {
+            type = spec.substring(0, idx);
+            arg = spec.substring(idx + 1);
+        }
+
+        switch (type) {
+            case "none":
+                idType = IdType.None;
+                idKey = null;
+                break;
+            case "ip":
+                idType = IdType.IP;
+                idKey = null;
+                break;
+            case "cookie":
+                idType = IdType.Cookie;
+                idKey = arg;
+                break;
+            case "header":
+                idType = IdType.Header;
+                idKey = arg;
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
+
     public static void main(String... args) {
         final Options options = new Options();
         options.addOption(option("l", "logLevel", "Log level.", "level"));
         options.addOption(option("f", "useFold", "Use this if processing folded sequences."));
+        options.addOption(option("m", "multiplier", "How many repeats of sequence to inject.", "multiplier"));
+        options.addOption(option("r", "repeats", "How many repeats of single step to collapse.", "repeats"));
+        options.addOption(option("id", "id", "User ID type none|ip|cookie:name|header:name", "repeats"));
 
         try {
             CommandLine cl = new DefaultParser().parse(options, args);
@@ -132,6 +169,15 @@
             ArrayList<ArrayList<String>> sequences = result.getSequences(fold);
 
             SequenceConverter converter = new SequenceConverter();
+            if (cl.hasOption('m')) {
+                converter.multiplier = Integer.parseInt(cl.getOptionValue('m'));
+            }
+            if (cl.hasOption('r')) {
+                converter.maxRepeats = Integer.parseInt(cl.getOptionValue('r'));
+            }
+            if (cl.hasOption("id")) {
+                converter.resolveUserIdSpec(cl.getOptionValue("id"));
+            }
             converter.writeSequenceFilterConf(sequences, Arrays.asList(result.ignoredUrls), output);
 
         } catch (ParseException e) {