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");
}
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")));
}
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"));
}
}
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);
}
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());
}
Aggregations