-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run ATH with CSP when
csp.rule
is defined (#1743)
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/org/jenkinsci/test/acceptance/junit/CspRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jenkinsci.test.acceptance.junit; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Injector; | ||
import org.jenkinsci.test.acceptance.po.GlobalSecurityConfig; | ||
import org.jenkinsci.test.acceptance.po.Jenkins; | ||
import org.jenkinsci.test.acceptance.update_center.PluginSpec; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
@GlobalRule | ||
public final class CspRule implements TestRule { | ||
|
||
@Inject | ||
private Injector injector; | ||
|
||
@Override | ||
public Statement apply(final Statement base, final Description d) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
if (isEnabled() | ||
&& d.getAnnotation(WithInstallWizard.class) == null | ||
&& d.getTestClass().getAnnotation(WithInstallWizard.class) == null) { | ||
Jenkins jenkins = injector.getInstance(Jenkins.class); | ||
|
||
PluginSpec plugin = new PluginSpec("csp"); | ||
jenkins.getPluginManager().installPlugins(plugin); | ||
|
||
GlobalSecurityConfig security = new GlobalSecurityConfig(jenkins); | ||
security.open(); | ||
security.disableCspReportOnly(); | ||
security.save(); | ||
} | ||
base.evaluate(); | ||
} | ||
|
||
private static boolean isEnabled() { | ||
if (System.getProperty("csp.rule") == null) { | ||
return false; | ||
} | ||
if (System.getProperty("csp.rule").isEmpty()) { | ||
return true; | ||
} | ||
return Boolean.getBoolean("csp.rule"); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters