Regression test case optimization method suitable for Web application firewall

By drawing code dependency graphs and calculating Euclidean distance, the impact of Web application firewall regression test cases is determined, which solves the problem of low regression testing efficiency in rapid iterative development and achieves more efficient test coverage and efficiency improvement.

CN118779211APending Publication Date: 2024-10-15CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410524422.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-29
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

In the rapidly iterative development process of Web Application Firewall (WAF), existing technology is difficult to effectively optimize regression testing, resulting in low testing efficiency. It is necessary to calculate as few necessary test cases as possible to improve the efficiency of regression testing.

Method used

Determine the final regression test case by drawing the code dependency graph, calculating the Euclidean distance and analyzing the degree of impact. The specific steps include parsing the code, determining the dependency relationship, drawing the dependency graph, calculating the Euclidean distance and establishing a similarity matrix to identify the modified code files. According to the scope and degree of impact, the smallest set of regression test cases is selected.

Benefits of technology

It improves test coverage and testing efficiency, and can quickly screen out the smallest set of regression test cases after software updates. Compared with full regression testing, it significantly improves testing efficiency and is flexible and scalable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779211A_ABST
    Figure CN118779211A_ABST
Patent Text Reader

Abstract

The invention discloses a regression test case optimization method suitable for a Web application firewall, belongs to the field of cloud security, and can better identify other code files influenced by a modified code file by drawing a code dependency graph, so that all functions related to software updating can be delimited to be covered, and the overall test coverage rate is improved. The method comprises the following steps: quantifying the class and method times in other file reference change codes, forming a vector by the characteristics to represent each code file, calculating the Euclidean distance of other code files depending on inserted codes, and determining a functional module with a relatively large influence degree; after software is updated and published, the minimum regression test case set which is rapidly screened out is used for testing, and compared with full-quantity regression testing, the testing efficiency can be remarkably improved; the method is not limited to specific types of software or test scenes, adjustment and expansion are carried out according to actual requirements, and good flexibility and expandability are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of cloud security, and in particular relates to a regression test case optimization method suitable for a Web application firewall. Background Art

[0002] With the rapid development of information technology, Web Application Firewall (WAF) has become an important means to ensure website data security and network security. WAF can effectively prevent SQL injection attacks, XSS attacks, information leakage and other network security issues. In agile development or other rapid iteration R&D processes, various WAF testing tasks become particularly important. WAF testing involves many aspects, including functional testing, performance testing, security capability testing, stability testing, etc. Each aspect of testing can be subdivided into many categories. For example, functional testing needs to consider domain name access function testing, protection policy configuration testing, protection log function testing, etc. Performance testing needs to consider QPS performance, throughput performance, performance under different traffic types, etc. Security capability testing needs to consider the detection capabilities of various attack types such as SQLi attack detection, XSS attack detection, and information leakage detection. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a regression test case optimization method suitable for a Web application firewall in view of the shortcomings of the background technology, aiming to calculate as few necessary test cases as possible to improve the efficiency of regression testing in rapid iteration.

[0004] The present invention adopts the following technical solutions to solve the above technical problems:

[0005] A method for optimizing regression test cases for a Web application firewall, specifically comprising the following steps;

[0006] Step 1, draw a code dependency graph;

[0007] Step 2: Euclidean distance calculation to generate the influence range;

[0008] Step 3: Analyze the impact and determine the final use case.

[0009] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, the step 1 specifically includes the following steps:

[0010] Step 1.1, code parsing: Use the parser of the corresponding code language to parse the baseline version code. The parser will perform lexical analysis and grammatical analysis on the code;

[0011] Step 1.2, determine the dependency relationship: determine the dependency relationship between files based on the abstract syntax tree;

[0012] Step 1.3, draw the dependency graph: Based on the abstract syntax tree and the determined dependencies, start drawing the code dependency graph.

[0013] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 1.2, the dependency relationship includes the calling relationship between functions and the reference relationship between variables.

[0014] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, the step 2 specifically includes the following steps:

[0015] Step 2.1, after adding, modifying, or deleting code on the baseline version code, use relevant tools to determine the number and file names of changed files in the project code;

[0016] Step 2.2, according to the code dependency graph, find out other code files that are directly or indirectly dependent on the inserted code file;

[0017] Step 2.3, calculate the Euclidean distance between each dependent file and the inserted code file;

[0018] Step 2.4, sort the calculated Euclidean distances to determine the functional modules with greater influence.

[0019] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, the step 2.3 specifically includes the following steps:

[0020] Step 2.3.1, extract feature vector:

[0021] Step 2.3.2, calculate the Euclidean distance: The calculation formula of the Euclidean distance is as follows: d = √(Σ(xi-yi)^2)

[0022] Among them, xi and yi represent the element values ​​in two feature vectors respectively, and n is the dimension of the feature vector;

[0023] Step 2.3.3, build a similarity matrix.

[0024] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 2.3.1, a feature vector is extracted: for each code file, the number of times the classes and methods in the file are referenced is counted as features, and the features are combined into a vector to represent each code file.

[0025] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 2.3.2, when calculating the Euclidean distance, the dimension and element type of the vector need to remain consistent.

[0026] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 2.3.3, the similarity matrix is ​​obtained by calculating the Euclidean distance between the feature vectors.

[0027] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 3, after determining the code files with a greater impact of this modification, the functional points with a greater impact can be determined according to the code file-function mapping table.

[0028] As a further preferred solution of the present invention applicable to the Web application firewall regression test case optimization method, in step 3, according to the mapping table of code file function-test case, the affected related module test cases can be selected as the final regression test case set.

[0029] Compared with the prior art, the present invention adopts the above technical solution and has the following technical effects:

[0030] 1. The present invention can better identify other code files affected by the modified code file by drawing a code dependency graph, so that all functions related to the software update can be covered, thereby improving the overall test coverage;

[0031] 2. The present invention quantifies the number of times other files reference classes and methods in the changed code, combines these features into a vector to represent each code file, and calculates the Euclidean distance of other code files that depend on the inserted code to determine the functional modules with greater impact;

[0032] 3. After the software update is released, the minimum regression test case set quickly screened by the present invention can be used for testing, which can significantly improve the testing efficiency compared with the full regression test;

[0033] 4. The method of the present invention is not limited to a specific type of software or test scenario. In order to avoid certain features from dominating and affecting the calculation of the Euclidean distance, feature scaling or standardization can be performed. It can be adjusted and expanded according to actual needs, and has good flexibility and scalability. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.

[0035] Figure 1 It is a schematic diagram of the tree structure of test cases for the product of the present invention;

[0036] Figure 2 It is a code function-test case mapping table of the present invention. DETAILED DESCRIPTION

[0037] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings:

