Mock method, system and electronic equipment of message encryption interface and medium

By configuring matching items and carried content for the test application and establishing an association between the carried content and the response message, the problem of the mock service being unable to distinguish the response message after the interface request is encrypted is solved, thereby improving test efficiency.

CN119544484BActive Publication Date: 2025-10-10CHINA UNITED NETWORK COMM GRP CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411732132.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-10-10
Estimated Expiration
2044-11-28

AI Technical Summary

Technical Problem

After the request body of the interface request is encrypted, the mock service cannot decipher the distinguishing information from it, resulting in different testers having to conduct request tests on the same interface at separate times, which reduces testing efficiency.

Method used

By configuring matching items and carried content for each test application, an association between carried content and response messages is established in the mock service. When a match is successful, the carried content is added to the request, allowing the mock service to distinguish and return the corresponding response message based on the carried content.

Benefits of technology

When the interface request is encrypted, the mock service can distinguish the requests of different testers, thereby improving the testing efficiency and avoiding the problem that different testers need to conduct separate tests on the same interface request.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119544484B_ABST
    Figure CN119544484B_ABST
Patent Text Reader

Abstract

The present disclosure provides a mock method and system of a message encryption interface, an electronic device and a storage medium to solve the problem that when the content of the request body is encrypted, the mock service cannot return the distinguished response message. The method comprises: determining all test applications, encryption methods of the test applications and interface URIs of the test applications; configuring the matching items and carrying contents corresponding to each test application; establishing an association between the carrying contents and the response messages in the mock service; matching the matching items of the test application before the interface request represented by the interface URI of the test application is sent, and if the matching is successful, the carrying contents are added to the request; reading the carrying contents in the request in the mock service, and performing the distinguishing processing of the response message according to the carrying contents and the association. The present disclosure can distinguish different requests when the message is encrypted and return the corresponding response message, thereby improving the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a mock method for a message encryption interface, a mock system for a message encryption interface, an electronic device, and a computer-readable storage medium. Background Art

[0002] Mocking an interface typically involves changing the interface's request address in some way so that when the interface is requested (when sending an HTTP request), it is directed to a specified service (i.e., a mock service) instead of the original service. For interface requests initiated from a client (such as a browser), the request address can be modified using a proxy tool (such as Fiddler). For interface requests within a service, changing the request address typically requires code-level manipulation by the developer. For example, when starting a service in a test environment, the address of a mock service is read from the configuration (such as the Apollo configuration platform) to replace the original address of the interface (i.e., the address of the production environment), thereby mocking the interface in the test environment. Regardless of the method used to mock an interface within a service, the interface request is ultimately sent to the mock service, which receives the request, responds to it, and returns the specified response message to the caller.

