use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldReturnTrueForGroupAdminsToViewTemplateConfigurationByDefault.
@Test
public void shouldReturnTrueForGroupAdminsToViewTemplateConfigurationByDefault() {
CruiseConfig config = getCruiseConfigWithSecurityEnabled();
CaseInsensitiveString groupAdmin = new CaseInsensitiveString("groupAdmin");
setUpGroupWithAuthorization(config, new Authorization(new AdminsConfig(new AdminUser(groupAdmin))));
CaseInsensitiveString templateName = new CaseInsensitiveString("template");
config.addTemplate(createTemplate("template"));
when(goConfigService.cruiseConfig()).thenReturn(config);
when(goConfigService.isUserAdmin(new Username(groupAdmin))).thenReturn(false);
when(goConfigService.isGroupAdministrator(groupAdmin)).thenReturn(true);
assertThat(securityService.isAuthorizedToViewTemplate(templateName, new Username(groupAdmin)), is(true));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldSayThatAUserIsAuthorizedToViewAndEditTemplatesWhenTheUserHasPermissionsForAtLeastOneTemplate.
@Test
public void shouldSayThatAUserIsAuthorizedToViewAndEditTemplatesWhenTheUserHasPermissionsForAtLeastOneTemplate() throws Exception {
CruiseConfig config = new BasicCruiseConfig();
String theSuperAdmin = "theSuperAdmin";
String templateName = "template";
String secondTemplateName = "secondTemplate";
CaseInsensitiveString templateAdminName = new CaseInsensitiveString("templateAdmin");
CaseInsensitiveString secondTemplateAdminName = new CaseInsensitiveString("secondTemplateAdmin");
GoConfigMother.enableSecurityWithPasswordFilePlugin(config);
GoConfigMother.addUserAsSuperAdmin(config, theSuperAdmin);
config.addTemplate(createTemplate(templateName, new Authorization(new AdminsConfig(new AdminUser(templateAdminName)))));
config.addTemplate(createTemplate(secondTemplateName, new Authorization(new AdminsConfig(new AdminUser(secondTemplateAdminName)))));
when(goConfigService.cruiseConfig()).thenReturn(config);
when(goConfigService.isUserAdmin(new Username(templateAdminName))).thenReturn(false);
when(goConfigService.isUserAdmin(new Username(secondTemplateName))).thenReturn(false);
when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString(theSuperAdmin)))).thenReturn(true);
when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString("someOtherUserWhoIsNotAdminOfAnyTemplates")))).thenReturn(false);
assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(templateAdminName)), is(true));
assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(secondTemplateAdminName)), is(true));
assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(theSuperAdmin))), is(true));
assertThat(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString("someOtherUserWhoIsNotAdminOfAnyTemplates"))), is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldReturnFalseForViewingAdminPageForARegularUser.
@Test
public void shouldReturnFalseForViewingAdminPageForARegularUser() {
final Username user = new Username(new CaseInsensitiveString("user"));
CruiseConfig config = new BasicCruiseConfig();
when(goConfigService.cruiseConfig()).thenReturn(config);
when(goConfigService.isUserAdmin(user)).thenReturn(false);
when(goConfigService.isGroupAdministrator(user.getUsername())).thenReturn(false);
when(goConfigService.isSecurityEnabled()).thenReturn(true);
SecurityService spy = spy(securityService);
doReturn(false).when(spy).isAuthorizedToViewAndEditTemplates(user);
doReturn(false).when(spy).isAuthorizedToViewTemplates(user);
assertThat(spy.canViewAdminPage(user), is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldSayThatAUserIsAuthorizedToEditTemplateWhenTheUserIsASuperAdmin.
@Test
public void shouldSayThatAUserIsAuthorizedToEditTemplateWhenTheUserIsASuperAdmin() throws Exception {
CruiseConfig cruiseConfig = new BasicCruiseConfig();
String adminName = "theSuperAdmin";
CaseInsensitiveString templateName = new CaseInsensitiveString("template");
GoConfigMother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
GoConfigMother.addUserAsSuperAdmin(cruiseConfig, adminName).addTemplate(createTemplate("template"));
when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString(adminName)))).thenReturn(true);
assertThat(securityService.isAuthorizedToEditTemplate(templateName, new Username(new CaseInsensitiveString(adminName))), is(true));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldBeAbleToTellIfAUserIsAnAdmin.
@Test
public void shouldBeAbleToTellIfAUserIsAnAdmin() {
Username username = new Username(new CaseInsensitiveString("user"));
when(goConfigService.isUserAdmin(username)).thenReturn(Boolean.TRUE);
when(goConfigService.isSecurityEnabled()).thenReturn(true);
assertThat(securityService.canViewAdminPage(username), is(true));
verify(goConfigService).isUserAdmin(username);
}
Aggregations