Closed asfimport closed 7 years ago
orimarko (migrated from Bugzilla): Attached Patch with added two functions and tests
Created attachment patch.patch: Patch with added two functions and tests
orimarko (migrated from Bugzilla): Add patch with 2 functions and tests
Created attachment patch.patch: Add patch with 2 functions and tests
@pmouawad (migrated from Bugzilla): Thank you for your contribution, I have few remarks:
@pmouawad (migrated from Bugzilla): Also:
orimarko (migrated from Bugzilla): Add patch with digest functions and tests plus function xdocs
Created attachment patchxdocs.patch: Add patch with digest function xdocs
The digest function returns a encrypted value in the specific SHA algorithm with the optional salt, upper case and variable name.
+orimarko (migrated from Bugzilla): Created attachment patch.patch: Patch with new Digest function and tests
@@ -140,4 +143,40 @@
);
}
}
+
+ /**
+ * Utility method to add variable value by variable name
+ *
+ * @param variableName variable name to put
+ * @param value variable value to put
+ */
+ protected void addVariableValue(String value, CompoundVariable[] values, int index) {
+ if (values.length > index) {
+ String variableName = values[index].execute();
+ if (StringUtils.isNotEmpty(variableName)) {
+ JMeterVariables vars = getVariables();
+ if (vars != null) {
+ vars.put(variableName, value);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Upper case value if optional parameter value is true
+ * @param encodedString
+ * @param index
+ * @return
+ */
+ protected String upperCase(String encodedString, CompoundVariable[] values, int index) {
+ if (values.length > index) {
+ String shouldUpperCase = values[index].execute();
+ boolean shouldDoUpperCase = SHOULD_DO_UPPERCASE.equalsIgnoreCase(shouldUpperCase);
+ if (shouldDoUpperCase) {
+ encodedString = encodedString.toUpperCase();
+ }
+ }
+ return encodedString;
+ }
}
Index: core/org/apache/jmeter/resources/messages.properties
===================================================================
--- core/org/apache/jmeter/resources/messages.properties (revision 1813248)
+++ core/org/apache/jmeter/resources/messages.properties (working copy)
@@ -95,6 +95,7 @@
aggregate_report_stddev=Std. Dev.
aggregate_report_total_label=TOTAL
ajp_sampler_title=AJP/1.3 Sampler
+algorithm_string=Digest algorithm
als_message=Note\: The Access Log Parser is generic in design and allows you to plugin
als_message2=your own parser. To do so, implement the LogParser, add the jar to the
als_message3=/lib directory and enter the class in the sampler.
@@ -933,6 +934,7 @@
running_test=Running test
runtime_controller_title=Runtime Controller
runtime_seconds=Runtime (seconds)
+salt_string=Salt to be used for encoding
sample_result_save_configuration=Sample Result Save Configuration
sample_scope=Apply to:
sample_scope_all=Main sample and sub-samples
@@ -1023,6 +1025,7 @@
servername=Servername \:
session_argument_name=Session Argument Name
setup_thread_group_title=setUp Thread Group
+sha_string=String to be encoded
should_save=You should save your test plan before running it. \nIf you are using supporting data files (ie, for CSV Data Set or __StringFromFile), \nthen it is particularly important to first save your test script. \nDo you want to save your test plan first?
shutdown=Shutdown
simple_config_element=Simple Config Element
@@ -1224,6 +1227,7 @@
update_per_iter=Update Once Per Iteration
upload=File Upload
upper_bound=Upper Bound
+upper_case=Upper case result - default false (optional)
url=URL
url_config_get=GET
url_config_http=HTTP
Index: functions/org/apache/jmeter/functions/DigestEncode.java
===================================================================
--- functions/org/apache/jmeter/functions/DigestEncode.java (revision 0)
+++ functions/org/apache/jmeter/functions/DigestEncode.java (working copy)
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter.functions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.functions.AbstractFunction;
+import org.apache.jmeter.functions.InvalidVariableException;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.util.JMeterUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * Sha512 Encode Function Optional Upper case value and save to variable name
+ *
+ * @author orim
+ *
+ */
+public class DigestEncode extends AbstractFunction {
+
+ private static final Logger log = LoggerFactory.getLogger(DigestEncode.class);
+ private static final String UTF_8 = "UTF-8";
+
+ /*
+ * The algorithm names in this section can be specified when generating an
+ * instance of MessageDigest: SHA-1 SHA-256 SHA-384 SHA-512
+ */
+ private static final List
orimarko (migrated from Bugzilla): Patch with new Digest function fixed and tests
Created attachment patch.patch: Patch with new Digest function and tests
@@ -140,4 +143,40 @@
);
}
}
+
+ /**
+ * Utility method to add variable value by variable name
+ *
+ * @param variableName variable name to put
+ * @param value variable value to put
+ */
+ protected void addVariableValue(String value, CompoundVariable[] values, int index) {
+ if (values.length > index) {
+ String variableName = values[index].execute();
+ if (StringUtils.isNotEmpty(variableName)) {
+ JMeterVariables vars = getVariables();
+ if (vars != null) {
+ vars.put(variableName, value);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Upper case value if optional parameter value is true
+ * @param encodedString
+ * @param index
+ * @return
+ */
+ protected String upperCase(String encodedString, CompoundVariable[] values, int index) {
+ if (values.length > index) {
+ String shouldUpperCase = values[index].execute();
+ boolean shouldDoUpperCase = SHOULD_DO_UPPERCASE.equalsIgnoreCase(shouldUpperCase);
+ if (shouldDoUpperCase) {
+ encodedString = encodedString.toUpperCase();
+ }
+ }
+ return encodedString;
+ }
}
Index: core/org/apache/jmeter/resources/messages.properties
===================================================================
--- core/org/apache/jmeter/resources/messages.properties (revision 1813248)
+++ core/org/apache/jmeter/resources/messages.properties (working copy)
@@ -95,6 +95,7 @@
aggregate_report_stddev=Std. Dev.
aggregate_report_total_label=TOTAL
ajp_sampler_title=AJP/1.3 Sampler
+algorithm_string=Digest algorithm
als_message=Note\: The Access Log Parser is generic in design and allows you to plugin
als_message2=your own parser. To do so, implement the LogParser, add the jar to the
als_message3=/lib directory and enter the class in the sampler.
@@ -933,6 +934,7 @@
running_test=Running test
runtime_controller_title=Runtime Controller
runtime_seconds=Runtime (seconds)
+salt_string=Salt to be used for encoding
sample_result_save_configuration=Sample Result Save Configuration
sample_scope=Apply to:
sample_scope_all=Main sample and sub-samples
@@ -1023,6 +1025,7 @@
servername=Servername \:
session_argument_name=Session Argument Name
setup_thread_group_title=setUp Thread Group
+sha_string=String to be encoded
should_save=You should save your test plan before running it. \nIf you are using supporting data files (ie, for CSV Data Set or __StringFromFile), \nthen it is particularly important to first save your test script. \nDo you want to save your test plan first?
shutdown=Shutdown
simple_config_element=Simple Config Element
@@ -1224,6 +1227,7 @@
update_per_iter=Update Once Per Iteration
upload=File Upload
upper_bound=Upper Bound
+upper_case=Upper case result - default false (optional)
url=URL
url_config_get=GET
url_config_http=HTTP
Index: functions/org/apache/jmeter/functions/DigestEncode.java
===================================================================
--- functions/org/apache/jmeter/functions/DigestEncode.java (revision 0)
+++ functions/org/apache/jmeter/functions/DigestEncode.java (working copy)
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter.functions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.functions.AbstractFunction;
+import org.apache.jmeter.functions.InvalidVariableException;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.util.JMeterUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * Sha512 Encode Function Optional Upper case value and save to variable name
+ *
+ * @author orim
+ *
+ */
+public class DigestEncode extends AbstractFunction {
+
+ private static final Logger log = LoggerFactory.getLogger(DigestEncode.class);
+ private static final String UTF_8 = "UTF-8";
+
+ /*
+ * The algorithm names in this section can be specified when generating an
+ * instance of MessageDigest: SHA-1 SHA-256 SHA-384 SHA-512
+ */
+ private static final List
@pmouawad (migrated from Bugzilla): Hello, I am currently merging the patch but I don't see tests . Can you attach the patch that only contains them ? Thanks
orimarko (migrated from Bugzilla): Add patch with tests digest function
Created attachment testpatch.patch: Add patch with tests digest function
orimarko (migrated from Bugzilla): Add tests patch
@pmouawad (migrated from Bugzilla): I merged the function with slight modifications:
Can you review those changes to see if there are issues and to see how to improve your future contributions that I hope will be exist :-) !
Thanks for this great contribution !
For future patches, can you just ensure that you create patch from root of jmeter project.
Author: pmouawad Date: Tue Nov 7 08:25:42 2017 New Revision: 1814464
URL: http://svn.apache.org/viewvc?rev=1814464&view=rev Log: https://github.com/apache/jmeter/issues/4567 - Add __digest function to provide computing of Hashes (SHA-XXX, MDX) https://github.com/apache/jmeter/issues/4567
Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/DigestEncode.java (with props) Modified: jmeter/trunk/src/core/org/apache/jmeter/functions/AbstractFunction.java jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties jmeter/trunk/xdocs/changes.xml jmeter/trunk/xdocs/usermanual/functions.xml
orimarko (migrated from Bugzilla): There are 2 errors in jenkins build
[checkstyle] /home/jenkins/jenkins-slave/workspace/JMeter-trunk/trunk/src/core/org/apache/jmeter/functions/AbstractFunction.java:152:1: error: File contains tab characters (this is the first instance).
[checkstyle] /home/jenkins/jenkins-slave/workspace/JMeter-trunk/trunk/src/functions/org/apache/jmeter/functions/DigestEncode.java:0: error: File does not end with a newline.
orimarko (migrated from Bugzilla): Resolved in apache-jmeter-r1814470, build number 6429
Thank you
@pmouawad (migrated from Bugzilla): Author: pmouawad Date: Wed Nov 8 19:44:02 2017 New Revision: 1814627
URL: http://svn.apache.org/viewvc?rev=1814627&view=rev Log: https://github.com/apache/jmeter/issues/4567 - Add __digest function to provide computing of Hashes (SHA-XXX, MDX) Add tests https://github.com/apache/jmeter/issues/4567
@pmouawad (migrated from Bugzilla): Author: pmouawad Date: Mon Nov 13 20:58:16 2017 New Revision: 1815133
URL: http://svn.apache.org/viewvc?rev=1815133&view=rev Log: https://github.com/apache/jmeter/issues/4567 - Add __digest function to provide computing of Hashes (SHA-XXX, MDX) Suffix class with Function https://github.com/apache/jmeter/issues/4567
Added: jmeter/trunk/src/functions/org/apache/jmeter/functions/DigestEncodeFunction.java
orimarko (Bug 61724): Add sha1 and sha256 functions to JMeter
Created attachment patch.patch: patch
OS: All
Duplicates: