■ ■ ■ ■ ■ ■
main/src/test/java/com/google/tsunami/main/cli/TsunamiCliTest.java
| skipped 37 lines |
38 | 38 | | import com.google.tsunami.plugin.testing.FakeVulnDetector2; |
39 | 39 | | import com.google.tsunami.plugin.testing.FakeVulnDetectorBootstrapModule; |
40 | 40 | | import com.google.tsunami.plugin.testing.FakeVulnDetectorBootstrapModule2; |
| 41 | + | import com.google.tsunami.proto.AddressFamily; |
41 | 42 | | import com.google.tsunami.proto.DetectionReport; |
| 43 | + | import com.google.tsunami.proto.Hostname; |
| 44 | + | import com.google.tsunami.proto.IpAddress; |
| 45 | + | import com.google.tsunami.proto.NetworkEndpoint; |
42 | 46 | | import com.google.tsunami.proto.NetworkService; |
| 47 | + | import com.google.tsunami.proto.Port; |
43 | 48 | | import com.google.tsunami.proto.ReconnaissanceReport; |
44 | 49 | | import com.google.tsunami.proto.ScanFinding; |
45 | 50 | | import com.google.tsunami.proto.ScanResults; |
46 | 51 | | import com.google.tsunami.proto.ScanStatus; |
| 52 | + | import com.google.tsunami.proto.ServiceContext; |
47 | 53 | | import com.google.tsunami.proto.TargetInfo; |
| 54 | + | import com.google.tsunami.proto.TransportProtocol; |
| 55 | + | import com.google.tsunami.proto.WebServiceContext; |
48 | 56 | | import com.google.tsunami.workflow.ScanningWorkflowException; |
49 | 57 | | import io.github.classgraph.ClassGraph; |
50 | 58 | | import io.github.classgraph.ScanResult; |
51 | 59 | | import java.io.IOException; |
| 60 | + | import java.net.Inet4Address; |
| 61 | + | import java.net.InetAddress; |
| 62 | + | import java.net.URL; |
52 | 63 | | import java.util.concurrent.ExecutionException; |
53 | 64 | | import java.util.stream.Stream; |
54 | 65 | | import javax.inject.Inject; |
| skipped 12 lines |
67 | 78 | | public final class TsunamiCliTest { |
68 | 79 | | private static final String IP_TARGET = "127.0.0.1"; |
69 | 80 | | private static final String HOSTNAME_TARGET = "localhost"; |
| 81 | + | private static final String URI_TARGET = "https://localhost/function1"; |
70 | 82 | | |
71 | 83 | | @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); |
72 | 84 | | |
| skipped 98 lines |
171 | 183 | | FakeServiceFingerprinter.addWebServiceContext( |
172 | 184 | | FakePortScanner.getFakeNetworkService( |
173 | 185 | | NetworkEndpointUtils.forHostname(HOSTNAME_TARGET)))) |
| 186 | + | .build()); |
| 187 | + | } |
| 188 | + | |
| 189 | + | @Test |
| 190 | + | public void run_whenUriTarget_generatesCorrectResult() |
| 191 | + | throws InterruptedException, ExecutionException, IOException { |
| 192 | + | |
| 193 | + | boolean scanSucceeded = runCli(ImmutableMap.of(), "--uri-target=" + URI_TARGET); |
| 194 | + | assertThat(scanSucceeded).isTrue(); |
| 195 | + | |
| 196 | + | URL url = new URL(URI_TARGET); |
| 197 | + | String hostname = url.getHost(); |
| 198 | + | String ipaddress = InetAddress.getByName(hostname).getHostAddress(); |
| 199 | + | InetAddress inetAddress = InetAddress.getByName(url.getHost()); |
| 200 | + | AddressFamily addressFamily = |
| 201 | + | inetAddress instanceof Inet4Address ? AddressFamily.IPV4 : AddressFamily.IPV6; |
| 202 | + | |
| 203 | + | NetworkEndpoint networkEndpoint = |
| 204 | + | NetworkEndpoint.newBuilder() |
| 205 | + | .setType(NetworkEndpoint.Type.IP_HOSTNAME_PORT) |
| 206 | + | .setHostname(Hostname.newBuilder().setName("localhost")) |
| 207 | + | .setPort(Port.newBuilder().setPortNumber(443)) |
| 208 | + | .setIpAddress( |
| 209 | + | IpAddress.newBuilder().setAddressFamily(addressFamily).setAddress(ipaddress)) |
| 210 | + | .build(); |
| 211 | + | |
| 212 | + | verify(scanResultsArchiver, times(1)).archive(scanResultsCaptor.capture()); |
| 213 | + | ScanResults storedScanResult = scanResultsCaptor.getValue(); |
| 214 | + | assertThat(storedScanResult.getScanStatus()).isEqualTo(ScanStatus.SUCCEEDED); |
| 215 | + | assertThat(storedScanResult.getReconnaissanceReport()) |
| 216 | + | .isEqualTo( |
| 217 | + | ReconnaissanceReport.newBuilder() |
| 218 | + | .setTargetInfo(TargetInfo.newBuilder().addNetworkEndpoints(networkEndpoint)) |
| 219 | + | .addNetworkServices( |
| 220 | + | NetworkService.newBuilder() |
| 221 | + | .setNetworkEndpoint(networkEndpoint) |
| 222 | + | .setTransportProtocol(TransportProtocol.TCP) |
| 223 | + | .setServiceName("https") |
| 224 | + | .setServiceContext( |
| 225 | + | ServiceContext.newBuilder() |
| 226 | + | .setWebServiceContext( |
| 227 | + | WebServiceContext.newBuilder() |
| 228 | + | .setApplicationRoot(url.getPath())))) |
174 | 229 | | .build()); |
175 | 230 | | } |
176 | 231 | | |
| skipped 76 lines |