示例#1
0
    def test_catch_surplus_unmute(self):
        with self.xmlstream.mute():
            pass

        with self.assertRaisesRegex(AssertionError, "unexpected unmute"):
            run_coroutine(self.xmlstream.run_test([
                XMLStreamMock.Mute(),
            ], ))
示例#2
0
    def test_mute_unmute_cycle(self):
        with self.xmlstream.mute():
            run_coroutine(self.xmlstream.run_test([
                XMLStreamMock.Mute(),
            ], ))

        run_coroutine(self.xmlstream.run_test([
            XMLStreamMock.Unmute(),
        ], ))
示例#3
0
 def test_initiate_challenge(self):
     state, payload = self._run_test(self.sm.initiate("foo", b"bar"), [
         XMLStreamMock.Mute(),
         XMLStreamMock.Send(nonza.SASLAuth(mechanism="foo", payload=b"bar"),
                            response=XMLStreamMock.Receive(
                                nonza.SASLChallenge(payload=b"baz"))),
         XMLStreamMock.Unmute(),
     ])
     self.assertEqual(state, "challenge")
     self.assertEqual(payload, b"baz")
示例#4
0
 def test_initiate_success(self):
     state, payload = self._run_test(self.sm.initiate("foo", b"bar"), [
         XMLStreamMock.Mute(),
         XMLStreamMock.Send(nonza.SASLAuth(mechanism="foo", payload=b"bar"),
                            response=XMLStreamMock.Receive(
                                nonza.SASLSuccess())),
         XMLStreamMock.Unmute(),
     ])
     self.assertEqual(state, "success")
     self.assertIsNone(payload)
示例#5
0
    def test_response_success(self):
        self.sm._state = "challenge"

        state, payload = self._run_test(self.sm.respond(b"bar"), [
            XMLStreamMock.Mute(),
            XMLStreamMock.Send(nonza.SASLResponse(payload=b"bar"),
                               response=XMLStreamMock.Receive(
                                   nonza.SASLSuccess())),
            XMLStreamMock.Unmute(),
        ])
        self.assertEqual(state, "success")
        self.assertIsNone(payload)
示例#6
0
    def test_response_challenge(self):
        self.sm._state = "challenge"

        state, payload = self._run_test(self.sm.respond(b"bar"), [
            XMLStreamMock.Mute(),
            XMLStreamMock.Send(nonza.SASLResponse(payload=b"bar"),
                               response=XMLStreamMock.Receive(
                                   nonza.SASLChallenge(payload=b"baz"))),
            XMLStreamMock.Unmute(),
        ])
        self.assertEqual(state, "challenge")
        self.assertEqual(payload, b"baz")
示例#7
0
    def test_initiate_failure(self):
        with self.assertRaises(aiosasl.SASLFailure) as ctx:
            self._run_test(self.sm.initiate("foo", b"bar"), [
                XMLStreamMock.Mute(),
                XMLStreamMock.Send(
                    nonza.SASLAuth(mechanism="foo", payload=b"bar"),
                    response=XMLStreamMock.Receive(
                        nonza.SASLFailure(condition=(namespaces.sasl,
                                                     "not-authorized")))),
                XMLStreamMock.Unmute(),
            ])

        self.assertEqual("not-authorized", ctx.exception.opaque_error)
示例#8
0
    def test_response_failure(self):
        self.sm._state = "challenge"

        with self.assertRaises(aiosasl.SASLFailure) as ctx:
            self._run_test(self.sm.respond(b"bar"), [
                XMLStreamMock.Mute(),
                XMLStreamMock.Send(
                    nonza.SASLResponse(payload=b"bar"),
                    response=XMLStreamMock.Receive(
                        nonza.SASLFailure(condition=(namespaces.sasl,
                                                     "credentials-expired")))),
                XMLStreamMock.Unmute(),
            ])

        self.assertEqual("credentials-expired", ctx.exception.opaque_error)