|
26 | 26 | import org.junit.rules.TemporaryFolder;
|
27 | 27 |
|
28 | 28 | import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
|
| 29 | +import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErr; |
29 | 30 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 31 | import static org.assertj.core.api.Assertions.assertThatNoException;
|
31 | 32 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
@@ -56,13 +57,29 @@ public interface Configurator {
|
56 | 57 | }
|
57 | 58 |
|
58 | 59 | public PluginManager initPluginManager(Configurator configurator) throws IOException {
|
| 60 | + return initPluginManagerWithSecurityWarning(false, configurator); |
| 61 | + } |
| 62 | + |
| 63 | + public PluginManager initPluginManagerWithSecurityWarning(boolean showSecurityWarnings, Configurator configurator) throws IOException { |
59 | 64 | Config.Builder configBuilder = Config.builder()
|
60 | 65 | .withJenkinsWar(jenkinsWar.getAbsolutePath())
|
61 | 66 | .withPluginDir(pluginsDir)
|
62 |
| - .withShowAvailableUpdates(true) |
63 | 67 | .withIsVerbose(true)
|
64 | 68 | .withDoDownload(false)
|
65 | 69 | .withCachePath(cacheDir.toPath());
|
| 70 | + if (showSecurityWarnings) { |
| 71 | + // if showing security warnings, do not show available updates |
| 72 | + configBuilder |
| 73 | + .withHideWarnings(false) |
| 74 | + .withShowWarnings(true) |
| 75 | + .withShowAvailableUpdates(false); |
| 76 | + } else { |
| 77 | + // if showing available updates, do not show security warnings |
| 78 | + configBuilder |
| 79 | + .withHideWarnings(true) |
| 80 | + .withShowWarnings(false) |
| 81 | + .withShowAvailableUpdates(true); |
| 82 | + } |
66 | 83 | configurator.configure(configBuilder);
|
67 | 84 | Config config = configBuilder.build();
|
68 | 85 |
|
@@ -133,6 +150,28 @@ public void showAvailableUpdates_shouldNotFailOnUIThemes() throws Exception {
|
133 | 150 | assertThat(output).doesNotContain("uithemes");
|
134 | 151 | }
|
135 | 152 |
|
| 153 | + @Test |
| 154 | + public void securityWarningsShownByDefaultTest() throws Exception { |
| 155 | + Plugin pluginScriptSecurityWithSecurityWarning = new Plugin("script-security", "1.30", null, null); |
| 156 | + PluginManager pluginManager = initPluginManagerWithSecurityWarning(true, |
| 157 | + configBuilder -> configBuilder.withPlugins(Arrays.asList(pluginScriptSecurityWithSecurityWarning))); |
| 158 | + |
| 159 | + String output = tapSystemErr( |
| 160 | + () -> pluginManager.start(false)); |
| 161 | + assertThat(output).contains("Security warnings"); |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + public void securityWarningsNotShownTest() throws Exception { |
| 166 | + Plugin pluginScriptSecurityWithSecurityWarning = new Plugin("script-security", "1.30", null, null); |
| 167 | + PluginManager pluginManager = initPluginManagerWithSecurityWarning(false, |
| 168 | + configBuilder -> configBuilder.withPlugins(Arrays.asList(pluginScriptSecurityWithSecurityWarning))); |
| 169 | + |
| 170 | + String output = tapSystemErr( |
| 171 | + () -> pluginManager.start(false)); |
| 172 | + assertThat(output).doesNotContain("Security warnings"); |
| 173 | + } |
| 174 | + |
136 | 175 | @Test
|
137 | 176 | public void findPluginsAndDependenciesTest() throws IOException {
|
138 | 177 | Plugin plugin1 = new Plugin("plugin1", "1.0", null, null);
|
|
0 commit comments