Search in sources :

Example 36 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class ProxyFunctionsTest method shouldFailWhenTypeIdDoNotMatch.

@Test(expected = Exception.class)
public void shouldFailWhenTypeIdDoNotMatch() throws Exception {
    BytesMatcher matcher = ProxyFunctions.matchBeginEx().typeId(0x01).build();
    ByteBuffer byteBuf = ByteBuffer.allocate(1024);
    new ProxyBeginExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x02).address(a -> a.inet4(i -> i.protocol(p -> p.set(STREAM)).source(new UnsafeBuffer(fromHex("c0a80001")), 0, 4).destination(new UnsafeBuffer(fromHex("c0a800fe")), 0, 4).sourcePort(32768).destinationPort(443))).build();
    matcher.match(byteBuf);
}
Also used : NONE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.NONE) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AUTHORITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.AUTHORITY) VERSION(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.VERSION) ByteBuffer(java.nio.ByteBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) Assert.assertSame(org.junit.Assert.assertSame) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) FunctionMapper(javax.el.FunctionMapper) BitUtil.fromHex(org.agrona.BitUtil.fromHex) Method(java.lang.reflect.Method) KEY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.KEY) NAMESPACE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.NAMESPACE) SECURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.SECURE) INET4(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET4) Assert.assertNotNull(org.junit.Assert.assertNotNull) INET6(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET6) CIPHER(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.CIPHER) Test(org.junit.Test) STREAM(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressProtocol.STREAM) IDENTITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.IDENTITY) UnknownHostException(java.net.UnknownHostException) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Assert.assertNull(org.junit.Assert.assertNull) ExpressionContext(org.kaazing.k3po.lang.internal.el.ExpressionContext) ALPN(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.ALPN) NAME(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.NAME) INET(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET) UNIX(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.UNIX) ELContext(javax.el.ELContext) SIGNATURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.SIGNATURE) Assert.assertEquals(org.junit.Assert.assertEquals) DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 37 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class ProxyFunctionsTest method shouldNotMatchInetBeginExtensionIdentity.

@Test(expected = Exception.class)
public void shouldNotMatchInetBeginExtensionIdentity() throws Exception {
    BytesMatcher matcher = ProxyFunctions.matchBeginEx().typeId(0x01).info().identity(fromHex("12345679")).build().build();
    ByteBuffer byteBuf = ByteBuffer.allocate(1024);
    new ProxyBeginExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).address(a -> a.inet(i -> i.protocol(p -> p.set(STREAM)).source("*").destination("example.com").sourcePort(32768).destinationPort(443))).infosItem(i -> i.identity(id -> id.value(v -> v.set(fromHex("12345678"))))).build();
    assertNull(matcher.match(byteBuf));
}
Also used : NONE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.NONE) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AUTHORITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.AUTHORITY) VERSION(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.VERSION) ByteBuffer(java.nio.ByteBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) Assert.assertSame(org.junit.Assert.assertSame) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) FunctionMapper(javax.el.FunctionMapper) BitUtil.fromHex(org.agrona.BitUtil.fromHex) Method(java.lang.reflect.Method) KEY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.KEY) NAMESPACE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.NAMESPACE) SECURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.SECURE) INET4(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET4) Assert.assertNotNull(org.junit.Assert.assertNotNull) INET6(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET6) CIPHER(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.CIPHER) Test(org.junit.Test) STREAM(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressProtocol.STREAM) IDENTITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.IDENTITY) UnknownHostException(java.net.UnknownHostException) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Assert.assertNull(org.junit.Assert.assertNull) ExpressionContext(org.kaazing.k3po.lang.internal.el.ExpressionContext) ALPN(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.ALPN) NAME(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.NAME) INET(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET) UNIX(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.UNIX) ELContext(javax.el.ELContext) SIGNATURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.SIGNATURE) Assert.assertEquals(org.junit.Assert.assertEquals) DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Example 38 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class ProxyFunctionsTest method shouldMatchInet6BeginExtensionDestination.

