Search in sources :

Example 1 with ProxyInfoFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW 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 ProxyInfoFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW 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 3 with ProxyInfoFW

use of io.aklivity.zilla.specs.binding.proxy.internal.types.ProxyInfoFW 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

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