Search in sources :

Example 36 with Username

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 37 with Username

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 38 with Username

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)));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 39 with Username

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);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 40 with Username

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));
}
Also used : TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) Username(com.thoughtworks.go.server.domain.Username) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10