Search in sources :

Example 1 with ProxyBeginExFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW in project zilla by aklivity.

the class ProxyFunctionsTest method shouldGenerateInet4BeginExtension.

@Test
public void shouldGenerateInet4BeginExtension() throws UnknownHostException {
    byte[] build = ProxyFunctions.beginEx().typeId(0x01).addressInet4().protocol("stream").source("192.168.0.1").destination("192.168.0.254").sourcePort(32768).destinationPort(443).build().info().alpn("echo").authority("example.com").identity(fromHex("12345678")).namespace("example").secure().version("TLSv1.3").cipher("ECDHE-RSA-AES128-GCM-SHA256").signature("SHA256").name("name@domain").key("RSA2048").build().build().build();
    DirectBuffer buffer = new UnsafeBuffer(build);
    ProxyBeginExFW beginEx = new ProxyBeginExFW().wrap(buffer, 0, buffer.capacity());
    assertNotNull(beginEx);
    assertEquals(0x01, beginEx.typeId());
    assertEquals(INET4, beginEx.address().kind());
    assertEquals(STREAM, beginEx.address().inet4().protocol().get());
    assertEquals(new UnsafeBuffer(fromHex("c0a80001")), beginEx.address().inet4().source().value());
    assertEquals(new UnsafeBuffer(fromHex("c0a800fe")), beginEx.address().inet4().destination().value());
    assertEquals(32768, beginEx.address().inet4().sourcePort());
    assertEquals(443, beginEx.address().inet4().destinationPort());
    ProxyInfoFW info = new ProxyInfoFW();
    final DirectBuffer infos = beginEx.infos().items();
    for (int index = 0, offset = 0; offset < infos.capacity(); index++) {
        info.wrap(infos, offset, infos.capacity());
        switch(index) {
            case 0:
                assertEquals(ALPN, info.kind());
                assertEquals("echo", info.alpn().asString());
                break;
            case 1:
                assertEquals(AUTHORITY, info.kind());
                assertEquals("example.com", info.authority().asString());
                break;
            case 2:
                assertEquals(IDENTITY, info.kind());
                assertEquals(new UnsafeBuffer(fromHex("12345678")), info.identity().value().value());
                break;
            case 3:
                assertEquals(NAMESPACE, info.kind());
                assertEquals("example", info.namespace().asString());
                break;
            case 4:
                assertEquals(SECURE, info.kind());
                assertEquals(VERSION, info.secure().kind());
                assertEquals("TLSv1.3", info.secure().version().asString());
                break;
            case 5:
                assertEquals(SECURE, info.kind());
                assertEquals(CIPHER, info.secure().kind());
                assertEquals("ECDHE-RSA-AES128-GCM-SHA256", info.secure().cipher().asString());
                break;
            case 6:
                assertEquals(SECURE, info.kind());
                assertEquals(SIGNATURE, info.secure().kind());
                assertEquals("SHA256", info.secure().signature().asString());
                break;
            case 7:
                assertEquals(SECURE, info.kind());
                assertEquals(NAME, info.secure().kind());
                assertEquals("name@domain", info.secure().name().asString());
                break;
            case 8:
                assertEquals(SECURE, info.kind());
                assertEquals(KEY, info.secure().kind());
                assertEquals("RSA2048", info.secure().key().asString());
                break;
        }
        offset = info.limit();
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Example 2 with ProxyBeginExFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW in project zilla by aklivity.

the class ProxyFunctionsTest method shouldGenerateInet6BeginExtension.

@Test
public void shouldGenerateInet6BeginExtension() throws UnknownHostException {
    byte[] build = ProxyFunctions.beginEx().typeId(0x01).addressInet6().protocol("stream").source("fd12:3456:789a:1::1").destination("fd12:3456:789a:1::fe").sourcePort(32768).destinationPort(443).build().build();
    DirectBuffer buffer = new UnsafeBuffer(build);
    ProxyBeginExFW beginEx = new ProxyBeginExFW().wrap(buffer, 0, buffer.capacity());
    assertNotNull(beginEx);
    assertEquals(0x01, beginEx.typeId());
    assertEquals(INET6, beginEx.address().kind());
    assertEquals(STREAM, beginEx.address().inet6().protocol().get());
    assertEquals(new UnsafeBuffer(fromHex("fd123456789a00010000000000000001")), beginEx.address().inet6().source().value());
    assertEquals(new UnsafeBuffer(fromHex("fd123456789a000100000000000000fe")), beginEx.address().inet6().destination().value());
    assertEquals(32768, beginEx.address().inet6().sourcePort());
    assertEquals(443, beginEx.address().inet6().destinationPort());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Example 3 with ProxyBeginExFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW in project zilla by aklivity.

the class ProxyFunctionsTest method shouldGenerateUnixBeginExtension.

@Test
public void shouldGenerateUnixBeginExtension() throws UnknownHostException {
    byte[] build = ProxyFunctions.beginEx().typeId(0x01).addressUnix().protocol("stream").source("source-1234").destination("destination-5678").build().build();
    DirectBuffer buffer = new UnsafeBuffer(build);
    ProxyBeginExFW beginEx = new ProxyBeginExFW().wrap(buffer, 0, buffer.capacity());
    assertNotNull(beginEx);
    assertEquals(0x01, beginEx.typeId());
    assertEquals(UNIX, beginEx.address().kind());
    assertEquals(STREAM, beginEx.address().unix().protocol().get());
    assertEquals(paddedUtf8("source-1234", 108), beginEx.address().unix().source().value());
    assertEquals(paddedUtf8("destination-5678", 108), beginEx.address().unix().destination().value());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Example 4 with ProxyBeginExFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW in project zilla by aklivity.

the class ProxyFunctionsTest method shouldGenerateNoneBeginExtension.

@Test
public void shouldGenerateNoneBeginExtension() throws UnknownHostException {
    byte[] build = ProxyFunctions.beginEx().typeId(0x01).addressNone().build().info().alpn("echo").authority("example.com").identity(fromHex("12345678")).namespace("example").secure().version("TLSv1.3").cipher("ECDHE-RSA-AES128-GCM-SHA256").signature("SHA256").name("name@domain").key("RSA2048").build().build().build();
    DirectBuffer buffer = new UnsafeBuffer(build);
    ProxyBeginExFW beginEx = new ProxyBeginExFW().wrap(buffer, 0, buffer.capacity());
    assertNotNull(beginEx);
    assertEquals(0x01, beginEx.typeId());
    assertEquals(NONE, beginEx.address().kind());
    ProxyInfoFW info = new ProxyInfoFW();
    final DirectBuffer infos = beginEx.infos().items();
    for (int index = 0, offset = 0; offset < infos.capacity(); index++) {
        info.wrap(infos, offset, infos.capacity());
        switch(index) {
            case 0:
                assertEquals(ALPN, info.kind());
                assertEquals("echo", info.alpn().asString());
                break;
            case 1:
                assertEquals(AUTHORITY, info.kind());
                assertEquals("example.com", info.authority().asString());
                break;
            case 2:
                assertEquals(IDENTITY, info.kind());
                assertEquals(new UnsafeBuffer(fromHex("12345678")), info.identity().value().value());
                break;
            case 3:
                assertEquals(NAMESPACE, info.kind());
                assertEquals("example", info.namespace().asString());
                break;
            case 4:
                assertEquals(SECURE, info.kind());
                assertEquals(VERSION, info.secure().kind());
                assertEquals("TLSv1.3", info.secure().version().asString());
                break;
            case 5:
                assertEquals(SECURE, info.kind());
                assertEquals(CIPHER, info.secure().kind());
                assertEquals("ECDHE-RSA-AES128-GCM-SHA256", info.secure().cipher().asString());
                break;
            case 6:
                assertEquals(SECURE, info.kind());
                assertEquals(SIGNATURE, info.secure().kind());
                assertEquals("SHA256", info.secure().signature().asString());
                break;
            case 7:
                assertEquals(SECURE, info.kind());
                assertEquals(NAME, info.secure().kind());
                assertEquals("name@domain", info.secure().name().asString());
                break;
            case 8:
                assertEquals(SECURE, info.kind());
                assertEquals(KEY, info.secure().kind());
                assertEquals("RSA2048", info.secure().key().asString());
                break;
        }
        offset = info.limit();
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Example 5 with ProxyBeginExFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW in project zilla by aklivity.

the class ProxyFunctionsTest method shouldGenerateInetBeginExtension.

@Test
public void shouldGenerateInetBeginExtension() throws UnknownHostException {
    byte[] build = ProxyFunctions.beginEx().typeId(0x01).addressInet().protocol("stream").source("*").destination("example.com").sourcePort(32768).destinationPort(443).build().info().alpn("echo").authority("example.com").identity(fromHex("12345678")).namespace("example").secure().version("TLSv1.3").cipher("ECDHE-RSA-AES128-GCM-SHA256").signature("SHA256").name("name@domain").key("RSA2048").build().build().build();
    DirectBuffer buffer = new UnsafeBuffer(build);
    ProxyBeginExFW beginEx = new ProxyBeginExFW().wrap(buffer, 0, buffer.capacity());
    assertNotNull(beginEx);
    assertEquals(0x01, beginEx.typeId());
    assertEquals(INET, beginEx.address().kind());
    assertEquals(STREAM, beginEx.address().inet().protocol().get());
    assertEquals("*", beginEx.address().inet().source().asString());
    assertEquals("example.com", beginEx.address().inet().destination().asString());
    assertEquals(32768, beginEx.address().inet().sourcePort());
    assertEquals(443, beginEx.address().inet().destinationPort());
    ProxyInfoFW info = new ProxyInfoFW();
    final DirectBuffer infos = beginEx.infos().items();
    for (int index = 0, offset = 0; offset < infos.capacity(); index++) {
        info.wrap(infos, offset, infos.capacity());
        switch(index) {
            case 0:
                assertEquals(ALPN, info.kind());
                assertEquals("echo", info.alpn().asString());
                break;
            case 1:
                assertEquals(AUTHORITY, info.kind());
                assertEquals("example.com", info.authority().asString());
                break;
            case 2:
                assertEquals(IDENTITY, info.kind());
                assertEquals(new UnsafeBuffer(fromHex("12345678")), info.identity().value().value());
                break;
            case 3:
                assertEquals(NAMESPACE, info.kind());
                assertEquals("example", info.namespace().asString());
                break;
            case 4:
                assertEquals(SECURE, info.kind());
                assertEquals(VERSION, info.secure().kind());
                assertEquals("TLSv1.3", info.secure().version().asString());
                break;
            case 5:
                assertEquals(SECURE, info.kind());
                assertEquals(CIPHER, info.secure().kind());
                assertEquals("ECDHE-RSA-AES128-GCM-SHA256", info.secure().cipher().asString());
                break;
            case 6:
                assertEquals(SECURE, info.kind());
                assertEquals(SIGNATURE, info.secure().kind());
                assertEquals("SHA256", info.secure().signature().asString());
                break;
            case 7:
                assertEquals(SECURE, info.kind());
                assertEquals(NAME, info.secure().kind());
                assertEquals("name@domain", info.secure().name().asString());
                break;
            case 8:
                assertEquals(SECURE, info.kind());
                assertEquals(KEY, info.secure().kind());
                assertEquals("RSA2048", info.secure().key().asString());
                break;
        }
        offset = info.limit();
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ProxyInfoFW(io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ProxyBeginExFW(io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW) Test(org.junit.Test)

Aggregations

ProxyBeginExFW (io.aklivity.zilla.specs.binding.proxy.internal.types.stream.ProxyBeginExFW)5 DirectBuffer (org.agrona.DirectBuffer)5 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)5 Test (org.junit.Test)5 ProxyInfoFW (io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW)3