[0003] Generally speaking, the mock service needs to distinguish the content of the response that needs to be returned based on the content of the request, so that different testers can get the response content they want when making requests to the same interface. The mock service usually distinguishes based on the content in the request body. For example, when the request body contains a mobile phone number, it will return the corresponding response result based on different mobile phone numbers (the mobile phone number and response result are configured in advance). However, sometimes the content of the request body is encrypted, making it impossible for the mock service to interpret the information that can be used for distinction from the request body, and thus unable to return the differentiated response message. An example is Figure 1 and Figure 2 As shown, under normal circumstances, the interface request inside the service will carry the plain text request body content to the mock service request after being mocked (such as Figure 1 ), and sometimes, for data security reasons, the request body will be encrypted before it is sent and converted into ciphertext (such as Figure 2 In this scenario, testers can only set the interface in the mock service to uniformly return a fixed response message. Therefore, different testers can only test the request of the same interface at different times (to avoid affecting each other), which reduces the test efficiency. Summary of the Invention

[0004] In order to at least solve the problem in the prior art that when the content of the request body is encrypted, the mock service cannot interpret the information that can be used to distinguish from the request body, and thus cannot return the differentiated response message. The present disclosure provides a mock method for a message encryption interface, a mock system for a message encryption interface, an electronic device, and a computer-readable storage medium, so that when the message is encrypted in the mock service, different requests can be distinguished and corresponding response messages can be returned, solving the problem that different testers can only test the requests of the same interface at different times, thereby improving testing efficiency.

[0005] In the first aspect, the present disclosure provides a mock method for a message encryption interface.

[0006] The methods include:

[0007] Determine all test applications, their encryption methods, and their interface URIs (Uniform Resource Identifiers).

[0008] Configure the corresponding matching items and carried content for each test application;

[0009] Establish an association between the content and response message in the mock service;

[0010] Before sending the interface request represented by the interface URI of the test application, the matching items of the test application are matched. If the match is successful, the carried content is added to the request;

[0011] The content carried in the request is read in the mock service, and the response message is distinguished and processed according to the content carried and the association relationship.

[0012] Furthermore, the method further comprises:

[0013] Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

[0014] Further,

[0015] Configuring the corresponding matching items for each test application includes:

[0016] Set the corresponding preset parameter values ​​at the designated locations of the encryption methods for each test application;

[0017] Matching the matching items of the test application includes:

[0018] Get the value of the parameter at the specified position of the current encryption method, and determine whether the value is the configured preset parameter value;

[0019] If so, the match is successful.

[0020] Furthermore, the method also includes:

[0021] Determine whether the currently configured application on the display page has been mounted and monitored;

[0022] If the monitor is already mounted, change the current configuration status to enabled;

[0023] If the listener is not mounted, first mount the listener for the application. After the mount is successful, save the mount identifier of the application in redis (RemoteDictionary Server, remote dictionary service);

[0024] The step of determining whether the currently configured application on the display page has been mounted and monitored includes:

[0025] Try to read the application's mount flag stored in Redis. If the value is read, it means that the application has been mounted and listened.

[0026] Furthermore, the matching items of the test application are matched, and if the match is successful, the carried content is added to the request, including:

[0027] S1: Monitor all methods in the application, including encryption methods and request methods. When a method is called, execute steps S2 and S7 before executing it.

[0028] S2: Determine whether the current method is an encryption method in the display page. If so, execute S3;

[0029] S3: Determine whether the status is on, if so, execute S4;

[0030] S4: Determine whether the matching item and the carried content in the configuration information of the encryption method are both not empty. If so, execute S5;

[0031] S5: Set a global variable flag with an initial value of true. Then read all matching information of the current encryption method, traverse each line of information, and execute the following logic for each line of information: obtain the value of the parameter at the specified position of the current encryption method, and determine whether the value contains the configured matching value. If not, set the flag to false and end the traversal. If the flag value is still true after all traversals are completed, execute S6.

[0032] S6: Read the content information configured by the current encryption method, combine the content information into a JSON string, and then save the combined JSON string into a preset thread variable;

[0033] S7: Determine whether the current method is an interface request method. If yes, execute S8;

[0034] S8: Determine whether the URI of the current request method is an interface URI in the display page. If so, try to read the content from the pre-collected thread variable. If it can be read, execute S9;

[0035] S9: Use mockData as the request header key and the read json string as the request header value to form a new request header item and add it to the request header.

[0036] In a second aspect, the present disclosure provides a mock system for a message encryption interface, the system comprising:

[0037] A determination module configured to determine all test applications, encryption methods of the test applications, and interface URIs of the test applications;

[0038] A configuration module configured to configure corresponding matching items and carried content for each test application;

[0039] The association module is configured to establish an association between the content and the response message in the mock service;

[0040] A matching module is configured to match the matching items of the test application before sending the interface request represented by the interface URI of the test application. If the match is successful, the carried content is added to the request;

[0041] The processing module is configured to read the carried content in the request in the mock service, and perform distinguishing processing on the response message according to the carried content and the association relationship.

[0042] Furthermore, the determining module is further configured to:

[0043] Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

[0044] Further,

[0045] The configuration module is specifically configured as follows:

[0046] Set the corresponding preset parameter values ​​at the designated locations of the encryption methods for each test application;

[0047] The matching module is specifically configured as follows:

[0048] Get the value of the parameter at the specified position of the current encryption method, and determine whether the value is the configured preset parameter value;

[0049] If so, the match is successful.

[0050] In a third aspect, the present disclosure provides an electronic device comprising a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes the mock method of the message encryption interface as described in any one of the first aspects.

[0051] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the mock method of the message encryption interface described in any one of the first aspects is implemented.

[0052] Beneficial effects:

[0053] The present disclosure provides a mock method for a message encryption interface, a mock system for a message encryption interface, an electronic device, and a storage medium. For an interface requesting message encryption, by configuring matching items and carried content corresponding to a test application, a mock service can perform differentiated processing by reading the content carried in the request. This enables the mock service to distinguish different requests and return corresponding response messages, solving the problem that different testers can only test requests for the same interface at separate times, thereby improving testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 This is a diagram of a request to a mock service with a request body containing plain text content.

[0055] Figure 2 This is a diagram showing how the request body is encrypted and converted into ciphertext to request the mock service.

[0056] Figure 3 A schematic diagram of a mock method for a message encryption interface provided in the first embodiment of the present disclosure;

[0057] Figure 4 A schematic diagram of adding a test application page for a configuration provided in an embodiment of the present disclosure;

[0058] Figure 5 A schematic diagram of a test application display page configured according to an embodiment of the present disclosure;

[0059] Figure 6A schematic diagram of a configuration matching item and content configuration page provided in an embodiment of the present disclosure;

[0060] Figure 7 A schematic diagram of a code of monitoring processing logic provided by an embodiment of the present disclosure;

[0061] Figure 8 This is an architectural diagram of a mock system for a message encryption interface provided in the second embodiment of the present disclosure;

[0062] Figure 9 This is an architecture diagram of an electronic device provided in Example 3 of the present disclosure. DETAILED DESCRIPTION

[0063] To enable those skilled in the art to better understand the technical solutions of the present disclosure, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments and drawings described herein are only used to explain the present disclosure, rather than to limit the present disclosure.

[0064] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence; and, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be arbitrarily combined with each other.

[0065] The terms used in the embodiments of the present disclosure are for the purpose of describing specific embodiments only and are not intended to limit the present disclosure. The singular forms "a," "an," "the," and "the" used in the embodiments of the present disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.

[0066] In the subsequent description, suffixes such as "module," "component," or "unit" used to represent elements are only used to facilitate the description of the present disclosure and have no specific meaning. Therefore, "module," "component," or "unit" can be used interchangeably.

[0067] When the content of the request body is encrypted, the mock service cannot interpret the distinguishing information from the request body, and thus cannot return a distinguished response message. In this scenario, the tester can only set it to return a fixed response message. Therefore, different testers can only test the request of the same interface at different times (to avoid affecting each other), which reduces the test efficiency.

[0068] In the embodiments of the present disclosure,

[0069] Test application: refers to the application name to which the interface to be mocked belongs, such as kcard-xxx;

[0070] Encryption method: refers to the method used to encrypt the request message before sending the request. The full path of the method needs to be filled in here, such as com.kcard.kcardorder.interceptor.ZopEncryptInterceptor#encrypt, which represents the encryption method encrypt under the class com.kcard.kcardorder.interceptor.ZopEncryptInterceptor;

[0071] Interface URI: refers to the URI of the interface that needs to be mocked, such as / king / card / message / send.

[0072] The following is a detailed description of the technical solution of the present invention and how the technical solution of the present invention solves the above-mentioned problems in the prior art with specific embodiments. It will be understood that in the embodiments of the present application, the execution subject can perform some or all of the steps in the embodiments of the present application, and these steps or operations are only examples. The embodiments of the present application can also perform other operations or variations of various operations. In addition, the various steps can be performed in the different orders presented in the embodiments of the present application, and it is possible that not all operations in the embodiments of the present application need to be performed. Moreover, the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0073] Figure 3 A flowchart of a mock method for a message encryption interface provided in the first embodiment of the present disclosure is shown as follows: Figure 3 As shown, the method includes:

[0074] Step S101: Determine all test applications, encryption methods of test applications, and interface URIs of test applications;

[0075] Step S102: configuring corresponding matching items and carried content for each test application;

[0076] Step S103: establishing an association between the content carried and the response message in the mock service;

[0077] Step S104: before sending the interface request represented by the interface URI of the test application, matching items of the test application are matched. If the match is successful, the carried content is added to the request;

[0078] Step S105: reading the carried content in the request in the mock service, and performing differentiation processing on the response message according to the carried content and the association relationship.

[0079] When the content of the request body is encrypted, the mock service cannot interpret the distinguishing information from the request body, and thus cannot return a distinguished response message. In this scenario, the tester can only set it to return a fixed response message. Therefore, different testers can only test the request of the same interface at different times (to avoid affecting each other), which reduces the test efficiency.

[0080] To solve this problem, the embodiment of the present disclosure establishes an association between carried content and response messages in the mock service by matching corresponding matching items and carried content for each test application. When the request message is encrypted, the corresponding carried content is added to the message through the matching item. The function of the matching item is to add the carried content to the request before the subsequent request is sent when the encryption method is successfully matched. The carried content refers to the content that needs to be added to the request. Therefore, the interface request represented by the interface URI will carry the configured carried content when it is sent. At this time, the mock service can perform differentiated processing by reading the carried content carried in the request (returning different response messages according to different carried content).

