use of hudson.security.AuthorizationStrategy in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCopiedFrom.
@Test
public void testOnCopiedFrom() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(2);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 1);
AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
assertEquals(property.getGrantedPermissions().keySet().size(), 7);
assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
use of hudson.security.AuthorizationStrategy in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCreatedFromScratchGlobalMatrixAuthorizationStrategy.
@Test
public void testOnCreatedFromScratchGlobalMatrixAuthorizationStrategy() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(1);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 0);
}
use of hudson.security.AuthorizationStrategy in project blueocean-plugin by jenkinsci.
the class BlueOceanConfigStatePreloader method getStateJson.
/**
* {@inheritDoc}
*/
@Override
public String getStateJson() {
StringWriter writer = new StringWriter();
Jenkins jenkins = Jenkins.getInstance();
String version = Jenkins.getVersion() != null ? Jenkins.getVersion().toString() : Jenkins.VERSION;
AuthorizationStrategy authorizationStrategy = jenkins.getAuthorizationStrategy();
boolean allowAnonymousRead = true;
if (authorizationStrategy instanceof FullControlOnceLoggedInAuthorizationStrategy) {
allowAnonymousRead = ((FullControlOnceLoggedInAuthorizationStrategy) authorizationStrategy).isAllowAnonymousRead();
}
new JSONBuilder(writer).object().key("version").value(getBlueOceanPluginVersion()).key("jenkinsConfig").object().key("version").value(version).key("security").object().key("enabled").value(jenkins.isUseSecurity()).key("loginUrl").value(jenkins.getSecurityRealm() == SecurityRealm.NO_AUTHENTICATION ? null : jenkins.getSecurityRealm().getLoginUrl()).key("authorizationStrategy").object().key("allowAnonymousRead").value(allowAnonymousRead).endObject().key("enableJWT").value(BlueOceanConfigProperties.BLUEOCEAN_FEATURE_JWT_AUTHENTICATION).endObject().endObject().key("features").object().key("organizations.enabled").value(Boolean.getBoolean("blueocean.features.organizations.enabled")).endObject().endObject();
return writer.toString();
}
use of hudson.security.AuthorizationStrategy in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCopiedFromGlobalMatrixAuthorizationStrategy.
@Test
public void testOnCopiedFromGlobalMatrixAuthorizationStrategy() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(1);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
assertTrue(freeStyleProject.isHoldOffBuildUntilSave());
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
assertEquals(freeStyleProject.getAllProperties().size(), 0);
}
use of hudson.security.AuthorizationStrategy in project hudson-2.x by hudson.
the class FreeStyleProjectTest method testOnCreatedFromScratch.
@Test
public void testOnCreatedFromScratch() {
Hudson hudson = createMock(Hudson.class);
AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
User user = createMock(User.class);
expect(user.getId()).andReturn(USER).times(2);
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
assertEquals(freeStyleProject.getCreatedBy(), USER);
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 1);
AuthorizationMatrixProperty property = (AuthorizationMatrixProperty) properties.get(0);
assertEquals(property.getGrantedPermissions().keySet().size(), 7);
assertNotNull(property.getGrantedPermissions().get(Item.CONFIGURE));
assertTrue(property.getGrantedPermissions().get(Item.CONFIGURE).contains(USER));
}
Aggregations