Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the beanshell of JMeter to encrypt the interface

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Recently, the interface test of http protocol is being done in the project, in which the field value of the interface request message data needs to be signed after encryption, that is, for the sake of data security in the process of network transmission, the requested data should be specifically processed (encrypted) before the request.

At first, due to the need to catch up with the schedule of the project, the choice is to let the developer write a code that encrypts the generated request message, and then runs the code with eclipse every time the test sends a request, and the changes to the test data are also changed in the code. After running a round of tests like this, the test colleagues all reported that they were too tired.

BeanShell in jmeter can be used to call our utility class to process the data and then make related requests. I happen to have used it in my previous work, so I used jmeter's beanshell to solve this problem.

Resolution process:

1. Get the tool class for the encryption of the corresponding interface, and generate the jar package

This depends on whether the tester has the permission to view the code, and if not, just ask the developer to send the code of the tool class.

Create a Java project in eclipse and import the resulting utility code. It is then exported as a jar package.

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

Place the exported jar package in jmeter's lib\ ext directory. You can also not put it in this directory and refer to it directly in jmeter's test plan.

3. Create a jmeter script

Create a project in jmeter, add a httprequest, and add a BeanShell PreProcessor to the request.

Enter the corresponding data in the http request according to the actual situation:

To import our jar package into BeanShellPreProcessor, the two methods in BeanShellPreProcessor are the most commonly used: vars.get (String paramStr) and vars.put (Stringkey,String value). The first is to get the value of the variable from jmeter, and the other is to store the data in the jmeter variable.

Note: mac is a field that needs to be signed and encrypted. In BeanShell PreProcessor, the encryption tool class is mainly used to encrypt the message to get the encrypted Mac value, and then call mac in the interface message.

4. Execute jmeter script

Through the script of the above steps, the test processing of sending the request after the interface message needs to be encrypted can be solved.

Unencrypted request result:

Request result after beanshell encryption:

At this point, the encryption processing of the interface request has been completed, which not only solves the tedious method of generating the request message through the code, but also realizes the automatic testing of the data-driven interface on the basis of this script. the testers can test happily.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report