[0081] The disclosed embodiment targets an interface with encrypted request messages. By configuring the matching items and carried content corresponding to the test application, the mock service can perform differentiated processing by reading the content carried in the request. This enables the mock service to distinguish different requests and return corresponding response messages, solving the problem that different testers can only test requests for the same interface at separate times, thereby improving test efficiency.

[0082] Furthermore, the method further comprises:

[0083] Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

[0084] like Figure 4 and Figure 5 As shown, the embodiment of the present disclosure configures the test application adding page and the test application display page. After filling in the corresponding content on the adding page, it will be automatically added to the display page. This method can be implemented through the corresponding software program. The tester can Figure 4 Add a new configuration on the Add page shown. You need to fill in the application, encryption method, and interface uri. After filling in, click the Add button. After clicking the Add button, you will jump to Figure 5The display page is shown, all configurations are displayed in the page; for the newly added configuration, the state is set to off by default, the tester can click the start button to set the state to start; before starting, the tester should click the edit button to further edit the configuration; after clicking the edit button, it will jump to Figure 6 The page is shown, in the page, the tester needs to configure two items, which are matching items and carrying content. Thus, the corresponding matching items and carrying content are configured for each test request.

[0085] Further,

[0086] The corresponding matching items for each test application are configured, including:

[0087] The corresponding preset parameter value of the specified position of the encryption method of each test application is set;

[0088] The matching of the matching items of the test application includes:

[0089] The value of the parameter of the specified position of the current encryption method is obtained, and it is judged whether the value is the configured preset parameter value;

[0090] If yes, the matching is successful.

[0091] When configuring the matching item, the matching item information of the encryption method can be configured by setting the corresponding preset parameter value of the specified position. When encrypting, all matching item information of the encryption method is read, the value of the parameter of the specified position of the encryption method (such as the value of the parameter of the position 1) is obtained, and it is judged whether the value contains the configured matching value (such as 18600000001). Determine whether to match; when the values of the parameters of the specified positions of the encryption method are all matched successfully, the carrying content will be added to the request before the subsequent request is sent. The specified position and the preset parameter value can be set to multiple, and only when all the information is matched, it is determined to be matched successfully.

[0092] Further, the method further includes:

[0093] It is judged whether the application of the current configuration in the display page has been mounted to listen;

[0094] If it has been mounted to listen, the state of the current configuration is modified to start;

[0095] If it has not been mounted to listen, the application is mounted to listen first, and after the mounting is successful, the mounting identifier of the application is saved in the redis;

[0096] It is judged whether the application of the current configuration in the display page has been mounted to listen, including:

[0097] Try to read the application's mount flag stored in Redis. If the value is read, it means that the application has been mounted and listened.

[0098] exist Figure 4 After clicking the Add button on the page shown, a new request will be triggered to Service A (the service provided by this disclosure). Service A will save the newly added configuration information to Redis and save the value of the Status field as Closed. Figure 5 When the tester clicks the start button, a query request is sent to service A. Service A reads all the configuration information stored in Redis and returns it to the page for display. When the tester clicks the start button, a start request is sent to service A. After receiving the request, service A executes the following logic:

[0099] 1. Determine whether the currently configured application has been mounted and monitored. If so, proceed to step 3. Otherwise, proceed to step 2. The determination method is to try to read the application's mount identifier stored in Redis (such as get monitor:kcard-xxx). If the value can be read, it means that the application has been mounted and monitored.

[0100] 2. If the monitor is not mounted, then mount the monitor for the application first. After the mount is successful, save the mount flag of the application in redis (such as set monitor:kcard-xxx 1). The mount is executed by remote command, the command is: . / sandbox.sh-p 8-d′service-monitor / loadMonit', where 8 is the application process, which is obtained by executing the command ps-ef|grep-i kcard-xxx|awk'{print$2}' (for example, the current application is kcard-xxx); sandbox.sh is the mount monitor command execution script of the jvm-sandbox installed in advance on the server where the application is located; jvm-sandbox is a jvm-based process monitoring tool that can monitor the java process (i.e., the application process) in the jvm. Similar tools include trace, arthas, etc. Therefore, if you do not use jvm-sandbox, you can also use other monitoring tools to achieve the purpose; service-monitor / loadMonit is the name of the monitoring logic implementation package provided by the present invention.

