Automatic login method for JMeter interface test realized based on RSA encryption algorithm

By calling the RSA encryption algorithm in JMeter to encrypt and cache the login password, the password encryption problem during interface test automatic login is solved, and automated login is realized, which improves testing efficiency and reduces the risk of password leakage.

CN118916271APending Publication Date: 2024-11-08SHANGHAI ZHENHUA HEAVY IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410949214.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When using JMeter for interface testing, the test tool cannot automatically log in to the application software, and there is a risk of leakage when copying and pasting password clear text frequently, and the login process is complicated and cumbersome, and the workload is large.

Method used

By calling Java code containing RSA encryption algorithm in JMeter, the login password is encrypted, and the encrypted ciphertext is stored in system variables to achieve automatic login. The specific steps include adding thread groups, HTTP request default values ​​and HTTP header managers in the JMeter test plan, writing a BeanShell preprocessor to call the RSA encryption algorithm, generating an encrypted ciphertext and cache it in a local variable container, and automatically using it during subsequent login. Log in to this ciphertext.

Benefits of technology

The login function of automated interface testing is realized, the password encryption problem is solved, the efficiency of automated testing is improved, and the risk of password leakage is reduced, and it can be reused multiple times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916271A_ABST
    Figure CN118916271A_ABST
Patent Text Reader

Abstract

The invention discloses a JMeter interface test automatic login method realized based on an RSA encryption algorithm, and the method comprises the following steps: adding a thread group in a JMeter test plan, and adding a user-defined variable, an HTTP request default value and an HTTP information header manager in the thread group; a BeanShel l preprocessing program is added in the thread group, a section of Java code containing an RSA encryption algorithm is called, and a plaintext of the login password is encrypted; and clicking an interface start button to realize the automatic login test of the JMeter interface based on the RSA encryption algorithm. According to the automatic login method for the JMeter interface test, the problem of password encryption during automatic interface test login is solved, the method can be repeatedly used for multiple tests, the purpose of automatic login is achieved, and the efficiency of automatic test login test is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software testing, and more specifically, to a JMeter interface test automatic login method based on an RSA encryption algorithm. Background Art

[0002] When using a test tool, such as JMeter, JMeter is an open source tool software for load function testing and performance testing written in pure Java. It is an interface testing tool suitable for multi-protocol, multi-extension backend API interface testing. JMeter is compact, flexible and easy to use, and is a mainstream Web system performance testing tool. When JMeter tests the login function of the application software, a username and password must be used, but the test tool generally tests the backend interface directly through HTTP requests. There is no front-end code, the password cannot be encrypted, and the application software cannot be logged in directly. At this time, the password ciphertext can only be manually calculated through a third-party tool, and then the password ciphertext is manually entered into the parameter list of the HTTP request, and then the subsequent login operation can be continued. This approach is complicated and troublesome, and the workload is large. When using the test tool for interface testing, the application software cannot be automatically logged in, and frequent copying and pasting of password plaintext will also cause the risk of password leakage. Summary of the invention

[0003] The purpose of the present invention is to provide a JMeter interface test automatic login method based on RSA encryption algorithm. A section of Java code containing RSA encryption algorithm is called by JMeter to encrypt the plain text of login password, and the encrypted ciphertext is stored in system variables. The ciphertext is automatically used in subsequent login tests, which solves the problem of password encryption during login in automated interface tests. The method can be reused for multiple tests, thereby achieving the purpose of automatic login and improving the efficiency of automated login tests.

[0004] In order to achieve the above object, the present invention adopts the following technical solutions:

[0005] The present invention provides a JMeter interface test automatic login method based on RSA encryption algorithm, comprising the following steps:

[0006] S1. Add a thread group to the JMeter test plan, and add a custom variable, an HTTP request default value, and an HTTP header manager to the thread group.

[0007] S2. Add a BeanShell preprocessor to the thread group, call a Java code containing the RSA encryption algorithm, and encrypt the plain text of the login password;

[0008] S3. Click the start button on the interface to implement the JMeter interface automatic login test based on the RSA encryption algorithm.

[0009] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, S1 includes the following steps:

[0010] S11. Add a thread group to the JMeter test plan, set the number of threads in the thread group's thread properties, and then set the Ramp-Up time to control the time to start all threads;

[0011] S12. Add a user-defined variable to the thread group, store some frequently used variables in the cache, and enter the required user variables into the variable table;

[0012] S13. Add an HTTP request default value in the thread group, and enter the protocol name, server name or IP, and port number information of the Web server;

