def test_init(self): challenge = nonza.SASLResponse(b"foo") self.assertEqual(challenge.payload, b"foo") challenge = nonza.SASLResponse(payload=b"foo") self.assertEqual(challenge.payload, b"foo") with self.assertRaisesRegex(TypeError, "positional argument"): nonza.SASLResponse()
def test_response_success(self): self.sm._state = "challenge" state, payload = self._run_test(self.sm.respond(b"bar"), [ XMLStreamMock.Send(nonza.SASLResponse(payload=b"bar"), response=XMLStreamMock.Receive( nonza.SASLSuccess())) ]) self.assertEqual(state, "success") self.assertIsNone(payload)
def test_response_challenge(self): self.sm._state = "challenge" state, payload = self._run_test(self.sm.respond(b"bar"), [ XMLStreamMock.Send(nonza.SASLResponse(payload=b"bar"), response=XMLStreamMock.Receive( nonza.SASLChallenge(payload=b"baz"))) ]) self.assertEqual(state, "challenge") self.assertEqual(payload, b"baz")
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.Send( nonza.SASLResponse(payload=b"bar"), response=XMLStreamMock.Receive( nonza.SASLFailure(condition=(namespaces.sasl, "credentials-expired")))) ]) self.assertEqual("credentials-expired", ctx.exception.opaque_error)