Search in sources :

Example 16 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldPopulateErrorCorrectly_VSMForMaterial.

@Test
public void shouldPopulateErrorCorrectly_VSMForMaterial() throws Exception {
    /*
				git --> p1
		 */
    String groupName = "g1";
    String pipelineName = "p1";
    String userName = "looser";
    GitMaterial gitMaterial = new GitMaterial("git");
    MaterialConfig gitConfig = gitMaterial.config();
    GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
    PipelineConfigs groups = new BasicPipelineConfigs(groupName, new Authorization(), PipelineConfigMother.pipelineConfig(pipelineName, new MaterialConfigs(gitConfig)));
    CruiseConfig cruiseConfig = new BasicCruiseConfig(groups);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(goConfigService.groups()).thenReturn(new PipelineGroups(groups));
    when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(false);
    // unknown material
    valueStreamMapService.getValueStreamMap("unknown-material", "r1", new Username(new CaseInsensitiveString(userName)), result);
    assertResult(SC_NOT_FOUND, "MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND");
    // unauthorized
    valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
    assertResult(SC_UNAUTHORIZED, "MATERIAL_CANNOT_VIEW");
    // material config exists but no material instance
    when(securityService.hasViewPermissionForGroup(userName, groupName)).thenReturn(true);
    when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(null);
    valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
    assertResult(SC_NOT_FOUND, "MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND");
    // modification (revision) doesn't exist
    when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.findModificationWithRevision(gitMaterial, "r1")).thenReturn(null);
    valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
    assertResult(SC_NOT_FOUND, "MATERIAL_MODIFICATION_NOT_FOUND");
    // internal error
    when(goConfigService.groups()).thenThrow(new RuntimeException("just for fun"));
    valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), "r1", new Username(new CaseInsensitiveString(userName)), result);
    assertResult(SC_INTERNAL_SERVER_ERROR, "VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL");
}
Also used : GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Username(com.thoughtworks.go.server.domain.Username) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 17 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class UserHelperTest method shouldGetDisplayNameForAPasswordFileUser.

@Test
public void shouldGetDisplayNameForAPasswordFileUser() {
    GrantedAuthority[] authorities = { new GrantedAuthorityImpl("anything") };
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "Full Name", "password", true, true, true, true, authorities), null, authorities);
    assertThat(UserHelper.getUserName(authentication), is(new Username(new CaseInsensitiveString("user"), "Full Name")));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 18 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineSqlMapDaoIntegrationTest method shouldThrowExceptionWhenBuildCauseIsAskedForAPipelineWithInvalidCounter.

@Test
public void shouldThrowExceptionWhenBuildCauseIsAskedForAPipelineWithInvalidCounter() {
    String pipelineName = "P1";
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages(pipelineName, "S1");
    String username = "username";
    BuildCause manualForced = BuildCause.createManualForced(modifyOneFile(pipelineConfig), new Username(new CaseInsensitiveString(username)));
    Pipeline pipeline = dbHelper.schedulePipeline(pipelineConfig, manualForced, username, new TimeProvider());
    dbHelper.pass(pipeline);
    BuildCause buildCause = pipelineDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, 1);
    assertThat(buildCause, is(notNullValue()));
    try {
        pipelineDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, 10);
        fail("should have thrown PipelineNotFoundException");
    } catch (Exception e) {
        assertThat(e instanceof PipelineNotFoundException, is(true));
        assertThat(e.getMessage(), is("Pipeline P1 with counter 10 was not found"));
    }
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SQLException(java.sql.SQLException) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 19 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PluginServiceTest method shouldSavePluginSettingsToDbIfPluginSettingsAreValidated.

@Test
public void shouldSavePluginSettingsToDbIfPluginSettingsAreValidated() {
    Map<String, String> parameterMap = new HashMap<>();
    parameterMap.put("p2-k1", "v1");
    PluginSettings pluginSettings = new PluginSettings("plugin-id-2");
    pluginSettings.populateSettingsMap(parameterMap);
    Username currentUser = new Username("admin");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(securityService.isUserAdmin(currentUser)).thenReturn(true);
    when(configRepoExtension.canHandlePlugin("plugin-id-2")).thenReturn(true);
    when(configRepoExtension.validatePluginSettings(eq("plugin-id-2"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
    pluginService.savePluginSettings(currentUser, result, pluginSettings);
    Plugin plugin = new Plugin("plugin-id-2", toJSON(parameterMap));
    verify(pluginDao).saveOrUpdate(plugin);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 20 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PluginServiceTest method shouldIgnoreErrorsWhileNotifyingPluginSettingChange.

@Test
public void shouldIgnoreErrorsWhileNotifyingPluginSettingChange() throws Exception {
    Map<String, String> parameterMap = new HashMap<>();
    parameterMap.put("p2-k1", "v1");
    PluginSettings pluginSettings = new PluginSettings("plugin-id-2");
    pluginSettings.populateSettingsMap(parameterMap);
    Username currentUser = new Username("admin");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(securityService.isUserAdmin(currentUser)).thenReturn(true);
    when(configRepoExtension.canHandlePlugin("plugin-id-2")).thenReturn(true);
    when(configRepoExtension.validatePluginSettings(eq("plugin-id-2"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
    doThrow(new RuntimeException()).when(configRepoExtension).notifyPluginSettingsChange("plugin-id-2", pluginSettings.getSettingsAsKeyValuePair());
    pluginService.savePluginSettings(currentUser, result, pluginSettings);
    Plugin plugin = new Plugin("plugin-id-2", toJSON(parameterMap));
    verify(pluginDao).saveOrUpdate(plugin);
    verify(configRepoExtension).notifyPluginSettingsChange("plugin-id-2", pluginSettings.getSettingsAsKeyValuePair());
    assertTrue(result.isSuccessful());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) 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