def test_client_socket_send(fake_socket, packets, state): body = TACACSAuthenticationStart('user123', TAC_PLUS_AUTHEN_TYPE_ASCII) client = TACACSClient('127.0.0.1', 49, None, session_id=12345) client._sock = fake_socket packet = client.send(body, TAC_PLUS_AUTHEN) assert isinstance(packet, TACACSPacket) reply = TACACSAuthenticationReply.unpacked(packet.body) assert getattr(reply, state) is True # the first 12 bytes of the packet represent the header fake_socket.buff.seek(0) sent_header, sent_body = (fake_socket.buff.read(12), fake_socket.buff.read()) body_length = TACACSHeader.unpacked(sent_header).length assert len(sent_body) == body_length assert body.packed == sent_body
def test_client_socket_send_wrong_headers(fake_socket, packets): body = TACACSAuthenticationStart('user123', TAC_PLUS_AUTHEN_TYPE_ASCII) client = TACACSClient('127.0.0.1', 49, None, session_id=12345) client._sock = fake_socket with pytest.raises(socket.error): client.send(body, TAC_PLUS_AUTHEN)