[0013] S14. Add an HTTP Header Manager to the Thread Group and enter Content-Type and Authorization.

[0014] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S13 includes the following steps:

[0015] S131. Enter ${ip} as the server name or IP to get the IP address from the "User Defined Variables";

[0016] S132. After the default value of the HTTP request is set, the subsequent HTTP request will use this default value if no additional value is set.

[0017] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, S2 includes the following steps:

[0018] S21. Write JAVA code in the script input box and implement RSA encryption by writing an RSA encryption algorithm function;

[0019] S22. Call the RSA encryption algorithm function to convert the plain text password into encrypted ciphertext and store it in the local variable container in the JMeter thread.

[0020] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S21 includes the following steps:

[0021] S211. Introduce RSA algorithm dependency package;

[0022] S212. Define an RSA public key variable;

[0023] S213. Input algorithm signature and encrypted data length parameter;

[0024] S214. Define the RSA encryption algorithm function name and parameters;

[0025] S215. Define RSA encryption algorithm function.

[0026] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S215 includes the following steps:

[0027] S2151. Convert the RSA public key to Base64 encoding;

[0028] S2152. Create X509 encoded key specification;

[0029] S2153. Get the KeyFactory object;

[0030] S2154. Generate a public key object according to the X509 encoding key specification;

[0031] S2155. Get the Cipher object according to the converted name;

[0032] S2156. Initialize Cipher object with public key;

[0033] S2157. Use Cipher object to encrypt data segments;

[0034] S2158. Returns the character array of the ciphertext.

[0035] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S2157 includes the following steps:

[0036] S21571. The method process of the server generating public and private keys;

[0037] S21572.Message encryption process.

[0038] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S21571 includes the following steps:

[0039] S215711. Randomly pick two relatively large different prime numbers p and q, N = p*q, and find the least common multiple r of (p-1) and (q-1), the expression is r = (p-1)*(q-1);

[0040] S215712. Choose an integer e less than r, such that e and r are mutually prime, and choose an integer d such that ed-1 is divisible by r, ed = 1 (mod r), then the public key is (N, e), and the private key is (N, d);

[0041] S215713. The public key is open to all clients, and the private key is kept confidential by the server.

[0042] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, the S21572 includes the following steps:

[0043] S215721. Concatenate the Base64 encoding of the client message to be encrypted into a number, which is a non-negative integer n less than N;

[0044] S215722. If the information to be encrypted is long, divide the encrypted information into several segments, and the number of each segment is a non-negative integer less than N;

[0045] S215723. The calculation formula of the encrypted ciphertext C is: C = n^e (mod N), and the ciphertext of the encrypted message is obtained.

[0046] As one aspect of the JMeter interface test automatic login method implemented based on the RSA encryption algorithm of the present invention, S3 includes the following steps:

[0047] S31. After clicking the start button on the interface, run to the BeanShell l preprocessor;

[0048] S32. Automatically encrypt the password and cache it in a local variable container;

[0049] S33. When running to the login interface test, the ciphertext cached in the local variable container is extracted from the HTTP message body, filled into the interface request parameters, and sent to the server to realize automatic login.

[0050] By adopting the above technical solution, the present invention has the following advantages:

[0051] The present invention provides a JMeter interface test automatic login method based on RSA encryption algorithm, which encrypts the plain text of the login password by calling a section of Java code containing the RSA encryption algorithm through JMeter, and stores the encrypted ciphertext in a system variable, and automatically uses the ciphertext in subsequent login tests. The JMeter interface test automatic login method based on RSA encryption algorithm solves the problem of password encryption during automated interface test login, and can be repeatedly used for multiple tests, thereby achieving the purpose of automatic login and improving the efficiency of automated test login tests. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Other features, objectives and advantages of the present invention will become more apparent from a reading of the detailed description of non-limiting embodiments made with reference to the following accompanying drawings.

[0053] Figure 1 This is a flowchart of automatic login for JMeter interface testing based on RSA encryption algorithm;

[0054] Figure 2 It is a schematic diagram of the RSA encryption algorithm function code of the present invention;

[0055] Figure 3 It is an interactive flow chart of the RSA encryption algorithm of an embodiment of the present invention. DETAILED DESCRIPTION

[0056] The technical solution of the present invention is specifically described below in conjunction with the drawings in the specification. The detailed features and advantages of the present invention are described in detail in the specific implementation mode. The content is sufficient to enable any technical personnel in the field to understand the technical content of the present invention and implement it accordingly. According to the description, claims and drawings disclosed in this specification, the technical personnel in the field can easily understand the relevant purposes and advantages of the present invention.

