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());
}
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();
}
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();
}
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);
}
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);
}
Aggregations