Esempio n. 1
0
    def test_wait_for_auth(self):
        con = self._connection()
        p = Protocol(con, "foo")
        p._authed = True
        p._authed_event.set()

        p._wait_for_auth()
Esempio n. 2
0
    def test_auth_resp_invalid(self):
        con = self._with_pck((MSG_AUTH_RESP, dict(status=False)))

        p = Protocol(con, "foo")
        p._loop()

        ok_(not p.authenticated)
Esempio n. 3
0
    def test_accept_auth_resp(self):
        con = self._with_pck((MSG_AUTH_RESP, dict(status=True)))

        p = Protocol(con, "foo")

        p._loop()

        ok_(p.authenticated)
Esempio n. 4
0
    def test_responds_to_challenge(self, p):
        con = self._with_pck((MSG_CHALLENGE, dict(challenge="0" * 64)))
        p = Protocol(con, "foo")

        p._loop()

        con.send_packet.assert_called_once_with(
            MSG_AUTH, dict(signature=sentinel.signed))
Esempio n. 5
0
    def test_stop(self):
        con = self._connection()
        p = Protocol(con, "foo")
        th = p._th = Mock()

        p.stop()

        con.stop.assert_called_once()
        th.join.assert_called_once()
        th.kill.assert_called_once()
Esempio n. 6
0
    def _start(self):
        serv, cli, clifd = get_sockets()
        secret = "__NO_AUTH__"
        if self._secured:  # pragma: nocover
            raise RuntimeError("Secure connections are not supported yet")

        self._proc = open_process(clifd, secret)
        self._con = Connection(serv)
        self._proto = Protocol(self._con,
                               None if not self._secured else secret)
        self._proto.start()
Esempio n. 7
0
    def test_request_async(self):
        con = self._with_pck((MSG_RESPONSE, self._response_data))

        p = Protocol(con, "foo")
        p._authed = True

        args = dict(somearg=sentinel.somearg)
        handle = p.request(sentinel.mtd, **args)

        p._loop()

        # calling handle should wait the response
        ret = handle()

        eq_(ret, "foo")
        con.send_packet.assert_called_once_with(MSG_REQUEST, {
            "reqid": 1,
            "action": sentinel.mtd,
            "args": args
        })
Esempio n. 8
0
    def test_request_sync(self):
        con = self._with_pck((MSG_RESPONSE, self._response_data))

        p = Protocol(con, "foo")
        p._authed = True

        def fn():
            time.sleep(0.001)
            p._loop()

        th = gevent.Greenlet(fn)
        th.start()

        args = dict(somearg=sentinel.somearg)
        ret = p.request_sync(sentinel.mtd, timeout=1, **args)

        eq_(ret, "foo")
        con.send_packet.assert_called_once_with(MSG_REQUEST, {
            "reqid": 1,
            "action": sentinel.mtd,
            "args": args
        })
        th.join()
Esempio n. 9
0
    def test_start(self):
        con = self._connection()

        p = Protocol(con, "foo")
        p.start()
        con.send_packet.assert_called_once_with(ord('h'), {"hello": "hello"})