Search in sources :

Example 16 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class MessageDecoderTest method shouldThrowOnUnknownStructType.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldThrowOnUnknownStructType(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    PackedOutputArray out = new PackedOutputArray();
    Neo4jPack.Packer packer = packerUnderTest.newPacker(out);
    packer.packStructHeader(2, RunMessage.SIGNATURE);
    packer.pack("RETURN $x");
    packer.packMapHeader(1);
    packer.pack("x");
    packer.packStructHeader(0, (byte) 'A');
    var ex = assertThrows(BoltIOException.class, () -> unpack(out.bytes()));
    assertEquals("Struct types of 0x41 are not recognized.", ex.getMessage());
}
Also used : PackedOutputArray(org.neo4j.bolt.packstream.PackedOutputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class TransportUnauthenticatedConnectionErrorIT method createHelloWithOversizeDeclaredMap.

private byte[] createHelloWithOversizeDeclaredMap(Neo4jPack neo4jPack) throws IOException {
    PackedOutputArray out = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(out);
    packer.packStructHeader(2, HelloMessage.SIGNATURE);
    // Map claims to be huge when it isn't
    packer.packMapHeader(Integer.MAX_VALUE);
    packer.pack("x");
    packer.pack("Boom!");
    return out.bytes();
}
Also used : PackedOutputArray(org.neo4j.bolt.packstream.PackedOutputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack)

Example 18 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class TransportUnauthenticatedConnectionErrorIT method createHelloWithOversizeDeclaredList.

byte[] createHelloWithOversizeDeclaredList(Neo4jPack neo4jPack) throws IOException {
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(output);
    packer.packStructHeader(2, HelloMessage.SIGNATURE);
    packer.packMapHeader(1);
    packer.pack("x");
    // list claims to be huge when it isn't
    packer.packListHeader(Integer.MAX_VALUE);
    TextArray labels = ALICE.labels();
    for (int i = 0; i < labels.length(); i++) {
        String labelName = labels.stringValue(i);
        packer.pack(labelName);
    }
    return output.bytes();
}
Also used : PackedOutputArray(org.neo4j.bolt.packstream.PackedOutputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) TextArray(org.neo4j.values.storable.TextArray)

Example 19 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeWhenEmptyRoutingContextProvided.

@Test
void testShouldDecodeWhenEmptyRoutingContextProvided() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, meta);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Example 20 with Neo4jPack

use of org.neo4j.bolt.packstream.Neo4jPack in project neo4j by neo4j.

the class HelloMessageDecoderTest method testShouldDecodeRoutingContext.

@Test
void testShouldDecodeRoutingContext() throws Exception {
    Map<String, Object> meta = new HashMap<>();
    Map<String, Object> authToken;
    Map<String, String> parameterMap = new HashMap<>();
    RoutingContext routingContext = new RoutingContext(true, parameterMap);
    parameterMap.put("policy", "fast");
    parameterMap.put("region", "eu-west");
    Neo4jPack neo4jPack = newNeo4jPack();
    meta.put("user_agent", "My Driver");
    meta.put("routing", parameterMap);
    authToken = new HashMap<>(Map.copyOf(meta));
    authToken.remove("routing");
    HelloMessage originalMessage = new HelloMessage(meta, routingContext, authToken);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    // these two steps are executed before decoding in order to select a correct decoder
    unpacker.unpackStructHeader();
    unpacker.unpackStructSignature();
    RequestMessage deserializedMessage = decoder.decode(unpacker);
    assertHelloMessageMatches(originalMessage, deserializedMessage);
    assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) HelloMessage(org.neo4j.bolt.v41.messaging.request.HelloMessage) HashMap(java.util.HashMap) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) AuthTokenDecoderTest(org.neo4j.bolt.security.auth.AuthTokenDecoderTest) Test(org.junit.jupiter.api.Test)

Aggregations

Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)26 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)18 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)14 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)10 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)7 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)7 HashMap (java.util.HashMap)5 Test (org.junit.jupiter.api.Test)5 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)5 RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)5 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)5 AuthTokenDecoderTest (org.neo4j.bolt.security.auth.AuthTokenDecoderTest)5 HelloMessage (org.neo4j.bolt.v41.messaging.request.HelloMessage)5 BoltProtocolV4ComponentFactory.newNeo4jPack (org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack)4 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)4 PackedOutputArray (org.neo4j.bolt.packstream.PackedOutputArray)3 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)2 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)2 BoltProtocolV41ComponentFactory.newNeo4jPack (org.neo4j.bolt.v41.BoltProtocolV41ComponentFactory.newNeo4jPack)2 BoltProtocolV43ComponentFactory.newNeo4jPack (org.neo4j.bolt.v43.BoltProtocolV43ComponentFactory.newNeo4jPack)2