Exemplo n.º 1
0
  @Test
  public void shouldSetToDefaultGroupWithGroupNameIsEmptyString() {
    PipelineConfigs pipelineConfigs = createEmpty();
    pipelineConfigs.setGroup("");

    assertThat(pipelineConfigs.getGroup(), is(BasicPipelineConfigs.DEFAULT_GROUP));
  }
Exemplo n.º 2
0
  @Test
  public void
      shouldSetViewPermissionByDefaultIfNameIsPresentAndPermissionsAreOff_whileSettingAttributes() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "user1",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, OFF, OFF)),
                m(
                    Authorization.NAME,
                    "role1",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, OFF, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getViewConfig().size(), is(2));
    assertThat(
        authorization.getViewConfig(),
        hasItems(
            (Admin) new AdminRole(new CaseInsensitiveString("role1")),
            (Admin) new AdminUser(new CaseInsensitiveString("user1"))));

    assertThat(authorization.getOperationConfig().size(), is(0));
    assertThat(authorization.getAdminsConfig().size(), is(0));
  }
Exemplo n.º 3
0
 @Test
 public void hasViewPermissionDefinedShouldReturnFalseIfAuthorizationIsNotDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   assertThat(
       "hasViewPermissionDefinedShouldReturnFalseIfAuthorizationIsNotDefined",
       group.hasViewPermissionDefined(),
       is(false));
 }
Exemplo n.º 4
0
 @Test
 public void shouldReturnFalseIfPipelineNotExist() {
   PipelineConfigs configs = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   assertThat(
       "shouldReturnFalseIfPipelineNotExist",
       configs.hasPipeline(new CaseInsensitiveString("not-exist")),
       is(false));
 }
Exemplo n.º 5
0
 @Test
 public void shouldReturnIndexOfPipeline() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   PipelineConfig pipelineConfig = (PipelineConfig) group.get(0).clone();
   pipelineConfig.setLabelTemplate("blah");
   group.update(group.getGroup(), pipelineConfig, "pipeline1");
   assertThat(group.get(0).getLabelTemplate(), is("blah"));
 }
Exemplo n.º 6
0
 @Test
 public void shouldGetAllPipelinesList() {
   PipelineConfig pipeline1 = PipelineConfigMother.pipelineConfig("pipeline1");
   PipelineConfig pipeline2 = PipelineConfigMother.pipelineConfig("pipeline2");
   PipelineConfigs group = createWithPipelines(pipeline1, pipeline2);
   assertThat(group.getPipelines(), hasItem(pipeline1));
   assertThat(group.getPipelines(), hasItem(pipeline2));
 }
Exemplo n.º 7
0
 @Test
 public void shouldReturnTrueIfPipelineExist() {
   PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline1");
   PipelineConfigs configs = createWithPipeline(pipelineConfig);
   assertThat(
       "shouldReturnTrueIfPipelineExist",
       configs.hasPipeline(new CaseInsensitiveString("pipeline1")),
       is(true));
 }
Exemplo n.º 8
0
 @Test
 public void shouldReturnFalseIfViewPermissionIsNotDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   group
       .getAuthorization()
       .getOperationConfig()
       .add(new AdminUser(new CaseInsensitiveString("jez")));
   assertThat(group.hasViewPermission(new CaseInsensitiveString("jez"), null), is(false));
 }
Exemplo n.º 9
0
 @Test
 public void shouldReturnIndexOfPipeline_When2Pipelines() {
   PipelineConfigs group =
       createWithPipelines(
           PipelineConfigMother.pipelineConfig("pipeline1"),
           PipelineConfigMother.pipelineConfig("pipeline2"));
   PipelineConfig pipelineConfig = group.findBy(new CaseInsensitiveString("pipeline2"));
   assertThat(group.indexOf(pipelineConfig), is(1));
 }
Exemplo n.º 10
0
  @Test
  public void shouldAddPipelineAtIndex() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline0"));

    PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1");
    group.add(1, p1);

    assertThat(group.get(1), is(p1));
  }
Exemplo n.º 11
0
 @Test
 public void hasViewPermissionDefinedShouldReturnTrueIfAuthorizationIsDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   group.getAuthorization().getViewConfig().add(new AdminUser(new CaseInsensitiveString("jez")));
   assertThat(
       "hasViewPermissionDefinedShouldReturnTrueIfAuthorizationIsDefined",
       group.hasViewPermissionDefined(),
       is(true));
 }
Exemplo n.º 12
0
 @Test
 public void validate_shouldMakeSureTheNameIsAppropriate() {
   PipelineConfigs group = createEmpty();
   group.validate(null);
   assertThat(
       group.errors().on(BasicPipelineConfigs.GROUP),
       is(
           "Invalid group name 'null'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
 }
Exemplo n.º 13
0
  @Test
  public void shouldReInitializeAuthorizationIfWeClearAllPermissions() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "loser",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, DISABLED, DISABLED)),
                m(
                    Authorization.NAME,
                    "boozer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, ON, ON)),
                m(
                    Authorization.NAME,
                    "geezer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "gang_of_losers",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "blinds",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, ON, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(2));
    assertThat(authorization.getOperationConfig().size(), is(2));
    assertThat(authorization.getViewConfig().size(), is(3));

    group.setConfigAttributes(m());

    authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(0));
    assertThat(authorization.getOperationConfig().size(), is(0));
    assertThat(authorization.getViewConfig().size(), is(0));
  }
