Search in sources :

Example 1 with ZpeMatch

use of com.yahoo.athenz.zpe.match.ZpeMatch in project athenz by yahoo.

the class ZpeUpdPolLoader method getMatchObject.

ZpeMatch getMatchObject(String value) {
    ZpeMatch match = null;
    if ("*".equals(value)) {
        match = new ZpeMatchAll();
    } else {
        int anyCharMatch = value.indexOf('*');
        int singleCharMatch = value.indexOf('?');
        if (anyCharMatch == -1 && singleCharMatch == -1) {
            match = new ZpeMatchEqual(value);
        } else if (anyCharMatch == value.length() - 1 && singleCharMatch == -1) {
            match = new ZpeMatchStartsWith(value.substring(0, value.length() - 1));
        } else {
            match = new ZpeMatchRegex(value);
        }
    }
    return match;
}
Also used : ZpeMatchRegex(com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex) ZpeMatchStartsWith(com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith) ZpeMatchEqual(com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) ZpeMatchAll(com.yahoo.athenz.zpe.match.impl.ZpeMatchAll)

Example 2 with ZpeMatch

use of com.yahoo.athenz.zpe.match.ZpeMatch in project athenz by yahoo.

the class TestZpeMatch method testGetMatchAll.

@Test
public void testGetMatchAll() {
    try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
        ZpeMatch matchObject = loader.getMatchObject("*");
        assertTrue(matchObject instanceof ZpeMatchAll);
        assertTrue(matchObject.matches("abc"));
        assertTrue(matchObject.matches("false"));
        assertTrue(matchObject.matches("whatever"));
    }
}
Also used : ZpeUpdPolLoader(com.yahoo.athenz.zpe.ZpeUpdPolLoader) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) ZpeMatchAll(com.yahoo.athenz.zpe.match.impl.ZpeMatchAll) Test(org.testng.annotations.Test)

Example 3 with ZpeMatch

use of com.yahoo.athenz.zpe.match.ZpeMatch in project athenz by yahoo.

the class TestZpeMatch method testGetMatchEqual.

@Test
public void testGetMatchEqual() {
    try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
        ZpeMatch matchObject = loader.getMatchObject("coretech");
        assertTrue(matchObject instanceof ZpeMatchEqual);
        assertTrue(matchObject.matches("coretech"));
        // failures
        // random data
        assertFalse(matchObject.matches("whatever"));
        // extra A
        assertFalse(matchObject.matches("coretechA"));
        // missing h
        assertFalse(matchObject.matches("coretec"));
    }
}
Also used : ZpeUpdPolLoader(com.yahoo.athenz.zpe.ZpeUpdPolLoader) ZpeMatchEqual(com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) Test(org.testng.annotations.Test)

Example 4 with ZpeMatch

use of com.yahoo.athenz.zpe.match.ZpeMatch in project athenz by yahoo.

the class TestZpeMatch method testGetMatchStartsWith.

@Test
public void testGetMatchStartsWith() {
    try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
        ZpeMatch matchObject = loader.getMatchObject("coretech*");
        assertTrue(matchObject instanceof ZpeMatchStartsWith);
        assertTrue(matchObject.matches("coretech"));
        assertTrue(matchObject.matches("coretechtest"));
        assertTrue(matchObject.matches("coretechtesttest"));
        // failures
        // random data
        assertFalse(matchObject.matches("whatever"));
        // missing h
        assertFalse(matchObject.matches("coretec"));
        // missing h + extra A
        assertFalse(matchObject.matches("coretecA"));
    }
}
Also used : ZpeUpdPolLoader(com.yahoo.athenz.zpe.ZpeUpdPolLoader) ZpeMatchStartsWith(com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) Test(org.testng.annotations.Test)

Example 5 with ZpeMatch

use of com.yahoo.athenz.zpe.match.ZpeMatch in project athenz by yahoo.

the class TestZpeMatch method testGetMatchRegex.

@Test
public void testGetMatchRegex() {
    try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
        ZpeMatch matchObject = loader.getMatchObject("coretech?test*");
        assertTrue(matchObject instanceof ZpeMatchRegex);
        assertTrue(matchObject.matches("coretechAtest"));
        assertTrue(matchObject.matches("coretechbtestgreat"));
        // failures
        // random data
        assertFalse(matchObject.matches("whatever"));
        // missing ?
        assertFalse(matchObject.matches("coretechtestgreat"));
    }
}
Also used : ZpeUpdPolLoader(com.yahoo.athenz.zpe.ZpeUpdPolLoader) ZpeMatchRegex(com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) Test(org.testng.annotations.Test)

Aggregations

ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)9 Test (org.testng.annotations.Test)5 ZpeUpdPolLoader (com.yahoo.athenz.zpe.ZpeUpdPolLoader)4 ZpeMatchEqual (com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual)4 ZpeMatchAll (com.yahoo.athenz.zpe.match.impl.ZpeMatchAll)3 ZpeMatchRegex (com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex)3 ZpeMatchStartsWith (com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith)3 Struct (com.yahoo.rdl.Struct)3 Assertion (com.yahoo.athenz.zts.Assertion)1 AssertionEffect (com.yahoo.athenz.zts.AssertionEffect)1 DomainSignedPolicyData (com.yahoo.athenz.zts.DomainSignedPolicyData)1 Policy (com.yahoo.athenz.zts.Policy)1 PolicyData (com.yahoo.athenz.zts.PolicyData)1 SignedPolicyData (com.yahoo.athenz.zts.SignedPolicyData)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1