Search in sources :

Example 6 with RangerSecurityZone

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

the class RangerSecurityZoneValidatorTest method testIsValidSecurityZoneForDeleteWithWrongNameReturnFalse.

@Test
public void testIsValidSecurityZoneForDeleteWithWrongNameReturnFalse() throws Exception {
    RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
    Mockito.when(_store.getSecurityZone(suppliedSecurityZone.getName())).thenReturn(null);
    List<ValidationFailureDetails> failures = new ArrayList<ValidationFailureDetails>();
    boolean isValid = rangerSecurityZoneValidator.isValid(suppliedSecurityZone.getName(), RangerValidator.Action.DELETE, failures);
    Assert.assertFalse(isValid);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with RangerSecurityZone

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

the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneWithoutNameForCreate.

@Test
public void testValidateSecurityZoneWithoutNameForCreate() throws Exception {
    RangerSecurityZone suppliedSecurityZone = new RangerSecurityZone();
    suppliedSecurityZone.setName(null);
    try {
        rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
    } catch (Exception ex) {
        Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3035], reason[Internal error: missing field[name]], field[name], subfield[null], type[missing] ");
    }
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) Test(org.junit.Test)

Example 8 with RangerSecurityZone

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

the class RangerSecurityZoneValidatorTest method testIsValidSecurityZoneForDeleteWithWrongIdReturnFalse.

@Test
public void testIsValidSecurityZoneForDeleteWithWrongIdReturnFalse() throws Exception {
    RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
    Mockito.when(_store.getSecurityZone(suppliedSecurityZone.getId())).thenReturn(null);
    List<ValidationFailureDetails> failures = new ArrayList<ValidationFailureDetails>();
    boolean isValid = rangerSecurityZoneValidator.isValid(suppliedSecurityZone.getId(), RangerValidator.Action.DELETE, failures);
    Assert.assertFalse(isValid);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with RangerSecurityZone

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

the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneWitoutServicesAdminUserAdminUserGroupAuditUserAuditUserGroupForCreateThrowsError.

@Test
public void testValidateSecurityZoneWitoutServicesAdminUserAdminUserGroupAuditUserAuditUserGroupForCreateThrowsError() throws Exception {
    RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
    suppliedSecurityZone.setAdminUserGroups(null);
    suppliedSecurityZone.setAdminUsers(null);
    suppliedSecurityZone.setAuditUserGroups(null);
    suppliedSecurityZone.setAuditUsers(null);
    suppliedSecurityZone.setServices(null);
    Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
    try {
        rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
    } catch (Exception ex) {
        Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3044], reason[No services specified for security-zone:[MyZone]], field[services], subfield[null], type[missing] (1) Validation failure: error code[3038], reason[both users and user-groups collections for the security zone were null/empty], field[security zone admin users/user-groups], subfield[null], type[missing] (2) Validation failure: error code[3038], reason[both users and user-groups collections for the security zone were null/empty], field[security zone audit users/user-groups], subfield[null], type[missing] ");
    }
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) Test(org.junit.Test)

Example 10 with RangerSecurityZone

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

the class RangerSecurityZoneValidatorTest method testIsValidSecurityZoneIdForDeleteWithWrongActionTypeReturnFalse.

@Test
public void testIsValidSecurityZoneIdForDeleteWithWrongActionTypeReturnFalse() throws Exception {
    RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
    List<ValidationFailureDetails> failures = new ArrayList<ValidationFailureDetails>();
    boolean isValid = rangerSecurityZoneValidator.isValid(suppliedSecurityZone.getId(), RangerValidator.Action.UPDATE, failures);
    Assert.assertFalse(isValid);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)68 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)27 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)16 WebApplicationException (javax.ws.rs.WebApplicationException)14 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 RangerService (org.apache.ranger.plugin.model.RangerService)11 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)10 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 XXTrxLog (org.apache.ranger.entity.XXTrxLog)9 RangerSecurityZoneService (org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService)7 HashMap (java.util.HashMap)6 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)3