[0101] 3. Change the status of the current configuration to enabled (modify the information in redis).

[0102] By mounting a listener, you can monitor the process accordingly when executing request encryption or request, match the matching items, and add the carried content to the request after matching.

[0103] Furthermore, the matching items of the test application are matched, and if the match is successful, the carried content is added to the request, including:

[0104] S1: Monitor all methods in the application, including encryption methods and request methods. When a method is called, execute steps S2 and S7 before executing it.

[0105] S2: Determine whether the current method is an encryption method in the display page. If so, execute S3;

[0106] S3: Determine whether the status is on, if so, execute S4;

[0107] S4: Determine whether the matching item and the carried content in the configuration information of the encryption method are both not empty. If so, execute S5;

[0108] S5: Set a global variable flag with an initial value of true. Then read all matching information of the current encryption method, traverse each line of information, and execute the following logic for each line of information: obtain the value of the parameter at the specified position of the current encryption method, and determine whether the value contains the configured matching value. If not, set the flag to false and end the traversal. If the flag value is still true after all traversals are completed, execute S6.

[0109] S6: Read the content information configured by the current encryption method, combine the content information into a JSON string, and then save the combined JSON string into a preset thread variable;

[0110] S7: Determine whether the current method is an interface request method. If yes, execute S8;

[0111] S8: Determine whether the URI of the current request method is an interface URI in the display page. If so, try to read the content from the pre-collected thread variable. If it can be read, execute S9;

[0112] S9: Use mockData as the request header key and the read json string as the request header value to form a new request header item and add it to the request header.

[0113] The monitoring logic implementation package of this disclosure implements logic such as S1-S9;

[0114] In S5, a global variable flag is set with an initial value of true, and then all matching information of the current encryption method is read. Each line of information is traversed, and the following logic is executed for each line of information: the value of the parameter at the specified position of the current encryption method (such as the value of the parameter at position 1) is obtained, and it is determined whether the value contains the configured matching value (such as 18600000001). If not, the flag is set to false and the traversal ends. If the flag value is still true after all traversals are completed, it means that all information can be matched successfully, and S6 is executed.