[0057] Figure 1 The flowchart of the JMeter interface test automatic login method based on the RSA encryption algorithm is shown. A JMeter interface test automatic login method based on the RSA encryption algorithm is specifically as follows Figure 1 As shown, the following steps are included:

[0058] S1. Add a thread group to the JMeter test plan, and add a custom variable, an HTTP request default value, and an HTTP header manager to the thread group.

[0059] Among them, S1 includes the following specific steps:

[0060] S11. Add a thread group to the JMeter test plan, set the number of threads in the thread group's thread properties. The value of the number of threads represents the number of concurrent network users. Then set the Ramp-Up time to control the time to start all threads. For example, if the number of threads is set to 10 and the Ramp-Up time is set to 5, then 10 threads will be started within 5 seconds, and 2 threads will be started per second. Then set the number of loops to control the number of times each thread sends data requests. For example, if the number of threads is set to 10 and the number of loops is set to 10, then each thread will send 10 data requests, and all threads will send a total of 10*10=100 data requests. To test the automatic login interface, the thread properties use the system default settings, the number of threads = 1, Ramp-Up = 1, and the number of loops = 1. That is, create a user, start 1 thread within 1 second, and send 1 data request.

[0061] S12. Add a "user defined variable" in the JMeter thread group to store some variables that will be frequently used in subsequent interface tests in the cache to facilitate variable value modification and interface calls. Enter the required user variables, such as user name, password, IP address, RSA public key RSAPublicKey, etc. into the variable table. The values ​​of the entered user variables are all plain text. The RSA public key is a string of 128 characters.

[0062] S13. Add an HTTP request default value in the thread group, and enter the protocol name, server name or IP, and port number information of the Web server;

[0063] Wherein, S13 includes the following specific steps:

[0064] S131. Enter ${ip} as the server name or IP to get the IP address from the "User Defined Variables";

[0065] S132. After the default value of the HTTP request is set, the subsequent HTTP request will use this default value if no additional value is set.

[0066] S14. Add an "HTTP Header Manager" in the thread group, enter "Content-Type" and "Authorization", Content-Type defines the type of network files and the encoding of web pages, Authorization saves verification information, set Content-Type = "application / json; charset = UTF-8", define the media type in the HTTP request as json data format, and the character encoding of the HTML document as UTF-8.

[0067] S2. Add a BeanShell preprocessor to the thread group. The BeanShell preprocessor is a small embedded Java interpreter that comes with JMeter. It can execute Java syntax and call a Java code containing the RSA encryption algorithm to encrypt the plain text of the login password.

[0068] S2 includes the following specific steps:

[0069] S21. Write JAVA code in the script input box, and implement RSA encryption by writing a RSA encryption algorithm function. RSA is an asymmetric encryption algorithm. The RSA algorithm has a pair of different keys, namely a public key and a private key. The public key is open to the public, and the private key is kept by the server and not open to the public. When information is transmitted, the client program encrypts the information with the public key and transmits it. After receiving the encrypted information, the server decrypts it with the private key. This ensures the security of the information and avoids the risk of information being cracked by directly transmitting the key.

[0070] Wherein, S21 includes the following specific steps:

[0071] S211. Import RSA algorithm dependency packages: for example: importorg.apache.commons.codec.binary.Base64; the BeanShell preprocessor references a class by the full name of the package and class or imports one or more classes from a Java package.

[0072] S212. Define an RSA public key variable: defined as String RSA_PUB_KEY, the value is obtained from the user-defined variable, that is, String RSA_PUB_KEY = "${RSAPublicKey}".

[0073] S213. Input algorithm signature, encrypted data length parameters: for example, String KEY_ALGORITHM = "RSA", int MAX_ENCRYPT_BLOCK = 117. RSA requires that the maximum length of the encrypted data cannot be greater than the length of the public key string. At present, the key length of mainstream security is at least 1024 bits, and the maximum length of the encrypted data each time is 1024 / 8 = 128 bytes. If the length of the data to be encrypted exceeds 128 bytes, the data needs to be encrypted in segments. In order to ensure that the ciphertext after each encryption is different, a string of random characters is spliced ​​after the original text during encryption. The random characters occupy 11 strings, so the actual length of each encrypted data is 128-11 = 117 characters. When decrypting, subtract 11 strings from the decrypted plaintext to get the original data.

