File tree Expand file tree Collapse file tree 4 files changed +58
-0
lines changed
main/java/org/jenkinsci/plugins/scriptler
java/org/jenkinsci/plugins/scriptler Expand file tree Collapse file tree 4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 7777 <artifactId >token-macro</artifactId >
7878 </dependency >
7979
80+ <dependency >
81+ <groupId >io.jenkins.configuration-as-code</groupId >
82+ <artifactId >test-harness</artifactId >
83+ <scope >test</scope >
84+ </dependency >
85+
8086 <dependency >
8187 <groupId >nl.jqno.equalsverifier</groupId >
8288 <artifactId >equalsverifier</artifactId >
8389 <version >3.17.4</version >
8490 <scope >test</scope >
8591 </dependency >
92+
93+ <dependency >
94+ <groupId >org.jenkins-ci.plugins</groupId >
95+ <artifactId >matrix-auth</artifactId >
96+ <scope >test</scope >
97+ </dependency >
8698 </dependencies >
8799
88100 <repositories >
Original file line number Diff line number Diff line change 11package org .jenkinsci .plugins .scriptler ;
22
3+ import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
4+ import hudson .init .InitMilestone ;
5+ import hudson .init .Initializer ;
36import hudson .security .Permission ;
47import hudson .security .PermissionGroup ;
58import hudson .security .PermissionScope ;
@@ -26,4 +29,13 @@ public final class ScriptlerPermissions {
2629 public static final Permission BYPASS_APPROVAL = Jenkins .ADMINISTER ;
2730
2831 private ScriptlerPermissions () {}
32+
33+ @ SuppressFBWarnings (
34+ value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT" ,
35+ justification = "getEnabled return value discarded" )
36+ @ Initializer (after = InitMilestone .PLUGINS_STARTED , before = InitMilestone .EXTENSIONS_AUGMENTED )
37+ public static void ensurePermissionsRegistered () {
38+ CONFIGURE .getEnabled ();
39+ RUN_SCRIPTS .getEnabled ();
40+ }
2941}
Original file line number Diff line number Diff line change 1+ package org .jenkinsci .plugins .scriptler ;
2+
3+ import static org .junit .jupiter .api .Assertions .assertTrue ;
4+
5+ import hudson .security .SecurityRealm ;
6+ import io .jenkins .plugins .casc .misc .ConfiguredWithCode ;
7+ import io .jenkins .plugins .casc .misc .JenkinsConfiguredWithCodeRule ;
8+ import io .jenkins .plugins .casc .misc .junit .jupiter .WithJenkinsConfiguredWithCode ;
9+ import org .junit .jupiter .api .Test ;
10+ import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
11+ import org .springframework .security .core .Authentication ;
12+
13+ @ WithJenkinsConfiguredWithCode
14+ class ScriptlerPermissionsTests {
15+ @ ConfiguredWithCode ("/casc.yaml" )
16+ @ Test
17+ void permissionsAreAvailableOnStartup (JenkinsConfiguredWithCodeRule rule ) throws Exception {
18+ SecurityRealm realm = rule .createDummySecurityRealm ();
19+ rule .jenkins .setSecurityRealm (realm );
20+
21+ UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken ("user" , "user" );
22+ Authentication a = realm .getSecurityComponents ().manager2 .authenticate (authRequest );
23+ assertTrue (rule .jenkins .hasPermission2 (a , ScriptlerPermissions .CONFIGURE ));
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ jenkins :
2+ authorizationStrategy :
3+ projectMatrix :
4+ entries :
5+ - group :
6+ name : authenticated
7+ permissions :
8+ - " Scriptler/Configure"
9+ - " Scriptler/RunScripts"
You can’t perform that action at this time.
0 commit comments