Search in sources :

Example 26 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestRangerServiceValidator method test_isValid_missingRequiredParameter.

@Test
public void test_isValid_missingRequiredParameter() throws Exception {
    // Create/Update: simulate a condition where required parameters are missing
    Object[][] input = new Object[][] { { "param1", true }, { "param2", true }, { "param3", false }, { "param4", false } };
    List<RangerServiceConfigDef> configDefs = _utils.createServiceConditionDefs(input);
    RangerServiceDef serviceDef = mock(RangerServiceDef.class);
    when(serviceDef.getConfigs()).thenReturn(configDefs);
    // wire this service def into store
    when(_store.getServiceDefByName("aType")).thenReturn(serviceDef);
    // create a service with some require parameters missing
    RangerService service = mock(RangerService.class);
    when(service.getType()).thenReturn("aType");
    when(service.getName()).thenReturn("aName");
    // required parameters param2 is missing
    String[] params = new String[] { "param1", "param3", "param4", "param5" };
    Map<String, String> paramMap = _utils.createMap(params);
    when(service.getConfigs()).thenReturn(paramMap);
    // service does not exist in the store
    when(_store.getServiceByName("aService")).thenReturn(null);
    for (Action action : cu) {
        // it should be invalid
        checkFailure_isValid(_validator, service, action, _failures, "missing", "configuration", "param2");
    }
}
Also used : Action(org.apache.ranger.plugin.model.validation.RangerValidator.Action) RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 27 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestRangerValidator method test_getResourceNames.

@Test
public void test_getResourceNames() {
    // passing in null service def
    Set<String> accessTypes = _validator.getMandatoryResourceNames((RangerServiceDef) null);
    Assert.assertTrue(accessTypes.isEmpty());
    // that has null or empty access type def
    RangerServiceDef serviceDef = mock(RangerServiceDef.class);
    when(serviceDef.getResources()).thenReturn(null);
    accessTypes = _validator.getMandatoryResourceNames(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    List<RangerResourceDef> resourceDefs = new ArrayList<>();
    when(serviceDef.getResources()).thenReturn(resourceDefs);
    accessTypes = _validator.getMandatoryResourceNames(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    // having null accesstypedefs
    resourceDefs.add(null);
    accessTypes = _validator.getMandatoryResourceNames(serviceDef);
    Assert.assertTrue(accessTypes.isEmpty());
    // access type defs with null empty blank names are skipped, spaces within names are preserved
    Object[][] data = { // all good
    { "a", null, null, true }, // this should put a null element in the resource def!
    null, // mandatory field is null, i.e. false
    { "b", null, null, null }, // non-mandatory field false - upper case
    { "c", null, null, false }, // resource specified in upper case
    { "D", null, null, true }, // all good
    { "E", null, null, false } };
    resourceDefs.addAll(_utils.createResourceDefs(data));
    accessTypes = _validator.getMandatoryResourceNames(serviceDef);
    Assert.assertEquals(2, accessTypes.size());
    Assert.assertTrue(accessTypes.contains("a"));
    // name should come back lower case
    Assert.assertTrue(accessTypes.contains("d"));
    accessTypes = _validator.getAllResourceNames(serviceDef);
    Assert.assertEquals(5, accessTypes.size());
    Assert.assertTrue(accessTypes.contains("b"));
    Assert.assertTrue(accessTypes.contains("c"));
    Assert.assertTrue(accessTypes.contains("e"));
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) Test(org.junit.Test)

Example 28 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestRangerValidator method test_getRequiredParameters.

@Test
public void test_getRequiredParameters() {
    // reasonable protection against null things
    Set<String> parameters = _validator.getRequiredParameters(null);
    Assert.assertNotNull(parameters);
    Assert.assertTrue(parameters.isEmpty());
    RangerServiceDef serviceDef = mock(RangerServiceDef.class);
    when(serviceDef.getConfigs()).thenReturn(null);
    parameters = _validator.getRequiredParameters(null);
    Assert.assertNotNull(parameters);
    Assert.assertTrue(parameters.isEmpty());
    List<RangerServiceConfigDef> configs = new ArrayList<>();
    when(serviceDef.getConfigs()).thenReturn(configs);
    parameters = _validator.getRequiredParameters(null);
    Assert.assertNotNull(parameters);
    Assert.assertTrue(parameters.isEmpty());
    Object[][] input = new Object[][] { { "param1", false }, { "param2", true }, { "param3", true }, { "param4", false } };
    configs = _utils.createServiceConditionDefs(input);
    when(serviceDef.getConfigs()).thenReturn(configs);
    parameters = _validator.getRequiredParameters(serviceDef);
    Assert.assertTrue("result does not contain: param2", parameters.contains("param2"));
    Assert.assertTrue("result does not contain: param3", parameters.contains("param3"));
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class TestRangerValidator method test_getValidationRegExes.

@Test
public void test_getValidationRegExes() {
    // passing in null service def
    Map<String, String> regExMap = _validator.getValidationRegExes((RangerServiceDef) null);
    Assert.assertTrue(regExMap.isEmpty());
    // that has null or empty access type def
    RangerServiceDef serviceDef = mock(RangerServiceDef.class);
    when(serviceDef.getResources()).thenReturn(null);
    regExMap = _validator.getValidationRegExes(serviceDef);
    Assert.assertTrue(regExMap.isEmpty());
    List<RangerResourceDef> resourceDefs = new ArrayList<>();
    when(serviceDef.getResources()).thenReturn(resourceDefs);
    regExMap = _validator.getValidationRegExes(serviceDef);
    Assert.assertTrue(regExMap.isEmpty());
    // having null accesstypedefs
    resourceDefs.add(null);
    regExMap = _validator.getValidationRegExes(serviceDef);
    Assert.assertTrue(regExMap.isEmpty());
    // access type defs with null empty blank names are skipped, spaces within names are preserved
    String[][] data = { // null-regex
    { "a", null }, // this should put a null element in the resource def!
    null, // valid
    { "b", "regex1" }, // empty regex
    { "c", "" }, // valid
    { "d", "regex2" }, // blank regex
    { "e", "   " }, // all good
    { "f", "regex3" } };
    resourceDefs.addAll(_utils.createResourceDefsWithRegEx(data));
    regExMap = _validator.getValidationRegExes(serviceDef);
    Assert.assertEquals(3, regExMap.size());
    Assert.assertEquals("regex1", regExMap.get("b"));
    Assert.assertEquals("regex2", regExMap.get("d"));
    Assert.assertEquals("regex3", regExMap.get("f"));
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) Test(org.junit.Test)

Example 30 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class AbstractServiceStore method postUpdate.

protected void postUpdate(RangerBaseModelObject obj) throws Exception {
    if (obj instanceof RangerServiceDef) {
        RangerServiceDef serviceDef = (RangerServiceDef) obj;
        updateTagServiceDefForUpdatingAccessTypes(serviceDef);
        updateServicesForServiceDefUpdate(serviceDef);
    }
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Aggregations

RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)105 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 XXServiceDef (org.apache.ranger.entity.XXServiceDef)18 Date (java.util.Date)15 HashMap (java.util.HashMap)13 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)13 RangerService (org.apache.ranger.plugin.model.RangerService)12 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)12 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)12 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)11 VXString (org.apache.ranger.view.VXString)10 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)9 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)9 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)9 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)8 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)8 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)8 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)7