🤬
  • Add failed RemoteVulnDetectors for testing purposes.

    PiperOrigin-RevId: 461691002
    Change-Id: I1546bac52756a31669e5c6e20e87c04b2e22d65d
  • Loading...
  • John Y. Kim committed with Copybara-Service 2 years ago
    897f396a
    1 parent 524d383a
  • ■ ■ ■ ■ ■ ■
    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 + 
  • ■ ■ ■ ■ ■ ■
    plugin/src/main/java/com/google/tsunami/plugin/testing/FailedRemoteVulnDetectorBootstrapModule.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.tsunami.plugin.PluginBootstrapModule;
     19 + 
     20 +/** Bootstrapping module for {@link FailedRemoteVulnDetector}. */
     21 +public final class FailedRemoteVulnDetectorBootstrapModule extends PluginBootstrapModule {
     22 + @Override
     23 + protected void configurePlugin() {
     24 + registerPlugin(FailedRemoteVulnDetector.class);
     25 + }
     26 +}
     27 + 
Please wait...
Page is in error, reload to recover