[0074] S214. Define the RSA encryption algorithm function name and parameters: public static byte[]encryptByPublicKey(byte[]data,String publicKey). In the function parameters, data is the data to be encrypted, and publicKey is the RSA public key;

[0075] Figure 2 It is a schematic diagram of the RSA encryption algorithm function code of the present invention.

[0076] S215. Define RSA encryption algorithm function.

[0077] Among them, S215 includes the following specific steps: Figure 2 As shown:

[0078] S2151. Convert publicKey, i.e. RSA public key, into Base64 encoding: byte[]keyBytes=

[0079] Base64.decodeBase64(publicKey); Base64 encoding processes the binary data of publicKey, and divides each 3 bytes (8 bits per byte) into a group, a total of 3x8=24 bits, and then divides these 24 bits into 4 groups, each with 6 bits. The length increases to 4 / 3 of the original. If the binary data is not a multiple of 6, fill it with "0" to make its byte number a multiple of 6. If the binary data is less than 4 groups, fill it with "=".

[0080] S2152. Create X509 encoded key specification: 2) X509EncodedKeySpec x509KeySpec = newX509EncodedKeySpec (keyBytes); According to the ASN.1 standard, in accordance with the ASN.1X.509 encoding standard, create a new key specification using the given encoded key.

[0081] S2153. Get the KeyFactory object: KeyFactory keyFactory=

[0082] KeyFactory.getInstance(KEY_ALGORITHM); creates a new object instance of the RSA algorithm by calling the getInstance method and returns the new object instance.

[0083] S2154. Generate a public key object according to the X509 encoding key specification: Key publicK =

[0084] keyFactory.generatePublic(x509KeySpec);

[0085] S2155. Get the cipher object Cipher according to the converted name; Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());

[0086] S2156. Initialize the Cipher object with the public key: cipher.init(Cipher.ENCRYPT_MODE, publicK);

[0087] S2157. Use Cipher object to encrypt data in segments; cache = cipher.doFinal (data, offSet, MAX_ENCRYPT_BLOCK);

[0088] Among them, S2157 includes the following specific steps:

[0089] S21571. The method process of the server generating public and private keys;

[0090] Among them, S21571 includes the following specific steps:

[0091] S215711. Randomly pick two relatively large different prime numbers p and q, N = p*q, and find the least common multiple r of (p-1) and (q-1), the expression is r = (p-1)*(q-1);

[0092] S215712. Choose an integer e less than r, such that e and r are mutually prime, and choose an integer d such that ed-1 is divisible by r, ed = 1 (mod r), then the public key is (N, e), and the private key is (N, d);

[0093] S215713. The public key is open to all clients, and the private key is kept confidential by the server.

[0094] S21572.Message encryption process.

[0095] Among them, S21572 includes the following specific steps:

[0096] S215721. Concatenate the Base64 encoding of the client message to be encrypted into a number, which is a non-negative integer n less than N;

[0097] S215722. If the information to be encrypted is long, divide the encrypted information into several segments, and the number of each segment is a non-negative integer less than N;

[0098] S215723. The calculation formula of the encrypted ciphertext C is: C = n^e (mod N), and the ciphertext of the encrypted message is obtained.

[0099] S2158. Return the character array of the ciphertext: byte[]encryptedData=out.toByteArray().

[0100] S22. Call the RSA encryption algorithm function to convert the plain text password into encrypted ciphertext, named "sign", and store it in the local variable container vars in the JMeter thread.

[0101] Figure 3 The RSA encryption algorithm interaction flow chart of the embodiment of the present invention is shown. The RSA encryption algorithm interaction flow chart is as follows: Figure 3 As shown, first, the server generates a key pair, then the server sends the public key to the client, the client encrypts using the public key of the server, the client sends the ciphertext to the server, and finally, the server decrypts using the private key.

[0102] S3. Click the start button on the interface to implement the JMeter interface automatic login test based on the RSA encryption algorithm.

[0103] S3 includes the following steps:

[0104] S31. After clicking the start button on the interface, the BeanShell preprocessor is executed;

[0105] S32 automatically encrypts the password and caches it in a local variable container;

[0106] S33. When running to the login interface test, the ciphertext "sign" cached in the local variable container vars is extracted from the HTTP message body in the format of "${sign}", for example: "password":"${sign}", and filled into the interface request parameters, and sent to the server, finally realizing automatic login.

