When your software testing encounters an encrypted interface, is it impossible to test?

I believe that when you do interface testing at work, you will definitely encounter a scene, that is, your software, and the password is encrypted and stored.

So in this case, when we implement the interface, we start to have a headache when dealing with passwords.

Therefore, this article will use jmeter, an open source interface testing tool for java, to explain to you how jmeter completes encrypted interface requests

Prior knowledge

Before performing encryption, you need to understand 3 knowledge points:

1. Component -> Pre/Post Processor

2. What is beanshell

3. Built-in variables of beanshell

1. Component -> Pre/Post Processor

Preprocessor: This element highlights a "pre", so it is a processor before the request is made

Post-processor: This element highlights a "post", so it is a processor after the request is sent and the response is obtained

2. What is beanshell

BeanShell is a scripting language that fully complies with the Java syntax specification, and has some syntax and methods of its own.

BeanShell can execute standard Java statements and expressions, and also includes some script commands and syntax.

Simply put, we can write java code in beanshell, and then jmeter will execute these codes.

3. Beanshell built-in variables

vars: Essentially. It is a collection similar to HashMap, so vars can store and read data, and the format of the data it stores is key.value

Its usual syntax:

vars.get(string key): Get a value from the collection

vars.put(string key.string value): Pass the variable to the collection for storage

ps: It should be noted that the vars built-in variable is a local variable and cannot be used across threads! ! !

01

Obtain the encrypted jar package from the development office

For many test engineers with little testing experience, they are a little afraid to ask development for things.

I always feel that if I ask the development, I will be scolded by the development. Don't worry, everyone, no, as long as your request is reasonable, the development team will definitely be willing to cooperate with you.

Therefore, when you want to encrypt data, you must first find the corresponding development, and develop a jar package that provides you with an encryption method.

Because of this encryption method, only the development in the company is the clearest. Moreover, each company's encryption method is different.

02

Reference the jar package in jmeter

There are two ways for jmeter to reference the jar package:

1. Direct reference in the test plan

Add picture annotations, no more than 140 words (optional)

2. Put the jar package under \lib\ext under the jmeter file

Add picture annotations, no more than 140 words (optional)

03

Add an encrypted request

ps: This article will use the password in the login interface to explain

Add picture annotations, no more than 140 words (optional)

04

Under the login request, add a pre-processor and complete the encryption of the password

Why add a pre-processor?

Because we log in with an encrypted password, the password must be encrypted before the request is sent.

Add picture annotations, no more than 140 words (optional)

code show as below:

Add picture annotations, no more than 140 words (optional)

PS: The picture below shows the use of rar software to open the jar package, right-click the jar package, select the opening method, and find the encryption class

Add picture annotations, no more than 140 words (optional)

05

The login request calls the encrypted string

Add picture annotations, no more than 140 words (optional)

06

Add a listener -> View the result tree to confirm the returned data

Add picture annotations, no more than 140 words (optional)

Add picture annotations, no more than 140 words (optional)

So far, the encryption of the request field through jmeter to be described in this article has ended. thanks for watching!

Guess you like

Origin blog.csdn.net/a448335587/article/details/132124154