示例#1
0
文件: sasl.py 项目: migarbo1/SpyAgent
    def _send_sasl_node_and_wait_for(self, node):
        node = yield from protocol.send_and_wait_for(
            self.xmlstream,
            [node],
            [
                nonza.SASLChallenge,
                nonza.SASLFailure,
                nonza.SASLSuccess
            ],
            timeout=self.timeout
        )

        state = node.TAG[1]

        if state == "failure":
            xmpp_error = node.condition[1]
            text = node.text
            raise aiosasl.SASLFailure(xmpp_error, text=text)

        if hasattr(node, "payload"):
            payload = node.payload
        else:
            payload = None

        return state, payload
示例#2
0
    def _check_action(self, action, payload):
        try:
            (next_action,
             next_payload,
             new_state,
             result_payload) = self._action_sequence.pop(0)
        except ValueError:
            raise AssertionError(
                "SASL action performed unexpectedly: "
                "{} with payload {}".format(
                    action,
                    payload))

        self._state = new_state

        self._testobj.assertEqual(
            action,
            next_action,
            "SASL action sequence violated")

        self._testobj.assertEqual(
            payload,
            next_payload,
            "SASL payload expectation violated")

        if new_state == "failure" and action != "abort":
            opaque_error, text = result_payload
            raise aiosasl.SASLFailure(opaque_error, text=text)

        if result_payload is not None:
            result_payload = result_payload

        return new_state, result_payload
示例#3
0
    def test_reject_double_initiate_after_error(self):
        opaque_error = object()
        self.intf.initiate.side_effect = aiosasl.SASLFailure(
            opaque_error
        )

        with self.assertRaises(aiosasl.SASLFailure):
            run_coroutine(self.sm.initiate("foo", b"bar"))

        with self.assertRaisesRegexp(RuntimeError,
                                     "has already been called"):
            run_coroutine(self.sm.initiate("foo"))
示例#4
0
    def test_response_failure(self):
        opaque_error = object()
        self.sm._state = aiosasl.SASLState.CHALLENGE
        self.intf.respond.side_effect = aiosasl.SASLFailure(
            opaque_error
        )

        with self.assertRaises(aiosasl.SASLFailure):
            run_coroutine(
                self.sm.response(b"bar")
            )

        self.assertEqual(self.sm._state, aiosasl.SASLState.FAILURE)
示例#5
0
 def abort(self):
     try:
         next_state, payload = yield from self._send_sasl_node_and_wait_for(
             nonza.SASLAbort())
     except aiosasl.SASLFailure as err:
         self._state = "failure"
         if err.opaque_error != "aborted":
             raise
         return "failure", None
     else:
         raise aiosasl.SASLFailure(
             "aborted",
             text="unexpected non-failure after abort: "
             "{}".format(self._state))