Mercurial > stress-tester
changeset 822:8977a1a9087a
ST-109 in progress
author | Devel 1 |
---|---|
date | Thu, 18 Jan 2018 11:43:32 +0100 |
parents | efc9f09afa8d |
children | f85afb8f6d54 |
files | stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java |
diffstat | 4 files changed, 85 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Thu Jan 18 10:53:52 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Thu Jan 18 11:43:32 2018 +0100 @@ -470,17 +470,10 @@ public static class ContentOperation extends Operation { - protected final HttpMessageHelper messageHelper = HttpMessageHelper.get(); - private final ContentReplacer replacer; private final CharSequence newValue; - public ContentOperation(String rule, CharSequence newValue) { - replacer = ContentExtractorUtils.createReplacer(rule); - this.newValue = newValue; - } - public ContentOperation(ContentReplacer replacer, CharSequence newValue) { this.replacer = replacer; this.newValue = newValue;
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Thu Jan 18 10:53:52 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Thu Jan 18 11:43:32 2018 +0100 @@ -180,12 +180,36 @@ break; } - String newValue = ConfigurationUtils.extractString(valTupleNode.getNode(), errors); - if(errors.hasError()) { + CNode newValueSpecNode = valTupleNode.getNode(); + String newValue = null; + if (newValueSpecNode.getType() == NodeType.VALUE) { + newValue = ConfigurationUtils.extractString(newValueSpecNode, errors); + } else if (newValueSpecNode.getType() == NodeType.MAP) { + CMapNode valAndParamNode = (CMapNode) newValueSpecNode; + List<CTupleNode> valAndParam = valAndParamNode.getChildren(); + for (CTupleNode t : valAndParam) { + String name = t.getName(); + switch (name) { + case "value": + newValue = ConfigurationUtils.extractString(t.getNode(), errors); + break; + case "*escape": + Boolean escape = ConfigurationUtils.extractBoolean(t.getNode(), errors); + replacer.setOption("escape", escape); + break; + default: + errors.reject(newValueSpecNode, "Invalid param: " + name); + break; + } + } + } else { break; } - - op = new ContentOperation(rule, newValue); + if (errors.hasError() || newValue == null) { + break; + } + + op = new ContentOperation(replacer, newValue); } } break;
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Thu Jan 18 10:53:52 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Thu Jan 18 11:43:32 2018 +0100 @@ -10,6 +10,7 @@ import com.passus.st.AppUtils; import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID; import com.passus.st.client.http.HttpFlowContext; +import com.passus.st.client.http.extractor.ContentExtractorUtils; import com.passus.st.client.http.filter.HttpMessageModificationFilter.AddCookieOperation; import com.passus.st.client.http.filter.HttpMessageModificationFilter.AddHeaderOperation; import com.passus.st.client.http.filter.HttpMessageModificationFilter.AddQueryParameterOperation; @@ -111,7 +112,7 @@ .content(content, contentType) .build(); HttpMessageModificationFilter filter = new HttpMessageModificationFilter(); - filter.addOperation(new ContentOperation(rule, newValue)); + filter.addOperation(new ContentOperation(ContentExtractorUtils.createReplacer(rule), newValue)); filter.filterOutbound(req, null, null); String filteredContent = helper.contentToString(req);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java Thu Jan 18 10:53:52 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformerTest.java Thu Jan 18 11:43:32 2018 +0100 @@ -1,11 +1,14 @@ package com.passus.st.client.http.filter; +import com.passus.commons.utils.ReflectionUtils; import com.passus.config.CMapNode; import com.passus.config.CTupleNode; import com.passus.config.CValueNode; import com.passus.config.YamlConfigurationReader; import com.passus.config.validation.Errors; +import com.passus.st.client.http.extractor.PostValueExtractor; import com.passus.st.client.http.filter.HttpMessageModificationFilter.*; +import java.lang.reflect.Field; import java.util.List; import static org.testng.AssertJUnit.*; import org.testng.annotations.Test; @@ -47,15 +50,22 @@ + " addPostParam:\n" + " P3: value\n" + " setContent:\n" - + " regexp:aaa(.+)bbb: aaaa\n"; + + " json:$.node: new\n" + + " setContent:\n" + + " xml:/root/node: new\n" + + " setContent:\n" + + " post:param2: new\n" + + " setContent:\n" + + " regexp:aaa(.+)bbb: new\n"; CTupleNode node = read(config); Errors errors = new Errors(); CValueNode value = transformer.transform(node.getNode(), errors, null); + HttpFilterTestUtils.printErrors(errors); List<Operation> operations = (List) value.getValue(); assertEquals(0, errors.getErrorCount()); - assertEquals(13, operations.size()); + assertEquals(16, operations.size()); assertTrue(operations.get(0) instanceof RemoveHeaderOperation); assertTrue(operations.get(1) instanceof SetHeaderOperation); assertTrue(operations.get(2) instanceof AddHeaderOperation); @@ -69,6 +79,49 @@ assertTrue(operations.get(10) instanceof PostDataSetParamOperation); assertTrue(operations.get(11) instanceof PostDataAddParamOperation); assertTrue(operations.get(12) instanceof ContentOperation); + assertTrue(operations.get(13) instanceof ContentOperation); + assertTrue(operations.get(14) instanceof ContentOperation); + assertTrue(operations.get(15) instanceof ContentOperation); } + @Test + public void testTransform_options() throws Exception { + String config = "operations:\n" + // + " setCookie:\n" + // + " C2: value\n" + // + " addCookie:\n" + // + " C3: value\n" + // + " setQueryParam:\n" + // + " Q2: value\n" + // + " addQueryParam:\n" + // + " Q3: value\n" + // + " setPostParam:\n" + // + " P2: value\n" + // + " addPostParam:\n" + // + " P3: value\n" + + " setContent:\n" + + " post:fld1: '{@var}'\n" + + " setContent:\n" + + " post:fld2:\n" + + " '*escape': false\n" + + " value: '{@var}'\n"; + CTupleNode node = read(config); + + Errors errors = new Errors(); + CValueNode value = transformer.transform(node.getNode(), errors, null); + HttpFilterTestUtils.printErrors(errors); + List<Operation> operations = (List) value.getValue(); + + assertEquals(0, errors.getErrorCount()); +// assertEquals(7, operations.size()); + System.out.println("size: " + operations.size()); + + assertTrue(getEscapeValue(operations.get(0))); + assertFalse(getEscapeValue(operations.get(1))); + } + + private static boolean getEscapeValue(Operation op) throws Exception { + PostValueExtractor replacer = ReflectionUtils.getField(op, "replacer"); + return ReflectionUtils.getField(replacer, "escape"); + } }