@Test
public void shouldMatchInet6BeginExtensionDestination() throws Exception {
    BytesMatcher matcher = ProxyFunctions.matchBeginEx().typeId(0x01).addressInet6().destination("fd12:3456:789a:1::fe").build().build();
    ByteBuffer byteBuf = ByteBuffer.allocate(1024);
    new ProxyBeginExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).address(a -> a.inet6(i -> i.protocol(p -> p.set(STREAM)).source(new UnsafeBuffer(fromHex("fd123456789a00010000000000000001")), 0, 16).destination(new UnsafeBuffer(fromHex("fd123456789a000100000000000000fe")), 0, 16).sourcePort(32768).destinationPort(443))).build();
    assertNotNull(matcher.match(byteBuf));
}
Also used : NONE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.NONE) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) AUTHORITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.AUTHORITY) VERSION(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.VERSION) ByteBuffer(java.nio.ByteBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) Assert.assertSame(org.junit.Assert.assertSame) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) FunctionMapper(javax.el.FunctionMapper) BitUtil.fromHex(org.agrona.BitUtil.fromHex) Method(java.lang.reflect.Method) KEY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.KEY) NAMESPACE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.NAMESPACE) SECURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.SECURE) INET4(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET4) Assert.assertNotNull(org.junit.Assert.assertNotNull) INET6(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET6) CIPHER(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.CIPHER) Test(org.junit.Test) STREAM(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressProtocol.STREAM) IDENTITY(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.IDENTITY) UnknownHostException(java.net.UnknownHostException) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Assert.assertNull(org.junit.Assert.assertNull) ExpressionContext(org.kaazing.k3po.lang.internal.el.ExpressionContext) ALPN(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoType.ALPN) NAME(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.NAME) INET(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.INET) UNIX(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyAddressFamily.UNIX) ELContext(javax.el.ELContext) SIGNATURE(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxySecureInfoType.SIGNATURE) Assert.assertEquals(org.junit.Assert.assertEquals) DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 39 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class ProxyFunctionsTest method shouldFailWhenBufferIncomplete.

@Test(expected = Exception.class)
public void shouldFailWhenBufferIncomplete() throws Exception {
    BytesMatcher matcher = ProxyFunctions.matchBeginEx().typeId(0x01).build();
    ByteBuffer byteBuf = ByteBuffer.allocate(1);
    assertNull(matcher.match(byteBuf));
}
Also used : BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 40 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class KafkaFunctionsTest method shouldMatchProduceDataExtensionHeaderWithNullValue.

@Test
public void shouldMatchProduceDataExtensionHeaderWithNullValue() throws Exception {
    BytesMatcher matcher = KafkaFunctions.matchDataEx().produce().header("name", null).build().build();
    ByteBuffer byteBuf = ByteBuffer.allocate(1024);
    new KafkaDataExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).produce(p -> p.timestamp(12345678L).sequence(0).key(k -> k.length(5).value(v -> v.set("match".getBytes(UTF_8)))).headersItem(h -> h.nameLen(4).name(n -> n.set("name".getBytes(UTF_8))).valueLen(-1).value((OctetsFW) null))).build();
    assertNotNull(matcher.match(byteBuf));
}
Also used : KafkaDeltaType(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaDeltaType) KafkaDescribeBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDescribeBeginExFW) ExpressionFactory(javax.el.ExpressionFactory) KafkaDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDataExFW) KafkaSkip(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaSkip) KafkaBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) KafkaBootstrapBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBootstrapBeginExFW) KafkaOffsetFW(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaOffsetFW) ByteBuffer(java.nio.ByteBuffer) KafkaValueMatchFW(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaValueMatchFW) KafkaMergedFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedFlushExFW) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) KafkaFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFlushExFW) HEADER(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADER) Array32FW(io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW) KafkaMetaDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMetaDataExFW) MutableInteger(org.agrona.collections.MutableInteger) Before(org.junit.Before) KafkaMergedBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedBeginExFW) KafkaFetchFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchFlushExFW) ExpressionFactoryUtils.newExpressionFactory(org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.newExpressionFactory) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) KafkaMetaBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMetaBeginExFW) Test(org.junit.Test) HEADERS(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADERS) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) OctetsFW(io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW) Objects(java.util.Objects) KafkaFetchDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchDataExFW) Assert.assertNull(org.junit.Assert.assertNull) ExpressionContext(org.kaazing.k3po.lang.internal.el.ExpressionContext) KafkaDescribeDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDescribeDataExFW) KafkaFetchBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchBeginExFW) NOT(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.NOT) ValueExpression(javax.el.ValueExpression) KafkaApi(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaApi) KEY(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY) KafkaProduceBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceBeginExFW) ELContext(javax.el.ELContext) Assert.assertEquals(org.junit.Assert.assertEquals) KafkaMergedDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedDataExFW) KafkaProduceDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceDataExFW) DirectBuffer(org.agrona.DirectBuffer) OctetsFW(io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)142 BytesMatcher (org.kaazing.k3po.lang.el.BytesMatcher)142 ByteBuffer (java.nio.ByteBuffer)134 ELContext (javax.el.ELContext)129 DirectBuffer (org.agrona.DirectBuffer)129 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)129 Assert.assertEquals (org.junit.Assert.assertEquals)129 Assert.assertNotNull (org.junit.Assert.assertNotNull)129 Assert.assertNull (org.junit.Assert.assertNull)129 ExpressionContext (org.kaazing.k3po.lang.internal.el.ExpressionContext)129 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)69 Assert.assertTrue (org.junit.Assert.assertTrue)69 Method (java.lang.reflect.Method)65 FunctionMapper (javax.el.FunctionMapper)65 Assert.assertSame (org.junit.Assert.assertSame)65 ExpressionFactory (javax.el.ExpressionFactory)64 ValueExpression (javax.el.ValueExpression)64 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)64 Before (org.junit.Before)64 ExpressionFactoryUtils.newExpressionFactory (org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.newExpressionFactory)64