Cryptographic processing of interfaces using JMeter's BeanShell

Source: Internet
Author: User
Tags vars

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 JMeter can 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, obtain the corresponding interface encryption tool class, and generate the jar package

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.

2. Put the jar bag under the ${jmeter_home}\lib\ext

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.

3. Create a JMeter script

Create a project in JMeter, add a HttpRequest, and add a BeanShell preprocessor to the request.

Fill in the corresponding data in the HTTP request according to the actual situation:

To 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 variable value from the JMeter, and the latter is the data stored in the JMeter variable.

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, and then call the Mac in the interface message.

4. Execute JMeter Script

The above step script can resolve the interface message needs to be encrypted before sending the requested test processing.

Non-encrypted request result:

Request results with BeanShell encryption:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.