use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldNotBeAbleToCreatePipelineIfUserIsTemplateAdmin.
@Test
public void shouldNotBeAbleToCreatePipelineIfUserIsTemplateAdmin() {
final Username user = new Username(new CaseInsensitiveString("user"));
when(goConfigService.isGroupAdministrator(user.getUsername())).thenReturn(false);
when(goConfigService.isUserAdmin(user)).thenReturn(false);
when(goConfigService.isSecurityEnabled()).thenReturn(true);
SecurityService spy = spy(securityService);
doReturn(true).when(spy).isAuthorizedToViewAndEditTemplates(user);
assertThat(spy.canCreatePipelines(new Username(new CaseInsensitiveString("user"))), is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class SecurityServiceTest method shouldSayUserIsAuthorizedToViewTemplatesWhenTheUserHasViewPermissionsToAtLeastOneTemplate.
@Test
public void shouldSayUserIsAuthorizedToViewTemplatesWhenTheUserHasViewPermissionsToAtLeastOneTemplate() {
CruiseConfig config = new BasicCruiseConfig();
String theSuperAdmin = "theSuperAdmin";
String templateName = "template";
String secondTemplateName = "secondTemplate";
CaseInsensitiveString templateAdminName = new CaseInsensitiveString("templateAdmin");
CaseInsensitiveString templateViewUser = new CaseInsensitiveString("templateViewUser");
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 ViewConfig(new AdminUser(templateViewUser)))));
when(goConfigService.cruiseConfig()).thenReturn(config);
when(goConfigService.isUserAdmin(new Username(templateAdminName))).thenReturn(false);
when(goConfigService.isUserAdmin(new Username(templateViewUser))).thenReturn(false);
when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString(theSuperAdmin)))).thenReturn(true);
when(goConfigService.isUserAdmin(new Username(new CaseInsensitiveString("regularUser")))).thenReturn(false);
assertThat(securityService.isAuthorizedToViewTemplates(new Username(templateAdminName)), is(true));
assertThat(securityService.isAuthorizedToViewTemplates(new Username(templateViewUser)), is(true));
assertThat(securityService.isAuthorizedToViewTemplates(new Username(new CaseInsensitiveString(theSuperAdmin))), is(true));
assertThat(securityService.isAuthorizedToViewTemplates(new Username(new CaseInsensitiveString("regularUser"))), is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method shouldNotHaveFailedTestsSectionWhenThereAreNoFailedTests.
@Test
public void shouldNotHaveFailedTestsSectionWhenThereAreNoFailedTests() {
String jezMail = prepareOneMatchedUser();
stubPipelineAndStage(new Date());
when(systemEnvironment.isShineEnabled()).thenReturn(true);
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(new ArrayList<>());
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(jezMail);
assertThat(body, not(containsString(StageNotificationService.FAILED_TEST_SECTION)));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method stubPipelineAndStage.
private void stubPipelineAndStage(Date date) {
final PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("go", "dev", "compile", "test", "twist");
final Modification svnModification = new Modification("lgao", "Fixing the not checked in files", "jez@cruise.com", date, "123");
svnModification.createModifiedFile("build.xml", "some_dir", ModifiedAction.added);
svnModification.createModifiedFile("some.xml", "other_dir", ModifiedAction.deleted);
Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, new ManualBuild(new Username(new CaseInsensitiveString("loser"))).onModifications(new MaterialRevisions(new MaterialRevision(new MaterialConfigConverter().toMaterials(pipelineConfig.materialConfigs()).get(0), svnModification)), false, null), new DefaultSchedulingContext("loser"), "md5-test", new TimeProvider());
Stage stage = pipeline.getStages().get(0);
when(stageService.findStageWithIdentifier(stageIdentifier)).thenReturn(stage);
stage.setPipelineId(100L);
when(pipelineService.fullPipelineById(100)).thenReturn(pipeline);
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method shouldHaveFailedTestsSectionWhenShineIsEnabledAndThereAreFailedTests.
@Test
public void shouldHaveFailedTestsSectionWhenShineIsEnabledAndThereAreFailedTests() {
String mail = prepareOneMatchedUser();
stubPipelineAndStage(new Date());
when(systemEnvironment.isShineEnabled()).thenReturn(true);
ArrayList<TestSuite> testSuites = new ArrayList<>();
testSuites.add(new TestSuite("blah"));
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(testSuites);
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(mail);
assertThat(body, containsString(StageNotificationService.FAILED_TEST_SECTION));
}
Aggregations