Exemplo n.º 14
0
 public Set<String> rolesThatCanOperateOnStage(
     CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) {
   PipelineConfigs group = cruiseConfig.findGroupOfPipeline(pipelineConfig);
   SortedSet<String> roles = new TreeSet<String>();
   if (group.hasAuthorizationDefined()) {
     if (group.hasOperationPermissionDefined()) {
       roles.addAll(group.getOperateRoleNames());
     }
   } else {
     roles.addAll(allRoleNames(cruiseConfig));
   }
   return roles;
 }
Exemplo n.º 15
0
  @Test
  public void shouldRemovePipeline() {
    PipelineConfig p0 = PipelineConfigMother.pipelineConfig("pipeline0");
    PipelineConfigs group = createWithPipeline(p0);

    PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1");
    group.add(1, p1);

    group.remove(p0);

    assertThat(group.get(0), is(p1));
    assertThat(group.size(), is(1));
  }
Exemplo n.º 16
0
  @Test
  public void shouldValidateThatPipelineNameIsUnique() {
    PipelineConfig first = PipelineConfigMother.pipelineConfig("first");
    PipelineConfig second = PipelineConfigMother.pipelineConfig("second");
    PipelineConfigs group = createWithPipelines(first, second);
    PipelineConfig duplicate = PipelineConfigMother.pipelineConfig("first");
    group.addWithoutValidation(duplicate);

    group.validate(null);
    assertThat(
        duplicate.errors().on(PipelineConfig.NAME),
        is(
            "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique."));
    assertThat(
        first.errors().on(PipelineConfig.NAME),
        is(
            "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique."));
  }
Exemplo n.º 17
0
 public Set<String> usersThatCanOperateOnStage(
     CruiseConfig cruiseConfig, PipelineConfig pipelineConfig) {
   SortedSet<String> users = new TreeSet<String>();
   PipelineConfigs group = cruiseConfig.findGroupOfPipeline(pipelineConfig);
   if (group.hasAuthorizationDefined()) {
     if (group.hasOperationPermissionDefined()) {
       users.addAll(group.getOperateUserNames());
       List<String> roles = group.getOperateRoleNames();
       for (Role role : cruiseConfig.server().security().getRoles()) {
         if (roles.contains(CaseInsensitiveString.str(role.getName()))) {
           users.addAll(role.usersOfRole());
         }
       }
     }
   } else {
     users.addAll(allUsernames());
   }
   return users;
 }
Exemplo n.º 18
0
 @Test
 public void shouldValidateGroupNameUniqueness() {
   Map<String, PipelineConfigs> nameToConfig = new HashMap<String, PipelineConfigs>();
   PipelineConfigs group1 = createEmpty();
   group1.setGroup("joe");
   PipelineConfigs group2 = createEmpty();
   group2.setGroup("joe");
   group1.validateNameUniqueness(nameToConfig);
   group2.validateNameUniqueness(nameToConfig);
   assertThat(
       group1.errors().on(PipelineConfigs.GROUP), is("Group with name 'joe' already exists"));
 }
Exemplo n.º 19
0
 protected Object valid() {
   CruiseConfig config = configForEditing();
   PipelineConfigs group = config.findGroup(groupName);
   return group.getCopyForEditing();
 }
Exemplo n.º 20
0
 public boolean isUserAdminOfGroup(final CaseInsensitiveString userName, PipelineConfigs group) {
   return group.isUserAnAdmin(userName, rolesForUser(userName));
 }
Exemplo n.º 21
0
  @Test
  public void shouldUpdateAuthorization() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "loser",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, DISABLED, DISABLED)),
                m(
                    Authorization.NAME,
                    "boozer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, ON, ON)),
                m(
                    Authorization.NAME,
                    "geezer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "gang_of_losers",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "blinds",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, ON, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(2));
    assertThat(
        authorization.getAdminsConfig(),
        hasItems(
            new AdminUser(new CaseInsensitiveString("loser")),
            new AdminRole(new CaseInsensitiveString("blinds"))));

    assertThat(authorization.getOperationConfig().size(), is(2));
    assertThat(
        authorization.getOperationConfig(),
        hasItems(
            new AdminUser(new CaseInsensitiveString("boozer")),
            new AdminRole(new CaseInsensitiveString("blinds"))));

    assertThat(authorization.getViewConfig().size(), is(3));
    assertThat(
        authorization.getViewConfig(),
        hasItems(
            new AdminUser(new CaseInsensitiveString("boozer")),
            new AdminUser(new CaseInsensitiveString("geezer")),
            new AdminRole(new CaseInsensitiveString("gang_of_losers"))));
  }
Exemplo n.º 22
0
  @Test
  public void shouldIgnoreBlankUserOrRoleNames_whileSettingAttributes() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, DISABLED, DISABLED)),
                m(
                    Authorization.NAME,
                    null,
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, ON, ON)),
                m(
                    Authorization.NAME,
                    "geezer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, ON, ON)),
                m(
                    Authorization.NAME,
                    null,
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, OFF, ON)),
                m(
                    Authorization.NAME,
                    "blinds",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, ON, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(1));
    assertThat(
        authorization.getAdminsConfig(),
        hasItem((Admin) new AdminRole(new CaseInsensitiveString("blinds"))));

    assertThat(authorization.getOperationConfig().size(), is(1));
    assertThat(
        authorization.getOperationConfig(),
        hasItem((Admin) new AdminRole(new CaseInsensitiveString("blinds"))));

    assertThat(authorization.getViewConfig().size(), is(1));
    assertThat(
        authorization.getViewConfig(),
        hasItem((Admin) new AdminUser(new CaseInsensitiveString("geezer"))));
  }