recent projects in the interface testing HTTP protocol, where the interface request message data has a field value needs to use the encrypted signature, that is, in the network transmission process, the data security considerations, to the requested data processing (encryption), and then make the request.
At first , due to the need for the project to make progress, the choice is: let development write a cryptographic process to generate the code of the request message, and then each test sends a request to run the code with Eclipse, the test data modification is also changed in the code. Run a test in this way, test colleagues are too tired to reflect.
the BeanShell in jmetercan be used to call our tool class to process the data before making the related request. I just used to work in the past, so the use of jmeter BeanShell to solve the problem.
Resolution process:
1, gets the tool class that corresponds to the interface encryption, and generatesJarPackage
this needs to see if the tester has permission to view the code, and if there is no permission, ask the developer to send the code of the tool class directly.
Build a Java project in Eclipse and take the resulting tool class code in. It is then exported into a jar package.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/82/CC/wKiom1dhEhKRL_5RAAHJEtHpgO8336.png "title=" 01.png "alt=" Wkiom1dhehkrl_5raahjethpgo8336.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/CC/wKiom1dhEjKAgFlZAACa8FTB_GI666.png "title=" 02.png "alt=" Wkiom1dhejkagflzaaca8ftb_gi666.png "/>
2, theJarThe package is placed${jmeter_home}\lib\extunder
Place the exported jar Package in the Lib\ext directory of the jmeter . You can also do this without putting it in the directory and then referencing it directly in the JMeter test plan.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/82/CA/wKioL1dhE3GyObqKAAAVofVMYWc764.png "title=" 01.png "alt=" Wkiol1dhe3gyobqkaaavofvmywc764.png "/>
3, creatingJmeterScript
Create a project in JMeter, add a HttpRequest, and add a BeanShell preprocessor to the request.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/CA/wKioL1dhE4KxqiB7AAAg2o8temc576.png "title=" 02.png "alt=" Wkiol1dhe4kxqib7aaag2o8temc576.png "/>
Fill in the corresponding data in the HTTP request according to the actual situation:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/82/CC/wKiom1dhEpewI3ulAADLsog90JQ610.png "title=" 01.png "alt=" Wkiom1dhepewi3ulaadlsog90jq610.png "/>
in the Import our jar package in Beanshellpreprocessor ,the two methods in BeanShell preprocessor are the most commonly used:Vars.get (String PARAMSTR), Vars.put (stringkey,string value), the previous one obtains the value of the variable from JMeter , and the latter is the data stored in the jmeter variable.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/82/CA/wKioL1dhE7eiHhekAAECkCFbwfI183.png "title=" 02.png "alt=" Wkiol1dhe7eihhekaaeckcfbwfi183.png "/>
Description:mac is a field that requires signature encryption, in BeanShell preprocessor the main is to use the cryptographic tool class to encrypt the message, get the encrypted mac value, Then call the Mac in the interface message .
4, ExecutionJmeterScript
The above step script can resolve the interface message needs to be encrypted before sending the requested test processing.
Non-encrypted request result:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/CA/wKioL1dhE-GzUefdAABmQWHI0CI041.png "title=" 01.png "alt=" Wkiol1dhe-gzuefdaabmqwhi0ci041.png "/>
Request results with BeanShell encryption:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/82/CA/wKioL1dhE_Sjp097AACcuJwLjac033.png "title=" 02.png "alt=" Wkiol1dhe_sjp097aaccujwljac033.png "/>
At this point, the interface request encryption processing has been completed, not only to solve the need through the code to generate request messages cumbersome method, but also on the basis of this script to achieve data-driven interface automation testing, testing the small partners can happily test.
This article is from the "Halfway test" blog, so be sure to keep this source http://tiantiantesting.blog.51cto.com/10211292/1789571
Cryptographic processing of interfaces using JMeter's BeanShell