|
28 | 28 |
|
29 | 29 | import com.denimgroup.threadfix.data.entities.RouteParameter; |
30 | 30 | import com.denimgroup.threadfix.data.entities.RouteParameterType; |
| 31 | +import com.denimgroup.threadfix.data.entities.WildcardEndpointPathNode; |
31 | 32 | import com.denimgroup.threadfix.data.enums.FrameworkType; |
32 | 33 | import com.denimgroup.threadfix.data.interfaces.Endpoint; |
| 34 | +import com.denimgroup.threadfix.data.interfaces.EndpointPathNode; |
33 | 35 | import com.denimgroup.threadfix.framework.engine.framework.FrameworkCalculator; |
34 | 36 | import com.denimgroup.threadfix.framework.engine.full.EndpointDatabase; |
35 | 37 | import com.denimgroup.threadfix.framework.engine.full.EndpointDatabaseFactory; |
|
46 | 48 | import org.codehaus.jackson.map.ObjectMapper; |
47 | 49 |
|
48 | 50 | import java.io.File; |
| 51 | +import java.io.FileNotFoundException; |
49 | 52 | import java.io.IOException; |
| 53 | +import java.net.UnknownHostException; |
50 | 54 | import java.util.Collection; |
51 | 55 | import java.util.List; |
52 | 56 | import java.util.Map; |
@@ -74,6 +78,8 @@ enum Logging { |
74 | 78 | static int totalDetectedEndpoints = 0; |
75 | 79 | static int totalDetectedParameters = 0; |
76 | 80 |
|
| 81 | + static String testUrlPath = null; |
| 82 | + |
77 | 83 | private static void println(String line) { |
78 | 84 | if (printFormat != SIMPLE_JSON && printFormat != FULL_JSON) { |
79 | 85 | System.out.println(line); |
@@ -326,6 +332,9 @@ private static boolean checkArguments(String[] args) { |
326 | 332 | path = path.substring(0, path.length() - 1); |
327 | 333 | } |
328 | 334 | pathListFile = path; |
| 335 | + } else if (arg.startsWith("-validation-server=")) { |
| 336 | + String[] parts = arg.split("="); |
| 337 | + testUrlPath = parts[1]; |
329 | 338 | } else { |
330 | 339 | println("Received unsupported option " + arg + ", valid arguments are -lint, -debug, -simple-json, -json, -path-list-file, and -simple"); |
331 | 340 | return false; |
@@ -446,6 +455,46 @@ private static List<Endpoint> listEndpoints(File rootFile, Collection<FrameworkT |
446 | 455 | println("Failed to validate serialization for at least one of these endpoints"); |
447 | 456 | } |
448 | 457 |
|
| 458 | + if (testUrlPath != null) { |
| 459 | + EndpointTester tester = new EndpointTester(testUrlPath); |
| 460 | + |
| 461 | + println("Testing endpoints against server at: " + testUrlPath); |
| 462 | + |
| 463 | + List<Endpoint> successfulEndpoints = list(); |
| 464 | + List<Endpoint> failedEndpoints = list(); |
| 465 | + List<Endpoint> allEndpoints = EndpointUtil.flattenWithVariants(endpoints); |
| 466 | + for (Endpoint endpoint : allEndpoints) { |
| 467 | + boolean skip = false; |
| 468 | + for (EndpointPathNode node : endpoint.getUrlPathNodes()) { |
| 469 | + if (node.getClass().equals(WildcardEndpointPathNode.class)) { |
| 470 | + skip = true; |
| 471 | + break; |
| 472 | + } |
| 473 | + } |
| 474 | + |
| 475 | + if (skip) { |
| 476 | + continue; |
| 477 | + } |
| 478 | + |
| 479 | + try { |
| 480 | + tester.test(endpoint); |
| 481 | + successfulEndpoints.add(endpoint); |
| 482 | + } catch (FileNotFoundException | UnknownHostException e) { |
| 483 | + failedEndpoints.add(endpoint); |
| 484 | + } catch (IOException e) { |
| 485 | + if (e.getMessage().contains("HTTP")) { |
| 486 | + successfulEndpoints.add(endpoint); |
| 487 | + } |
| 488 | + } |
| 489 | + } |
| 490 | + |
| 491 | + for (Endpoint endpoint : failedEndpoints) { |
| 492 | + println("Failed: " + endpoint.getUrlPath() + "[" + endpoint.getHttpMethod() + "]"); |
| 493 | + } |
| 494 | + |
| 495 | + println(successfulEndpoints.size() + "/" + (successfulEndpoints.size() + failedEndpoints.size()) + " endpoints were queryable"); |
| 496 | + } |
| 497 | + |
449 | 498 | int numMissingStartLine = 0; |
450 | 499 | int numMissingEndLine = 0; |
451 | 500 | int numSameLineRange = 0; |
|
0 commit comments