@Test
 public void shouldNotAllowUnauthorizedUserToGetMingleConfig() {
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   MingleConfig mingleConfig =
       mingleConfigService.mingleConfigForPipelineNamed(
           "foo", new Username(new CaseInsensitiveString("some_loser")), result);
   assertThat(mingleConfig, is(nullValue()));
   assertThat(result.isSuccessful(), is(false));
   assertThat(
       result.message(localizer), is("You do not have view permissions for pipeline 'foo'."));
   assertThat(result.httpCode(), is(401));
 }
예제 #2
0
 @Test
 public void shouldReturnBadRequestForInvalidEnvName() {
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   service.createEnvironment(
       env(
           "foo env",
           new ArrayList<String>(),
           new ArrayList<Map<String, String>>(),
           new ArrayList<String>()),
       new Username(new CaseInsensitiveString("any")),
       result);
   assertThat(result.httpCode(), is(HttpServletResponse.SC_BAD_REQUEST));
   assertThat(result.message(localizer), containsString("Failed to add environment."));
 }
  @Test
  public void shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository()
      throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    when(securityService.canViewAdminPage(username)).thenReturn(false);

    UpdateConfigFromUI updateCommand =
        service.getPackageRepositoryUpdateCommand(new PackageRepository(), username);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    updateCommand.checkPermission(GoConfigMother.configWithPipelines("sample"), result);

    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(401));
    verify(securityService).canViewAdminPage(username);
  }
예제 #4
0
 @Test
 public void shouldReturnBadRequestForUpdateWhenUsingInvalidEnvName() {
   configHelper.addEnvironments("foo-env");
   HttpLocalizedOperationResult result =
       service.updateEnvironment(
           "foo-env",
           env(
               "foo env",
               new ArrayList<String>(),
               new ArrayList<Map<String, String>>(),
               new ArrayList<String>()),
           new Username(new CaseInsensitiveString("any")),
           goConfigDao.md5OfConfigFile());
   assertThat(result.httpCode(), is(HttpServletResponse.SC_BAD_REQUEST));
   assertThat(
       result.message(localizer), containsString("Failed to update environment 'foo-env'."));
 }
예제 #5
0
 @Test
 public void
     shouldReturnBadRequestForUpdateWhenUsingInvalidEnvName_ForNewUpdateEnvironmentMethod_ForNewUpdateEnvironmentMethod()
         throws NoSuchEnvironmentException {
   configHelper.addEnvironments("foo-env");
   HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
   service.updateEnvironment(
       service.getEnvironmentConfig("foo-env"),
       env(
           "foo env",
           new ArrayList<String>(),
           new ArrayList<Map<String, String>>(),
           new ArrayList<String>()),
       new Username(new CaseInsensitiveString("any")),
       result);
   assertThat(result.httpCode(), is(HttpServletResponse.SC_BAD_REQUEST));
   assertThat(
       result.message(localizer), containsString("Failed to update environment 'foo-env'."));
 }