■ ■ ■ ■ ■ ■
plugin/src/main/java/com/google/tsunami/plugin/testing/FailedRemoteVulnDetector.java
| 1 | + | /* |
| 2 | + | * Copyright 2022 Google LLC |
| 3 | + | * |
| 4 | + | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + | * you may not use this file except in compliance with the License. |
| 6 | + | * You may obtain a copy of the License at |
| 7 | + | * |
| 8 | + | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + | * |
| 10 | + | * Unless required by applicable law or agreed to in writing, software |
| 11 | + | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + | * See the License for the specific language governing permissions and |
| 14 | + | * limitations under the License. |
| 15 | + | */ |
| 16 | + | package com.google.tsunami.plugin.testing; |
| 17 | + | |
| 18 | + | import com.google.common.collect.ImmutableList; |
| 19 | + | import com.google.common.collect.Sets; |
| 20 | + | import com.google.tsunami.plugin.LanguageServerException; |
| 21 | + | import com.google.tsunami.plugin.PluginType; |
| 22 | + | import com.google.tsunami.plugin.RemoteVulnDetector; |
| 23 | + | import com.google.tsunami.plugin.annotations.PluginInfo; |
| 24 | + | import com.google.tsunami.proto.DetectionReportList; |
| 25 | + | import com.google.tsunami.proto.MatchedPlugin; |
| 26 | + | import com.google.tsunami.proto.NetworkService; |
| 27 | + | import com.google.tsunami.proto.PluginDefinition; |
| 28 | + | import com.google.tsunami.proto.TargetInfo; |
| 29 | + | import java.util.Set; |
| 30 | + | |
| 31 | + | /** Fake {@link RemoteVulnDetector} implementation that fails to run. */ |
| 32 | + | @PluginInfo( |
| 33 | + | type = PluginType.REMOTE_VULN_DETECTION, |
| 34 | + | name = "FailedRemoteVulnDetector", |
| 35 | + | version = "v0.1", |
| 36 | + | description = "fake description", |
| 37 | + | author = "fake", |
| 38 | + | bootstrapModule = FailedRemoteVulnDetectorBootstrapModule.class) |
| 39 | + | public final class FailedRemoteVulnDetector implements RemoteVulnDetector { |
| 40 | + | |
| 41 | + | private final Set<MatchedPlugin> matchedPluginsToRun; |
| 42 | + | |
| 43 | + | public FailedRemoteVulnDetector() { |
| 44 | + | this.matchedPluginsToRun = Sets.newHashSet(); |
| 45 | + | } |
| 46 | + | |
| 47 | + | @Override |
| 48 | + | public DetectionReportList detect(TargetInfo target, ImmutableList<NetworkService> services) { |
| 49 | + | throw new LanguageServerException("RemoteVulnDetector failed."); |
| 50 | + | } |
| 51 | + | |
| 52 | + | @Override |
| 53 | + | public ImmutableList<PluginDefinition> getAllPlugins() { |
| 54 | + | return ImmutableList.of(PluginDefinition.getDefaultInstance()); |
| 55 | + | } |
| 56 | + | |
| 57 | + | @Override |
| 58 | + | public void addMatchedPluginToDetect(MatchedPlugin plugin) { |
| 59 | + | this.matchedPluginsToRun.add(plugin); |
| 60 | + | } |
| 61 | + | } |
| 62 | + | |