Skip to content

Commit a1c5082

Browse files
AndreBrinkopscurvydoggo
authored andcommitted
Add test cases for agent user rights
1 parent a1d6e49 commit a1c5082

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/org/jenkinsci/plugins/GithubRequireOrganizationMembershipACLTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ of this software and associated documentation files (the "Software"), to deal
6060
import java.util.Collections;
6161
import java.util.List;
6262

63+
import hudson.model.Computer;
6364
import hudson.model.Hudson;
6465
import hudson.model.Item;
6566
import hudson.model.Messages;
@@ -555,6 +556,30 @@ public void testCannotReadRepositoryWithInvalidRepoUrl() throws IOException {
555556
}
556557
}
557558

559+
@Test
560+
public void testAgentUserCanCreateConnectAndConfigureAgents() {
561+
GithubAuthenticationToken authenticationToken = Mockito.mock(GithubAuthenticationToken.class);
562+
Mockito.when(authenticationToken.isAuthenticated()).thenReturn(true);
563+
Mockito.when(authenticationToken.getName()).thenReturn("agent");
564+
GithubRequireOrganizationMembershipACL acl = createACL();
565+
566+
assertTrue(acl.hasPermission(authenticationToken, Computer.CREATE));
567+
assertTrue(acl.hasPermission(authenticationToken, Computer.CONFIGURE));
568+
assertTrue(acl.hasPermission(authenticationToken, Computer.CONNECT));
569+
}
570+
571+
@Test
572+
public void testAuthenticatedCanNotCreateConnectAndConfigureAgents() {
573+
GithubAuthenticationToken authenticationToken = Mockito.mock(GithubAuthenticationToken.class);
574+
Mockito.when(authenticationToken.isAuthenticated()).thenReturn(true);
575+
Mockito.when(authenticationToken.getName()).thenReturn("authenticated");
576+
GithubRequireOrganizationMembershipACL acl = createACL();
577+
578+
assertFalse(acl.hasPermission(authenticationToken, Computer.CREATE));
579+
assertFalse(acl.hasPermission(authenticationToken, Computer.CONFIGURE));
580+
assertFalse(acl.hasPermission(authenticationToken, Computer.CONNECT));
581+
}
582+
558583
@Test
559584
public void testAnonymousCanViewJobStatusWhenGranted() {
560585
this.allowAnonymousJobStatusPermission = true;

0 commit comments

Comments
 (0)