Method, device, and medium for verifying backend interface
Embodiments of the present disclosure provide a method, device, and medium for verifying a backend interface. The method comprises receiving a request associated with the backend interface. The method further comprising generating a mock response based on the request and a mock rule corresponding to the backend interface, where the mock rule is received through a user interface. The method further comprises obtaining an assertion rule corresponding to the backend interface, where the assertion rule is received through the user interface. In addition, the method further comprises generating a verification result for display based on the mock response and the assertion rule.
1 . A method for verifying a backend interface, comprising:
receiving a request associated with the backend interface;
generating a mock response based on the request and a mock rule corresponding to the backend interface, the mock rule being received through a user interface;
obtaining an assertion rule corresponding to the backend interface, the assertion rule being received through the user interface, wherein the assertion rule comprises a data path indicating a path of data to be verified, a verification rule indicating a verification operation, and an expected value; and
generating a verification result for display based on the mock response and the assertion rule,
wherein generating the verification result for display based on the mock response and the assertion rule comprises:
applying the verification rule to the data to be verified and the expected value; and
determining whether the data to be verified and the expected value satisfy the verification rule.
2 . The method according to claim 1 , further comprises:
pre-loading a plurality of mock rules from a database; and
obtaining the mock rule from the pre-loaded plurality of mock rules.
3 . The method according to claim 1 , wherein the mock rule received through the user interface comprises a mock header and a mock body.
4 . The method according to claim 1 , wherein generating the verification result for display based on the mock response and the assertion rule comprises:
obtaining a plurality of assertion rules corresponding to the backend interface, the plurality of assertion rules being received through the user interface, and the plurality of assertion rules comprising the assertion rule; and
determining that the backend interface is verified in response to all assertion rules pass.
5 . The method according to claim 1 , wherein the assertion rule received through the user interface further comprises at least one of:
a data type indicating whether the data to be verified is a request or a response, or
a data source indicating whether a source of the data to be verified is headers, body, or query parameters.
6 . The method according to claim 1 , further comprising:
displaying, through the user interface, a plurality of backend interfaces and a plurality of verification results corresponding to the plurality of backend interfaces, wherein the plurality of verification results comprises the verification result of the backend interface, and the verification result indicates that a verification of the backend interface is successful or unsuccessful.
7 . The method according to claim 1 , wherein generating the mock response based on the request and the mock rule corresponding to the backend interface comprises:
obtaining a proxy rule corresponding to the backend interface, the proxy rule indicating an actual destination to which the request is sent, and the proxy rule being received through the user interface;
determining that the actual destination is a mock based on the proxy rule; and
generating the mock response based on the request and the mock rule.
8 . The method according to claim 7 , further comprises:
determining that the actual destination is an isolation environment based on the proxy rule;
modifying a path of the backend interface to access the isolation environment;
generating a response from the isolation environment based on the request; and
generating a verification result based on the response and the assertion rule.
9 . The method according to claim 1 , wherein the assertion rule comprises encoded data, and the method further comprises:
obtaining a piece of code for decoding the encoded data in the assertion rule, the piece of code being received through the user interface; and
decoding the encoded data in the assertion rule using the piece of code.
10 . The method according to claim 1 , further comprising:
generating a hash value for rules associated with a verification task based on an identification of a verification step and an identification of the verification task; and
loading the rules associated with the verification task into a part of instances of verification engine; and
performing the verification task on the part of instances of verification engine based on the loaded rules.
11 . The method according to claim 1 , wherein generating the mock response based on the request and the mock rule corresponding to the backend interface comprises:
determining that the request matches the backend interface based on a matching rule, the matching rule being received through a user interface;
obtaining the mock rule corresponding to the backend interface; and
generating the mock response based on the request and the mock rule.
12 . The method according to claim 11 , wherein determining that the request matches the backend interface based on the matching rule comprises:
obtaining a plurality of matching rules, a plurality of assertion rules and a mock rule corresponding to the backend interface, the plurality of matching rules being received through the user interface, and the plurality of matching rules comprising the matching rule; and
determining that the request matches the backend interface in response to any of the plurality of matching rules being satisfied.
13 . An electronic device, comprising:
a memory and a processor;
wherein the memory is configured to store one or more computer instructions which, when executed by the processor, cause the processor to:
receive a request associated with the backend interface;
generate a mock response based on the request and a mock rule corresponding to the backend interface, the mock rule being received through a user interface;
obtain an assertion rule corresponding to the backend interface, the assertion rule being received through the user interface, wherein the assertion rule comprises a data path indicating a path of data to be verified, a verification rule indicating a verification operation, and an expected value; and
generate a verification result for display based on the mock response and the assertion rule,
wherein the instructions causing the processor to generate the verification result for display based on the mock response and the assertion rule comprise instructions causing the processor to:
apply the verification rule to the data to be verified and the expected value; and
determine whether the data to be verified and the expected value satisfy the verification rule.
14 . The device according to claim 13 , the instructions further causing the processor to:
pre-load a plurality of mock rules from a database; and
obtain the mock rule from the pre-loaded plurality of mock rules.
15 . The device according to claim 13 , wherein the mock rule received through the user interface comprises a mock header and a mock body.
16 . The device according to claim 13 , wherein the instructions causing the processor to generate the verification result for display based on the mock response and the assertion rule comprise instructions causing the processor to:
obtain a plurality of assertion rules corresponding to the backend interface, the plurality of assertion rules being received through the user interface, and the plurality of assertion rules comprising the assertion rule; and
determine that the backend interface is verified in response to all assertion rules pass.
17 . The device according to claim 13 , wherein the assertion rule received through the user interface further comprises at least one of:
a data type indicating whether the data to be verified is a request or a response, or
a data source indicating whether a source of the data to be verified is headers, body, or query parameters.
18 . The device according to claim 13 , the instructions further causing the processor to:
display, through the user interface, a plurality of backend interfaces and a plurality of verification results corresponding to the plurality of backend interfaces, wherein the plurality of verification results comprises the verification result of the backend interface, and the verification result indicates that a verification of the backend interface is successful or unsuccessful.
19 . The device according to claim 13 , wherein the instructions causing the processor to generate the mock response based on the request and the mock rule corresponding to the backend interface comprise instructions causing the processor to:
obtain a proxy rule corresponding to the backend interface, the proxy rule indicating an actual destination to which the request is sent, and the proxy rule being received through the user interface;
determine that the actual destination is a mock based on the proxy rule; and
generate the mock response based on the request and the mock rule.
20 . A non-transitory computer-readable medium comprising instructions stored thereon which, when executed by a processor, cause the processor to:
receive a request associated with the backend interface;
generate a mock response based on the request and a mock rule corresponding to the backend interface, the mock rule being received through a user interface;
obtain an assertion rule corresponding to the backend interface, the assertion rule being received through the user interface, wherein the assertion rule comprises a data path indicating a path of data to be verified, a verification rule indicating a verification operation, and an expected value; and
generate a verification result for display based on the mock response and the assertion rule,
wherein the instructions causing the processor to generate the verification result for display based on the mock response and the assertion rule comprise instructions causing the processor to:
apply the verification rule to the data to be verified and the expected value; and
determine whether the data to be verified and the expected value satisfy the verification rule.