Search in sources :

Example 1 with HandshakeOutcome

use of org.neo4j.bolt.transport.HandshakeOutcome in project neo4j by neo4j.

the class ProtocolChooserTest method shouldChooseFirstAvailableProtocol.

@Test
public void shouldChooseFirstAvailableProtocol() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, factory);
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(outcome, equalTo(PROTOCOL_CHOSEN));
    assertThat(chooser.chosenProtocol(), equalTo(protocol));
}
Also used : ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 2 with HandshakeOutcome

use of org.neo4j.bolt.transport.HandshakeOutcome in project neo4j by neo4j.

the class ProtocolChooserTest method shouldRejectIfInsecureHandshake.

@Test
public void shouldRejectIfInsecureHandshake() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, mock(BiFunction.class));
    ProtocolChooser chooser = new ProtocolChooser(available, true, false);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(outcome, equalTo(INSECURE_HANDSHAKE));
    assertThat(chooser.chosenProtocol(), nullValue());
}
Also used : BiFunction(java.util.function.BiFunction) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 3 with HandshakeOutcome

use of org.neo4j.bolt.transport.HandshakeOutcome in project neo4j by neo4j.

the class ProtocolChooserTest method shouldHandleFragmentedMessage.

@Test
public void shouldHandleFragmentedMessage() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, factory);
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome firstOutcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60 }), ch);
    // When
    HandshakeOutcome secondOutcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0xB0, (byte) 0x17 }), ch);
    HandshakeOutcome thirdOutcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 0, 0 }), ch);
    HandshakeOutcome fourthOutcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(firstOutcome, equalTo(PARTIAL_HANDSHAKE));
    assertThat(secondOutcome, equalTo(PARTIAL_HANDSHAKE));
    assertThat(thirdOutcome, equalTo(PARTIAL_HANDSHAKE));
    assertThat(fourthOutcome, equalTo(PROTOCOL_CHOSEN));
    assertThat(chooser.chosenProtocol(), equalTo(protocol));
}
Also used : ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 4 with HandshakeOutcome

use of org.neo4j.bolt.transport.HandshakeOutcome in project neo4j by neo4j.

the class ProtocolChooserTest method shouldRejectIfInvalidHandshake.

@Test
public void shouldRejectIfInvalidHandshake() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, mock(BiFunction.class));
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0xDE, (byte) 0xAD, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), ch);
    // Then
    assertThat(outcome, equalTo(INVALID_HANDSHAKE));
    assertThat(chooser.chosenProtocol(), nullValue());
}
Also used : BiFunction(java.util.function.BiFunction) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Example 5 with HandshakeOutcome

use of org.neo4j.bolt.transport.HandshakeOutcome in project neo4j by neo4j.

the class ProtocolChooserTest method shouldFallBackToNoneProtocolIfNoMatch.

@Test
public void shouldFallBackToNoneProtocolIfNoMatch() throws Throwable {
    // Given
    when(factory.apply(ch, true)).thenReturn(protocol);
    available.put(1L, mock(BiFunction.class));
    ProtocolChooser chooser = new ProtocolChooser(available, false, true);
    // When
    HandshakeOutcome outcome = chooser.handleVersionHandshakeChunk(wrappedBuffer(new byte[] { (byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4 }), ch);
    // Then
    assertThat(outcome, equalTo(NO_APPLICABLE_PROTOCOL));
    assertThat(chooser.chosenProtocol(), nullValue());
}
Also used : BiFunction(java.util.function.BiFunction) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) HandshakeOutcome(org.neo4j.bolt.transport.HandshakeOutcome) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 HandshakeOutcome (org.neo4j.bolt.transport.HandshakeOutcome)7 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)7 BiFunction (java.util.function.BiFunction)3 ByteBuf (io.netty.buffer.ByteBuf)1