[0115] In S6, the content information configured by the current encryption method is read and combined into a JSON string (such as {"phone":"18600000001","type":"01"}). The combined JSON string is then saved to the thread variable threadLocal (the code is threadLocal.set('{"phone":"18600000001","type":"01"}′)). Here, threadLocal is a global static variable of type ThreadLocal, which is used to store some data (such as the JSON string here) during the thread execution process. The saved data can be read at any time during the subsequent execution of the thread, and can only be read by the thread, not by other threads.

[0116] When S7 determines whether the current method is an interface request method, it can determine whether the current method is javax.servlet.http.HttpServlet#service. Here is an explanation: theoretically, all encapsulated methods of sending http requests use javax.servlet.http.HttpServlet#service to send requests at the bottom layer, so as long as this method is monitored, some operations on the interface request can be implemented (that is, the logic to be described later);

[0117] Determine whether the URI of the current request (get the URI from the httpServletRequest object passed in the service method) is Figure 5 If the interface URI in the page is the same, try to read the content from the thread variable. If it can be read, execute S9. Here is an explanation: if the content can be read, it means that the thread must have executed the encryption method before executing the request and triggered the saving of the json string in the previous S6.

[0118] Use mockData as the request header key and the read json string as the request header value to form a new request header item and add it to the request header (add the request header to the httpServletRequest object passed as a parameter in the service method);

[0119] In one implementation of the disclosed embodiment, a container with jvm-sandbox installed is deployed in the instance of the tested application, and the container will share the jvm-sandbox with the tested application. Figure 7 As shown in the figure, by monitoring the parameterless function getDayOfMonth, the monitoring processing logic is implemented in the monitoring event.

[0120] The disclosed embodiment is directed to an interface for request message encryption. By configuring the matching items and carried content corresponding to the test application, when encryption is performed, if the values ​​of the parameters at the specified positions of the encryption method are successfully matched, the carried content will be added to the request before the subsequent request is sent. The mock service can perform differentiated processing by reading the content carried in the request. This enables the mock service to distinguish different requests and return corresponding response messages, thereby resolving the problem that different testers can only test requests of the same interface at separate times, thereby improving test efficiency.

[0121] The second embodiment of the present disclosure provides a mock system for a message encryption interface, such as Figure 8 As shown, the system includes:

[0122] A determination module 11 is configured to determine all test applications, encryption methods of the test applications, and interface URIs of the test applications;

[0123] A configuration module 12 configured to configure corresponding matching items and carried content for each test application;

[0124] An association module 13 is configured to establish an association relationship between the content carried and the response message in the mock service;

[0125] A matching module 14 is configured to match the interface request represented by the interface URI of the test application with the matching items of the test application before sending it, and if the match is successful, add the carried content to the request;

[0126] The processing module 15 is configured to read the carried content in the request in the mock service, and perform distinguishing processing on the response message according to the carried content and the association relationship.

[0127] Furthermore, the determining module 11 is further configured to:

[0128] Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

[0129] Further,

[0130] The configuration module 12 is specifically configured as follows:

[0131] Set the corresponding preset parameter values ​​at the designated locations of the encryption methods for each test application;

[0132] The matching module is specifically configured as follows:

[0133] Get the value of the parameter at the specified position of the current encryption method, and determine whether the value is the configured preset parameter value;

[0134] If so, the match is successful.

[0135] Furthermore, the system further includes a monitoring module 16, and the monitoring module 16 is configured as follows;

[0136] Determine whether the currently configured application on the display page has been mounted and monitored;

[0137] If the monitor is already mounted, change the current configuration status to enabled;

[0138] If the monitor is not mounted, first mount the monitor for the application. After the mount is successful, save the mount ID of the application in redis.

[0139] Determining whether the currently configured application on the display page has been mounted and monitored includes:

[0140] Try to read the application's mount flag stored in Redis. If the value is read, it means that the application has been mounted and listened.

[0141] Furthermore, the matching module 14 is specifically configured to match the matching items of the test application by the following method, and if the match is successful, the carried content is added to the request:

[0142] S1: All methods in the application are monitored by the monitoring module 16, including encryption methods and request methods. When a method is called, steps S2 and S7 are executed before it is executed.

[0143] S2: Determine whether the current method is an encryption method in the display page. If so, execute S3;

[0144] S3: Determine whether the status is on, if so, execute S4;

[0145] S4: Determine whether the matching item and the carried content in the configuration information of the encryption method are both not empty. If so, execute S5;

[0146] S5: Set a global variable flag with an initial value of true. Then read all matching information of the current encryption method, traverse each line of information, and execute the following logic for each line of information: obtain the value of the parameter at the specified position of the current encryption method, and determine whether the value contains the configured matching value. If not, set the flag to false and end the traversal. If the flag value is still true after all traversals are completed, execute S6.

[0147] S6: Read the content information configured by the current encryption method, combine the content information into a JSON string, and then save the combined JSON string into a preset thread variable;

[0148] S7: Determine whether the current method is an interface request method. If yes, execute S8;

[0149] S8: Determine whether the URI of the current request method is an interface URI in the display page. If so, try to read the content from the pre-collected thread variable. If it can be read, execute S9;

[0150] S9: Use mockData as the request header key and the read json string as the request header value to form a new request header item and add it to the request header.

[0151] The mock system of the message encryption interface in the embodiment of the present disclosure is used to implement the mock method of the message encryption interface in the first method embodiment, so the description is relatively simple. For details, please refer to the relevant description in the previous method embodiment, which will not be repeated here.

[0152] In addition, if Figure 9 As shown, the third embodiment of the present disclosure further provides an electronic device, including a memory 100 and a processor 200, wherein the memory 100 stores a computer program. When the processor 200 runs the computer program stored in the memory 100, the processor 200 executes the above-mentioned various possible methods.

[0153] The memory 100 is connected to the processor 200 . The memory 100 may be a flash memory, a read-only memory, or other memory. The processor 200 may be a central processing unit or a single-chip microcomputer.

[0154] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and the computer program is used by a processor to execute the above-mentioned various possible methods.

[0155] The computer-readable storage medium includes volatile or nonvolatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), Digital Versatile Disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.

[0156] It is understood that the above embodiments are merely exemplary embodiments for illustrating the principles of the present disclosure, and the present disclosure is not limited thereto. Those skilled in the art may make various modifications and improvements without departing from the spirit and substance of the present disclosure, and such modifications and improvements are also considered to be within the scope of protection of the present disclosure.

Claims

1. A mock method for a message encryption interface, characterized in that: The method comprises: Determine all test applications, their encryption methods, and their interface uniform resource identifiers (URIs). Configure the corresponding matching items and carried content for each test application; Establish an association between the content and response message in the mock service; Before sending the interface request represented by the interface URI of the test application, the matching items of the test application are matched. If the match is successful, the carried content is added to the request; The content carried in the request is read in the mock service, and the response message is distinguished and processed according to the content carried and the association relationship.

2. The method according to claim 1, characterized in that The method further comprises: Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

3. The method according to claim 1, characterized in that Configuring the corresponding matching items for each test application includes: Set the corresponding preset parameter values ​​at the designated locations of the encryption methods for each test application; Matching the matching items of the test application includes: Get the value of the parameter at the specified position of the current encryption method, and determine whether the value is the configured preset parameter value; If so, the match is successful.

4. The method according to claim 2, characterized in that The delivery methods also include: Determine whether the currently configured application on the display page has been mounted and monitored; If the monitor is already mounted, change the current configuration status to enabled; If the monitor is not mounted, the application will be mounted first. After the mount is successful, the mount ID of the application will be saved in the remote dictionary service redis. Determining whether the currently configured application on the display page has been mounted and monitored includes: Try to read the application's mount flag stored in Redis. If the value is read, it means that the application has been mounted and listened.

5. The method according to claim 4, characterized in that The matching items of the test application are matched. If the match is successful, the carried content is added to the request, including: S1: Monitor all methods in the application, including encryption methods and request methods. When a method is called, execute steps S2 and S7 before executing it. S2: Determine whether the current method is an encryption method in the display page. If so, execute S3; S3: Determine whether the status is on, if so, execute S4; S4: Determine whether the matching item and the carried content in the configuration information of the encryption method are both not empty. If so, execute S5; S5: Set a global variable flag with an initial value of true. Then read all matching information of the current encryption method, traverse each line of information, and execute the following logic for each line of information: obtain the value of the parameter at the specified position of the current encryption method, and determine whether the value contains the configured matching value. If not, set the flag to false and end the traversal. If the flag value is still true after all traversals are completed, execute S6. S6: Read the content information configured by the current encryption method, combine the content information into a JSON string, and then save the combined JSON string into a preset thread variable; S7: Determine whether the current method is an interface request method. If yes, execute S8; S8: Determine whether the URI of the current request method is an interface URI in the display page. If so, try to read the content from the pre-collected thread variable. If it can be read, execute S9; S9: Use mockData as the request header key and the read json string as the request header value to form a new request header item and add it to the request header.

6. A mock system for a message encryption interface, characterized in that: The system comprises: A determination module configured to determine all test applications, encryption methods of the test applications, and interface URIs of the test applications; A configuration module configured to configure corresponding matching items and carried content for each test application; The association module is configured to establish an association between the content and the response message in the mock service; A matching module is configured to match the matching items of the test application before sending the interface request represented by the interface URI of the test application. If the match is successful, the carried content is added to the request; The processing module is configured to read the carried content in the request in the mock service, and perform distinguishing processing on the response message according to the carried content and the association relationship.

7. The system according to claim 6, characterized in that The determining module is further configured to: Configure the test application add page and the test application display page. Enter the test application, encryption method, and interface URI on the add page to display all test applications and their corresponding encryption methods and interface URIs on the display page.

8. The system according to claim 6, wherein: The configuration module is specifically configured as follows: Set the corresponding preset parameter values ​​at the designated locations of the encryption methods for each test application; The matching module is specifically configured as follows: Get the value of the parameter at the specified position of the current encryption method, and determine whether the value is the configured preset parameter value; If so, the match is successful.

9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program stored in the memory, the processor executes the mock method of the message encryption interface according to any one of claims 1 to 5.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the mock method of the message encryption interface according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • MOCK test method and device, computer equipment and storage medium

    CN110489322A

  • Processing method and device of mock test message

    CN114826623A