[0107] In summary, this method uses JMeter to call a Java code containing the RSA encryption algorithm to encrypt the plain text of the login password, and stores the encrypted ciphertext in the system variable, which is automatically used in subsequent login tests. This method solves the problem of password encryption during automated interface testing login, and can be reused for multiple tests, achieving the purpose of automatic login and improving the efficiency of automated login testing.

[0108] Finally, it should be pointed out that although the present invention has been described with reference to the current specific embodiments, ordinary technicians in this technical field should realize that the above embodiments are only used to illustrate the present invention and are not used as a limitation of the present invention. Various equivalent changes or substitutions can be made without departing from the concept of the present invention. Therefore, as long as the changes and modifications to the above embodiments are within the essential spirit of the present invention, they will fall within the scope of the claims of the present invention.

Claims

1. A JMeter interface test automatic login method based on RSA encryption algorithm, characterized in that: The following steps are involved: S1. Add a thread group to the JMeter test plan, and add a custom variable, an HTTP request default value, and an HTTP header manager to the thread group. S2. Add a BeanShell preprocessor to the thread group, call a Java code containing the RSA encryption algorithm, and encrypt the plain text of the login password; S3. Click the start button on the interface to implement the JMeter interface automatic login test based on the RSA encryption algorithm.

2. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 1, characterized in that: The S1 comprises the following steps: S11. Add a thread group to the JMeter test plan, set the number of threads in the thread group's thread properties, and then set the Ramp-Up time to control the time to start all threads; S12. Add a user-defined variable to the thread group, store some frequently used variables in the cache, and enter the required user variables into the variable table; S13. Add an HTTP request default value in the thread group, and enter the protocol name, server name or IP, and port number information of the Web server; S14. Add an HTTP Header Manager to the Thread Group and enter Content-Type and Authorization.

3. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 2, characterized in that: The S13 comprises the following steps: S131. Enter ${ip} as the server name or IP address to get the IP address from "User defined variables"; S132. After the default value of the HTTP request is set, the subsequent HTTP request will use this default value if no additional value is set.

4. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 1, characterized in that: The S2 comprises the following steps: S21. Write JAVA code in the script input box and implement RSA encryption by writing an RSA encryption algorithm function; S22. Call the RSA encryption algorithm function to convert the plain text password into encrypted ciphertext and store it in the local variable container in the JMeter thread.

5. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 1, characterized in that: The S21 comprises the following steps: S211. Introduce RSA algorithm dependency package; S212. Define an RSA public key variable; S213. Input algorithm signature and encrypted data length parameter; S214. Define the RSA encryption algorithm function name and parameters; S215. Define RSA encryption algorithm function.

6. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 5, characterized in that: The S215 comprises the following steps: S2151. Convert the RSA public key to Base64 encoding; S2152. Create X509 encoded key specification; S2153. Get the KeyFactory object; S2154. Generate a public key object according to the X509 encoding key specification; S2155. Get the Cipher object according to the converted name; S2156. Initialize Cipher object with public key; S2157. Use Cipher object to encrypt data segments; S2158. Returns the character array of the ciphertext.

7. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 6, characterized in that: The S2157 comprises the following steps: S21571. The method process of the server generating public and private keys; S21572.Message encryption process.

8. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 7, characterized in that: The S21571 includes the following steps: S215711. Randomly pick two relatively large different prime numbers p and q, N = p*q, and find the least common multiple r of (p-1) and (q-1), the expression is r = (p-1)*(q-1); S215712. Choose an integer e less than r, such that e and r are mutually prime, and choose an integer d such that ed-1 is divisible by r, ed = 1 (mod r), then the public key is (N, e), and the private key is (N, d); S215713. The public key is open to all clients.

9. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 7, characterized in that: The S21572 includes the following steps: S215721. Concatenate the Base64 encoding of the client message to be encrypted into a number, which is a non-negative integer n less than N; S215722. If the information to be encrypted is long, divide the encrypted information into several segments, and the number of each segment is a non-negative integer less than N; S215723. The calculation formula of the encrypted ciphertext C is: C = n^e (mod N), and the ciphertext of the encrypted message is obtained.

10. A JMeter interface test automatic login method based on RSA encryption algorithm as claimed in claim 1, characterized in that: The S3 comprises the following steps: S31. After clicking the start button on the interface, run to the BeanShell preprocessor; S32. Automatically encrypt the password and cache it in a local variable container; S33. When running to the login interface test, the ciphertext cached in the local variable container is extracted from the HTTP message body, filled into the interface request parameters, and sent to the server to realize automatic login.