-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise default permissions of
JUnit5JenkinsRule
(#910)
Co-authored-by: strangelookingnerd <strangelookingnerd@users.noreply.github.com>
- Loading branch information
1 parent
ab3a21a
commit 09b4a6c
Showing
2 changed files
with
59 additions
and
0 deletions.
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
54 changes: 54 additions & 0 deletions
54
src/test/java/org/jvnet/hudson/test/JenkinsRulePermissionTest.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,54 @@ | ||
package org.jvnet.hudson.test; | ||
|
||
import hudson.security.Permission; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.jvnet.hudson.test.junit.jupiter.WithJenkins; | ||
|
||
/** | ||
* Validates that JUnit4 and JUnit5 based {@link JenkinsRule} implementations have the same default authorization and permissions. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public class JenkinsRulePermissionTest { | ||
|
||
@Rule | ||
public JenkinsRule junit4rule = new JenkinsRule(); | ||
|
||
@org.junit.Test | ||
public void junit4() { | ||
MockAuthorizationStrategy strategy = new MockAuthorizationStrategy(); | ||
junit4rule.getInstance().setAuthorizationStrategy(strategy); | ||
|
||
// basic permissions | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.READ)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.WRITE)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.CREATE)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.UPDATE)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.DELETE)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.CONFIGURE)); | ||
|
||
// admin permissions | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.FULL_CONTROL)); | ||
Assert.assertTrue(junit4rule.getInstance().getACL().hasPermission(Permission.HUDSON_ADMINISTER)); | ||
} | ||
|
||
@org.junit.jupiter.api.Test | ||
@WithJenkins | ||
void junit5(JenkinsRule junit5rule) { | ||
MockAuthorizationStrategy strategy = new MockAuthorizationStrategy(); | ||
junit5rule.getInstance().setAuthorizationStrategy(strategy); | ||
|
||
// basic permissions | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.READ)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.WRITE)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.CREATE)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.UPDATE)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.DELETE)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.CONFIGURE)); | ||
|
||
// admin permissions | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.FULL_CONTROL)); | ||
Assertions.assertTrue(junit5rule.getInstance().getACL().hasPermission(Permission.HUDSON_ADMINISTER)); | ||
} | ||
} |