Ejemplo n.º 1
0
def test_reject_negative_negotiation():
    opt = StreamParser.OptionNegotiation(
        OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.LOCAL, False
    )
    assert opt.refuse() == StreamParser.OptionNegotiation(
        OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.LOCAL, True
    )
Ejemplo n.º 2
0
def test_accept_negative_negotiation():
    opt = StreamParser.OptionNegotiation(
        OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.LOCAL, False
    )
    assert opt.accept() == StreamParser.OptionNegotiation(
        OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.LOCAL, False
    )
Ejemplo n.º 3
0
def test_stuffer_option_recognized(stuffer):
    stuffed = stuffer.stuff(
        StreamParser.OptionNegotiation(
            OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.PEER, False
        )
    )
    assert stuffed == (B.IAC.byte + B.DONT.byte + OPTIONS.TM.byte)
Ejemplo n.º 4
0
def test_stream_dont(stream_parser):
    events = stream_parser.stream_updates(
        [Tokenizer.Option(B.DONT, OPTIONS.TM, OPTIONS.TM.value)]
    )
    assert events == [
        StreamParser.OptionNegotiation(
            OPTIONS.TM, OPTIONS.TM.value, StreamParser.Host.LOCAL, False
        )
    ]
Ejemplo n.º 5
0
def test_integration(tokenizer, stream_parser):
    data = (
        b"Hel"
        + B.IAC.byte
        + B.NOP.byte
        + b"lo,\r"
        +
        # start a subneg
        B.IAC.byte
        + B.SB.byte
        + bytes([42])
        + b"abc"
        +
        # literal IAC SE as subneg data
        B.IAC.byte
        + B.IAC.byte
        + B.SE.byte
        + b"def"
        +
        # finish the subneg
        B.IAC.byte
        + B.SE.byte
        + b"\0wor"
        + B.IAC.byte
        + B.DO.byte
        + bytes([42])
        + b"ld!"
    )
    atomized = [bytes([b]) for b in data]  # process it one byte at a time

    toks = sum([tokenizer.tokens(b) for b in atomized], [])
    events = sum([stream_parser.stream_updates([tok]) for tok in toks], [])

    assert events == [
        StreamParser.UserData("H"),
        StreamParser.UserData("e"),
        StreamParser.UserData("l"),
        StreamParser.Command(B.NOP, B.NOP.value),
        StreamParser.UserData("l"),
        StreamParser.UserData("o"),
        StreamParser.UserData(","),
        StreamParser.OptionSubnegotiation(None, 42),
        StreamParser.UserData("\r"),
        StreamParser.UserData("w"),
        StreamParser.UserData("o"),
        StreamParser.UserData("r"),
        StreamParser.OptionNegotiation(None, 42, StreamParser.Host.LOCAL, True),
        StreamParser.UserData("l"),
        StreamParser.UserData("d"),
        StreamParser.UserData("!"),
    ]
Ejemplo n.º 6
0
def test_stuffer_option_unrecognized(stuffer):
    stuffed = stuffer.stuff(
        StreamParser.OptionNegotiation(None, 42, StreamParser.Host.PEER, False)
    )
    assert stuffed == (B.IAC.byte + B.DONT.byte + bytes([42]))
Ejemplo n.º 7
0
def test_stream_wont(stream_parser):
    events = stream_parser.stream_updates([Tokenizer.Option(B.WONT, None, 42)])
    assert events == [
        StreamParser.OptionNegotiation(None, 42, StreamParser.Host.PEER, False)
    ]
Ejemplo n.º 8
0
def test_stream_will(stream_parser):
    events = stream_parser.stream_updates([Tokenizer.Option(B.WILL, None, 42)])
    assert events == [
        StreamParser.OptionNegotiation(None, 42, StreamParser.Host.PEER, True)
    ]
Ejemplo n.º 9
0
 def make_negotiation(self, state):
     return StreamParser.OptionNegotiation(OPTIONS.ECHO, OPTIONS.ECHO.value,
                                           StreamParser.Host.LOCAL, state)