[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. The present invention is described in detail below based on the drawings and preferred embodiments, and the purpose and effect of the present invention will become clearer. It should be understood that the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.

[0039] Glossary:

[0040] Provide a definition or brief explanation of the technical keywords in the proposal. Abbreviations need to be given in full in Chinese and English. For the same object being described, please ensure that the terms used in the briefing are consistent.

[0041] Code dependency graph: Draws a graph representing the dependency relationship between code files by analyzing the grammatical structure and symbolic reference relationship of the code.

[0042] Euclidean distance: It is a commonly used similarity measurement method between feature vectors. It can measure the degree of difference between feature vectors by calculating the geometric distance between them.

[0043] In the above context, in order to ensure the quality of WAF products, a large number of test cases will be constructed and prepared. However, in the process of rapid iteration of product development, it is inefficient and unnecessary to execute all test cases completely after updating. Therefore, the present invention proposes a regression test case optimization method suitable for Web application firewalls, which aims to calculate as few necessary test cases as possible to improve the efficiency of regression testing in rapid iteration.

[0044] A regression test case optimization method for a Web application firewall. The method includes the following three main steps:

[0045] Step 1, draw a code dependency graph;

[0046] Step 2: Euclidean distance calculation to generate the influence range;

[0047] Step 3: Analyze the impact and determine the final use case;

[0048] These three steps are explained in detail below.

[0049] Step 1: Draw a code dependency graph:

[0050] Step 1.1, code parsing: Use the parser of the corresponding code language to parse the baseline version code. The parser will perform lexical analysis and grammatical analysis on the code;

[0051] Step 1.2, determine the dependency relationship: The dependency relationship may include the calling relationship between functions and the reference relationship between variables. According to the abstract syntax tree, the dependency relationship between files is determined;

[0052] Step 1.3, draw a dependency graph: Based on the abstract syntax tree and the determined dependencies, you can start drawing a code dependency graph.

[0053] Step 2: Euclidean distance calculation to generate the influence range;

[0054] Step 2.1: After adding, modifying, or deleting code on the baseline version code, the number and file names of the changed files in the project code can be determined through relevant tools;

[0055] Step 2.2, according to the code dependency graph, find out other code files that are directly or indirectly dependent on the inserted code file;

[0056] Step 2.3, calculate the Euclidean distance between each dependent file and the inserted code file

[0057] Step 2.3.1, extract feature vector:

[0058] For each code file, the number of times the classes and methods in the file are referenced is counted as features, and these features are combined into a vector to represent each code file.

[0059] Since the actual number of citations varies greatly, the feature scaling factor can be increased to facilitate later result statistics:

[0060] Step 2.3.2, calculate the Euclidean distance:

[0061] The calculation formula of Euclidean distance is as follows: d = √(Σ(xi-yi)^2)

[0062] Where xi and yi represent the element values ​​in the two feature vectors, respectively, and n is the dimension of the feature vector. When calculating the Euclidean distance, the dimension and element type of the vector must be consistent.

[0063] Step 2.3.3, establish a similarity matrix: By calculating the Euclidean distance between the feature vectors, the following similarity matrix is ​​obtained.

[0064] Step 2.4, sort the calculated Euclidean distances to determine the functional modules with greater influence; generally speaking, the smaller the Euclidean distance, the closer the two vectors are, and the larger the distance, the greater the difference between the two vectors.

[0065] Step 3: Analyze the impact and determine the final use case;

[0066] From the results of step 2, we can know that other code files are affected to varying degrees after the code change. Since each code file corresponds to a related function point, after determining the code file with the greatest impact of this change, the function point with the greatest impact can be determined based on the code file-function mapping table.

[0067] According to the mapping table of code file function-test case, the test cases of the affected related modules can be selected as the final regression test case set.

[0068] Through the above method, the regression test case set can be optimized and the test efficiency can be improved while ensuring the test quality. Through the above method, the regression test case set can be optimized and the test efficiency can be improved while ensuring the test quality.

[0069] Example

[0070] The following is an embodiment of the present invention, which shows how to use the code dependency graph and calculate the Euclidean distance to determine the minimum regression test case set.

[0071] Assume that we have a network security product, and the test case tree structure (TCT) for this product is as follows: Figure 1 .

[0072] The test case tree structure of the product.

[0073] The basic code is as follows:

[0074] example.py

[0075]

[0076] module1.py

[0077]

[0078] module3.py

[0079] def func3():

[0080] print("This is func3 in module3")

[0081] Draw code dependency graph

[0082] Use the parser of the corresponding code language to parse the benchmark version code. The parser will perform lexical analysis and syntax analysis on the code. Use the Python parser to parse example.py and module1.py

[0083] Determine dependencies: Dependencies can include calling relationships between functions and reference relationships between variables. According to the abstract syntax tree, determine the dependency between the example.py file and the module1.py file, that is, the module1.func2() function is called in example.py.

[0084] Draw a dependency graph: Based on the abstract syntax tree and the determined dependencies, you can start drawing a code dependency graph, and you can get the following results:

[0085] example.py-->module1.py-->module3.py

[0086] |

[0087] +---->module2.py

[0088] 2. Euclidean distance calculation to quantify the impact on other files

[0089] After the fixture is updated, the modified code is as follows:

[0090] example.py, as follows:

[0091]

[0092] module1.py is as follows:

[0093]

[0094] module3.py, as follows:

[0095] def func3():

[0096] print("Add fixture,this is func3 in module3")

[0097] Determine the file and related function or method where the inserted code is located:

[0098] According to relevant tools, it can be determined that module1 has a new method func4(), and the main() function in the example.py file introduces the corresponding new method func4() of module1. In addition, the func3() method of module3 referenced by module1 also adds relevant features.

[0099] According to the code dependency graph, find out other code files that directly and indirectly depend on the inserted code. The files that are affected are

[0100]

[0101] 2.3 Calculate the Euclidean distance between each dependency file and the inserted code file

[0102] 2.3.1 Extract feature vectors:

[0103] For each code file, the number of times example.py, module1.py, and module3.py are referenced is counted as features, and these features are combined into a vector to represent each code file.

[0104] Since the actual number of citations varies greatly, in order to facilitate the statistics of the subsequent results, a feature scaling factor: δ is added. Here, the feature scaling factor is: 10.

[0105] The feature vectors are extracted as follows:

[0106] example.py:[10,10,10]

[0107] FileB:[10,0,10]

[0108] FileC:[0,10,20]

[0109] FileD:[0,0,0]

[0110] 2.3.2 Calculate Euclidean distance:

[0111] The calculation formula of Euclidean distance is as follows: d = √(Σ(xi-yi)^2)

[0112] Where xi and yi represent the element values ​​in the two feature vectors, respectively, and n is the dimension of the feature vector. When calculating the Euclidean distance, the dimension and element type of the vector must be consistent.

[0113] Euler distance between example.py and FileB:

[0114] d(example.py,FileB)=sqrt((10-10)^2+(10-0)^2+(10-10)^2)=10

[0115] Euler distance between example.py and FileC:

[0116] d(example.py,FileC)=sqrt((10-0)^2+(10-10)^2+(10-20)^2)=14.142

[0117] Euler distance between example.py and FileD:

[0118] d(example.py,FileD)=sqrt((10-0)^2+(10-0)^2+(10-0)^2)=17.321

[0119] 2.3.3 Establishing Similarity Matrix

[0120] By calculating the Euclidean distance between the feature vectors, the following similarity matrix is ​​obtained as shown in Table 1:

[0121] Table 1

[0122] example.py FileB FileC FileD example.py 0 10 14.142 17.321 FileB 10 0 FileC 14.142 0 FileD 17.321 0

[0123] 2.4 Sort the calculated Euclidean distances and determine the functional modules with greater impact

[0124] Generally speaking, the smaller the Euclidean distance, the closer the two vectors are, and the larger the distance, the greater the difference between the two vectors.

[0125] 3. Analyze the impact and determine the final use case

[0126] From step 2, it can be concluded that due to the introduction of fixture, the codes with the largest impact from largest to smallest are: FileB, FileC, FileD, FileD. Depending on the scenario, some files with smaller impact can be retained or discarded.

[0127] Since each code file corresponds to a related function point, after determining the code file that is most affected by this change, the function point that is most affected can be determined according to the code file-function mapping table.

[0128] Finally, according to the code function-test case mapping table, the test cases of the affected related modules are selected as the regression test case set.

[0129] The code file-function mapping table is shown in Table 2:

[0130] Table 2

[0131] Code file name Corresponding function points example.py New rules FileB RulesEdit FileC Rule Deletion

[0132] Code function-test case mapping table such as Figure 2 shown.

[0133] Based on the code files with greater impact this time, the functional module test cases marked with "!" as above can be selected as the final regression test case set.

[0134] By drawing a code dependency graph, the present invention can better identify other code files affected by the modified code file, so that all functions related to the software update can be covered, thereby improving the overall test coverage;

[0135] The present invention quantifies the number of times other files reference classes and methods in the changed code, combines these features into a vector to represent each code file, and calculates the Euclidean distance of other code files that depend on the inserted code to determine the functional modules with greater impact;

[0136] After the software update is released, the minimum regression test case set quickly screened out by the present invention can be used for testing, which can significantly improve the testing efficiency compared with the full regression test.

[0137] The method of the present invention is not limited to a specific type of software or test scenario. In order to avoid certain features from dominating and affecting the calculation of the Euclidean distance, feature scaling or standardization can be performed. It can be adjusted and expanded according to actual needs, and has good flexibility and scalability.

[0138] Based on the code files with greater impact this time, the functional module test cases marked in red above can be selected as the final regression test case set.

[0139] Those skilled in the art can understand that the above are only preferred examples of the invention and are not intended to limit the invention. Although the invention is described in detail with reference to the above examples, those skilled in the art can still modify the technical solutions recorded in the above examples or replace some of the technical features with equivalents. Any modification, equivalent replacement, etc. made within the spirit and principle of the invention should be included in the protection scope of the invention. All technical features in this embodiment can be freely combined according to actual needs.

[0140] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for optimizing regression test cases for a Web application firewall, characterized by: The specific steps include: Step 1, draw a code dependency graph; Step 2: Euclidean distance calculation to generate the influence range; Step 3: Analyze the impact and determine the final use case.

2. A method for optimizing regression test cases for a Web application firewall according to claim 1, characterized in that: The step 1 specifically comprises the following steps: Step 1.1, code parsing: Use the parser of the corresponding code language to parse the baseline version code. The parser will perform lexical analysis and grammatical analysis on the code; Step 1.2, determine the dependency relationship: determine the dependency relationship between files based on the abstract syntax tree; Step 1.3, draw the dependency graph: Based on the abstract syntax tree and the determined dependencies, start drawing the code dependency graph.

3. A method for optimizing regression test cases for a Web application firewall according to claim 2, characterized in that: In step 1.2, the dependencies include the calling relationships between functions and the reference relationships between variables.

4. The method for optimizing regression test cases for a Web application firewall according to claim 1, characterized in that: The step 2 specifically comprises the following steps: Step 2.1, after adding, modifying, or deleting code on the baseline version code, use relevant tools to determine the number and file names of changed files in the project code; Step 2.2, according to the code dependency graph, find out other code files that are directly or indirectly dependent on the inserted code file; Step 2.3, calculate the Euclidean distance between each dependent file and the inserted code file; Step 2.4, sort the calculated Euclidean distances to determine the functional modules with greater influence.

5. The method for optimizing regression test cases for a Web application firewall according to claim 1, characterized in that: The step 2.3 specifically includes the following steps: Step 2.3.1, extract feature vector: Step 2.3.2, calculate the Euclidean distance: The calculation formula of the Euclidean distance is as follows: d = √(Σ(xi-yi)^2) Among them, xi and yi represent the element values ​​in two feature vectors respectively, and n is the dimension of the feature vector; Step 2.3.3, build a similarity matrix.

6. A method for optimizing regression test cases for a Web application firewall according to claim 5, characterized in that: In step 2.3.1, extract feature vectors: For each code file, count the number of times the classes and methods in the file are referenced as features, and combine the features into a vector to represent each code file.

7. The method for optimizing regression test cases for a Web application firewall according to claim 5, characterized in that: In step 2.3.2, when calculating the Euclidean distance, the dimension and element type of the vector need to be consistent.

8. The method for optimizing regression test cases for a Web application firewall according to claim 5, characterized in that: In step 2.3.3, the similarity matrix is ​​obtained by calculating the Euclidean distance between the feature vectors.

9. The method for optimizing regression test cases for a Web application firewall according to claim 1, characterized in that: In step 3, after the code files that are most affected by this modification are determined, the functional points that are most affected can be determined based on the code file-function mapping table.

10. The method for optimizing regression test cases for a Web application firewall according to claim 9, characterized in that: In step 3, according to the mapping table of code file function-test case, the test cases of the affected related modules can be selected as the final regression test case set.