Mock method and system for message encryption interface, electronic equipment and medium
By configuring the matching items and carrying content of the test application, the problem of indistinguishability of the encrypted request body is solved, and the distinction processing of the encrypted request body in the mock service and the return of response packets is realized, which improves the testing efficiency.
Patent Information
- Application Number
- CN202411732132.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-11-28
AI Technical Summary
In the prior art, when the content of the request body is encrypted, the mock service cannot interpret the information that can be distinguished from the request body, thereby unable to return the differentiated response message, resulting in low testing efficiency.
By configuring the matching and carrying content of the test application, an association relationship between carrying content and response packets is established in the mock service. For the encrypted request body, the carrying content is added to the request after the matching is successful, so that the mock service can distinguish processing.
It realizes the distinction processing of the encrypted request body in the mock service, returns the corresponding response message, and solves the problem that different testers can only test at separate times for request tests on the same interface, thereby improving testing efficiency.
Smart Images

Figure CN119544484A_ABST
Abstract
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 usually means changing the request address of the interface in some way so that when the interface is requested (when sending an http request), it will be requested to the specified service (i.e., the mock service) instead of the original service. For interface requests initiated from the client (such as a browser), the request address can be modified through a proxy tool (such as fiddler); for interface requests within a service, if you want to change the request address, developers usually need to do some processing at the code level to achieve it. For example, when starting a service in a test environment, the address of the mock service will be read from the configuration (such as the Apollo configuration platform) to replace the original real address of the interface (i.e., the address of the formal environment), thereby implementing the mock of the interface in the test environment. For interface requests within a service, no matter which method is used to implement the mock of the interface, the interface request will eventually be requested to the mock service, which will receive the request, respond to the request, and return the specified response message to the caller.
[0003] Generally speaking, the mock service needs to distinguish the content of the response to be returned based on the content of the request, so that different testers can get the response content they want when they make 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). But 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, in general, 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 is encrypted before the interface request is sent and becomes a ciphertext (such as Figure 2 ). For this scenario, the tester 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 mutual influence), which leads to low 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 for differentiation from the request body, and thus cannot realize the return of the differentiated response message. The present disclosure provides a mock method of a message encryption interface, a mock system of 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 the 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 the test 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, encryption methods of test applications, and interface URIs (Uniform Resource Identifiers) of test applications;
[0008] Configure the corresponding matching items and carrying contents for each test application;
[0009] Establish an association between the content and the 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 adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying page.
[0014] Furthermore,
[0015] Configuring the corresponding matching items for each test application includes:
[0016] Set the corresponding preset parameter value at the designated position of the encryption method of each test application;
[0017] The matching of the matching items of the test application includes:
[0018] Obtain 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 yes, the match is successful.
[0020] Furthermore, the sending method also includes:
[0021] Determine whether the currently configured application in 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 monitor is not mounted, the application is mounted first. After the mount is successful, the mount identifier of the application is saved in redis (RemoteDictionary Server, remote dictionary service);
[0024] The step of determining whether the currently configured application in the display page has been mounted and monitored includes:
[0025] Try to read the mount flag of the application saved in redis. If the value can be 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, before it is executed, steps S2 and S7 are executed first;
[0028] S2: Determine whether the current method is an encryption method in the display page. If yes, execute S3;
[0029] S3: Determine whether the status is on, if yes, 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, and if so, execute S5;
[0031] S5: Set a global variable flag, initialize the value to 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 flag to false and end the traversal; if the value of flag 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 of the request.
[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, which is configured to configure corresponding matching items and carrying contents for each test application;
[0039] An association module is configured to establish an association relationship between the content carried 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, and if the match is successful, add the carried content 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 determination module is further configured to:
[0043] Configure the test application adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying page.
[0044] Furthermore,
[0045] The configuration module is specifically configured as follows:
[0046] Set the corresponding preset parameter value at the designated position of the encryption method of each test application;
[0047] The matching module is specifically configured as follows:
[0048] Obtain 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 yes, the match is successful.
[0050] In a third aspect, the present disclosure provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor runs the computer program stored in the memory, the processor executes a mock method of a 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, and 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 above is implemented.
[0052] Beneficial effects:
[0053] The present invention 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 distinguishing processing by reading the content carried in the request; different requests can be distinguished in the mock service to return corresponding response messages, thereby solving the problem that different testers can only test requests for the same interface at separate times, thereby improving test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 This is a schematic diagram of requesting a mock service with a request body containing plain text content.
[0055] Figure 2 This is a schematic diagram of the request body being encrypted and converted into ciphertext to request the mock service;
[0056] Figure 3 A flowchart 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 page for a test application configured according to 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 a content carrying configuration page provided in an embodiment of the present disclosure;
[0060] Figure 7 A schematic diagram of a code of a monitoring processing logic provided by an embodiment of the present disclosure;
[0061] Figure 8 An architectural diagram of a mock system for a message encryption interface provided in Embodiment 2 of the present disclosure;
[0062] Fig. 9 This is an architecture diagram of an electronic device provided in Embodiment 3 of the present disclosure. DETAILED DESCRIPTION
[0063] In order to enable those skilled in the art to better understand the technical solution of the present disclosure, the present disclosure is further described in detail below in conjunction with the drawings and embodiments. It should be understood that the specific embodiments and drawings described herein are only used to explain the present invention, rather than to limit the present invention.
[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 in the present disclosure and the features in the embodiments can be arbitrarily combined with each other.
[0065] The terms used in the embodiments of the present disclosure are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. The singular forms of "a", "said" and "the" used in the embodiments of the present disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings.
[0066] In the subsequent description, the 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 meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.
[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 the distinguished response message. For 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 mutual influence), and the test efficiency is relatively low.
[0068] In the disclosed embodiment,
[0069] Test application: refers to the name of the application to which the interface to be mocked belongs, such as kcard-xxx;
[0070] Encryption method: refers to the method of encrypting the request message before sending the request. Here you need to fill in the full path of the method, such as com.kcard.kcardorder.interceptor.ZopEncryptInterceptor#encrypt, which means 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 technical solution of the present invention and how the technical solution of the present invention solves the above-mentioned problems existing in the prior art are described in detail below with specific embodiments. It is understandable 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 deformations of various operations. In addition, each step can be performed in a different order presented in the embodiments of the present application, and it is possible not to perform all the operations in the embodiments of the present application. And, the following several 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 the test applications and interface URIs of the test applications;
[0075] Step S102: configuring the corresponding matching items and carried contents for each test application;
[0076] Step S103: establishing an association relationship 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, and 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 distinguishing and processing 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 the distinguished response message. For 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 mutual influence), and the test efficiency is relatively low.
[0080] To solve this problem, the embodiment of the present disclosure establishes an association between the carried content and the response message in the mock service by matching the 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 items. The function of the matching items is that when the encryption method is successfully matched, the carried content will be added to the request before the subsequent request is sent; the carried content refers to the content that needs to be added to the request; thus, the interface request represented by the interface URI will carry the configured carried content when it is sent, and the mock service can then 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 is directed to an interface for encrypting request messages. By configuring matching items and carried content corresponding to the test application, the mock service can perform differentiation 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 for the same interface at separate times, thereby improving test efficiency.
[0082] Furthermore, the method further comprises:
[0083] Configure the test application adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying 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 the corresponding content is filled in 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 shown in the figure shows all the configurations. For newly added configurations, the status is set to off by default. Testers can click the on button to turn it on. Before turning it on, testers should click the edit button to further edit the configuration. After clicking the edit button, you will be redirected to Figure 6 In the page shown, the tester needs to configure two items, namely, matching items and carried content. Thus, the corresponding matching items and carried content are configured for each test request.
[0085] Furthermore,
[0086] Configuring the corresponding matching items for each test application includes:
[0087] Set the corresponding preset parameter value at the designated position of the encryption method of each test application;
[0088] The matching of the matching items of the test application includes:
[0089] Obtain 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;
[0090] If yes, the match is successful.
[0091] When configuring the matching items, you can configure it by setting the matching item information of the encryption method, and by setting the corresponding preset parameter value at the specified position. When encrypting, read all the matching item information of the encryption method, obtain the value of the parameter at the specified position of the encryption method (such as the value of the parameter at position 1), and determine whether the value contains the configured matching value (such as 18600000001) to determine whether it matches; when the values of the parameters at the specified position of the encryption method are successfully matched, the carried content will be added to the request before the subsequent request is sent. Both the specified position and the preset parameter value can be set to multiple, and the match is determined to be successful only when all the information matches.
[0092] Furthermore, the sending method also includes:
[0093] Determine whether the currently configured application in the display page has been mounted and monitored;
[0094] If the monitor is already mounted, change the current configuration status to enabled;
[0095] If the monitor is not mounted, mount the monitor for the application first. After the mount is successful, save the mount mark of the application in redis;
[0096] The step of determining whether the currently configured application in the display page has been mounted and monitored includes:
[0097] Try to read the mount flag of the application saved in redis. If the value can be 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 triggered to service A. Service A reads all the configuration information saved in redis and returns it to the page for display. When the tester clicks the start button, a start request is triggered 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 it has been mounted and monitored, then proceed to step 3, otherwise proceed to step 2. The judgment method is to try to read the mount flag of the application saved 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 the application is mounted and monitored first. After the mount is successful, the mount flag of the application is saved 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 process of the application, 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 jvm-sandbox is not used, other monitoring tools can also be used to achieve the purpose; service-monitor / loadMonit is the name of the monitoring logic implementation package provided by the present disclosure.
[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, before it is executed, steps S2 and S7 are executed first;
[0105] S2: Determine whether the current method is an encryption method in the display page. If yes, execute S3;
[0106] S3: Determine whether the status is on, if yes, 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, and if so, execute S5;
[0108] S5: Set a global variable flag, initialize the value to 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 flag to false and end the traversal; if the value of flag 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 of the request.
[0113] The monitoring logic implementation package of the present 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 is obtained (such as the value of the parameter at position 1), 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 value of the flag is still true after all traversals are completed, it means that all information can be matched successfully, and S6 is executed;
[0115] In S6, by reading the content information configured by the current encryption method, the content information is combined into a json string (such as {"phone":"18600000001","type":"01"}), and then the combined json string is saved to the thread variable threadLocal (the code is threadLocal.set('{"phone":"18600000001","type":"01"}′)). Here, threadLocal is a global static variable of ThreadLocal type, which is used to save 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 for 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 (the uri obtained 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 of the request (add the request header to the httpServletRequest object passed 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 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 later.
[0120] The disclosed embodiment is directed to an interface for request message encryption, by configuring matching items and carried content corresponding to a test application; when encryption is performed, when the values of the parameters at the specified positions of the encryption method are successfully matched, the carried content is added to the request before subsequent requests are sent; the mock service can perform distinguishing processing by reading the content carried in the request; different requests can be distinguished in the mock service to return corresponding response messages, thereby solving the problem that different testers can only test requests for the same interface at separate times, thereby improving test efficiency.
[0121] Embodiment 2 of the present disclosure provides a mock system for a message encryption interface, such as Figure 8 As shown, the system comprises:
[0122] A determination module 11, which 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, which is configured to configure the corresponding matching items and carried contents for each test application;
[0124] An association module 13, which 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 matching items of the test application before sending the interface request represented by the interface uri of the test application, 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 adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying page.
[0129] Furthermore,
[0130] The configuration module 12 is specifically configured as follows:
[0131] Set the corresponding preset parameter value at the designated position of the encryption method of each test application;
[0132] The matching module is specifically configured as follows:
[0133] Obtain 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 yes, the match is successful.
[0135] Furthermore, the system further comprises a monitoring module 16, wherein the monitoring module 16 is configured as follows;
[0136] Determine whether the currently configured application in 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, mount the monitor for the application first. After the mount is successful, save the mount mark of the application in redis;
[0139] The step of determining whether the currently configured application in the display page has been mounted and monitored includes:
[0140] Try to read the mount flag of the application saved in redis. If the value can be 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 the method is executed.
[0143] S2: Determine whether the current method is an encryption method in the display page. If yes, execute S3;
[0144] S3: Determine whether the status is on, if yes, 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, and if so, execute S5;
[0146] S5: Set a global variable flag, initialize the value to 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 flag to false and end the traversal; if the value of flag 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 of the request.
[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 Fig. 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, and 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, and 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 executed by a processor to perform the above-mentioned various possible methods.
[0155] The computer-readable storage medium includes volatile or non-volatile, 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 Video Disc (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, 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 to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present disclosure, but the present disclosure is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and substance of the present disclosure, and these 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, encryption methods of test applications and interface uniform resource identifiers (URIs) of test applications; Configure the corresponding matching items and carrying contents for each test application; Establish an association between the content and the 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 adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying 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 value at the designated position of the encryption method of each test application; The matching of the matching items of the test application includes: Obtain 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 yes, 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 in 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 is mounted first. After the mount is successful, the mount mark of the application is saved in the remote dictionary service redis; The step of determining whether the currently configured application in the display page has been mounted and monitored includes: Try to read the mount flag of the application saved in redis. If the value can be 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, and 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, before it is executed, steps S2 and S7 are executed first; S2: Determine whether the current method is an encryption method in the display page. If yes, execute S3; S3: Determine whether the status is on, if yes, execute S4; S4: Determine whether the matching item and the carried content in the configuration information of the encryption method are both not empty, and if so, execute S5; S5: Set a global variable flag, initialize the value to 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 flag to false and end the traversal; if the value of flag 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 of the request.
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, which is configured to configure corresponding matching items and carrying contents for each test application; An association module is configured to establish an association relationship between the content carried 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, and if the match is successful, add the carried content 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 determination module is further configured to: Configure the test application adding page and the test application displaying page, and fill in the test application, encryption method, and interface URI in the adding page to display all the test applications and their corresponding encryption methods and interface URIs in the displaying page.
8. The system according to claim 6, characterized in that The configuration module is specifically configured as follows: Set the corresponding preset parameter value at the designated position of the encryption method of each test application; The matching module is specifically configured as follows: Obtain 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 yes, 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, and when the computer program is executed by a processor, the mock method of the message encryption interface according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
MOCK test method and device, computer equipment and storage medium
CN110489322A
Case test method and device, electronic equipment and storage medium
CN113176993A
Processing method and device of mock test message
CN114826623A
Coerced encryption on connected devices
US20150040235A1