Exemplo n.º 1
0
  @Test
  public void validate_group_query() throws Exception {
    Map<String, Object> validGroupParams = Maps.newHashMap();
    validGroupParams.put("group", "my_group");
    validGroupParams.put("permission", GlobalPermissions.SYSTEM_ADMIN);

    PermissionChangeQuery query = PermissionChangeQuery.buildFromParams(validGroupParams);
    query.validate();
  }
Exemplo n.º 2
0
  @Test
  public void detect_missing_permission() throws Exception {
    Map<String, Object> inconsistentParams = Maps.newHashMap();
    inconsistentParams.put("user", "my_login");

    PermissionChangeQuery query = PermissionChangeQuery.buildFromParams(inconsistentParams);

    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Missing permission parameter");
    query.validate();
  }
Exemplo n.º 3
0
  @Test
  public void reject_inconsistent_query() throws Exception {
    Map<String, Object> inconsistentParams = Maps.newHashMap();
    inconsistentParams.put("user", "my_login");
    inconsistentParams.put("group", "my_group");
    inconsistentParams.put("permission", GlobalPermissions.SYSTEM_ADMIN);

    PermissionChangeQuery query = PermissionChangeQuery.buildFromParams(inconsistentParams);

    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Only one of user or group parameter should be provided");
    query.validate();
  }
Exemplo n.º 4
0
  @Test
  public void validate_global_permission_reference() throws Exception {
    Map<String, Object> inconsistentParams = Maps.newHashMap();
    inconsistentParams.put("user", "my_login");
    inconsistentParams.put("permission", "invalid");

    PermissionChangeQuery query = PermissionChangeQuery.buildFromParams(inconsistentParams);

    thrown.expect(BadRequestException.class);
    thrown.expectMessage(
        "Invalid global permission key invalid. Valid values are [admin, profileadmin, shareDashboard, scan, dryRunScan, provisioning]");
    query.validate();
  }
Exemplo n.º 5
0
  @Test
  public void validate_component_permission_reference() throws Exception {
    Map<String, Object> inconsistentParams = Maps.newHashMap();
    inconsistentParams.put("user", "my_login");
    inconsistentParams.put("component", "org.sample.Sample");
    inconsistentParams.put("permission", "invalid");

    PermissionChangeQuery query = PermissionChangeQuery.buildFromParams(inconsistentParams);

    thrown.expect(BadRequestException.class);
    thrown.expectMessage(
        "Invalid component permission key invalid. Valid values are [user, admin, codeviewer]");
    query.validate();
  }