コード例 #1
0
 def test_plain(self):
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(u'testzid', result.authzid)
コード例 #2
0
 def test_plain(self):
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(
         io, 'PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=')
     self.assertEqual('testidentity', identity)
コード例 #3
0
 def test_crammd5_malformed(self):
     self.sock.sendall(b'334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'bWFsZm9ybWVk\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(ServerAuthError):
         auth.server_attempt(b'CRAM-MD5')
コード例 #4
0
 def test_plain(self):
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(u'testzid', result.authzid)
コード例 #5
0
 def test_crammd5_malformed(self):
     self.sock.sendall(b'334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'bWFsZm9ybWVk\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(ServerAuthError):
         auth.server_attempt('CRAM-MD5')
コード例 #6
0
 def test_client_bad_mech(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #7
0
 def test_plain_badcreds(self):
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with assert_raises(CredentialsInvalidError):
         auth.server_attempt(io, 'PLAIN dGVzdHppZAB0ZXN0dXNlcgBiYWRwYXNzd29yZA==')
     with assert_raises(ServerAuthError):
         auth.server_attempt(io, 'PLAIN dGVzdGluZw==')
コード例 #8
0
 def test_crammd5_badcreds(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHVzZXIgMTIzNDU2Nzg5MA==\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with assert_raises(CredentialsInvalidError):
         auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
コード例 #9
0
 def test_crammd5_malformed(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn('bWFsZm9ybWVk\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with assert_raises(ServerAuthError):
         auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
コード例 #10
0
 def test_client_bad_mech(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #11
0
 def test_crammd5(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHVzZXIgNDkzMzA1OGU2ZjgyOTRkZTE0NDJkMTYxOTI3ZGI5NDQ=\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
     assert_equal('testidentity', identity)
コード例 #12
0
 def test_client_plain(self):
     self.sock.sendall(b'AUTH PLAIN amtsAHRlc3RAZXhhbXBsZS5jb20AYXNkZg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', 'jkl', 'PLAIN')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #13
0
 def test_client_xoauth2(self):
     self.sock.sendall(b'AUTH XOAUTH2 dXNlcj10ZXN0QGV4YW1wbGUuY29tAWF1dGg9QmVhcmVyYXNkZgEB\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'XOAUTH2')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #14
0
 def test_plain_noarg(self):
     self.sock.sendall('334 \r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'PLAIN')
     assert_equal('testidentity', identity)
コード例 #15
0
 def test_login(self):
     self.sock.sendall('334 UGFzc3dvcmQ6\r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHBhc3N3b3Jk\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'LOGIN dGVzdHVzZXI=')
     assert_equal('testidentity', identity)
コード例 #16
0
 def test_crammd5_malformed(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn('bWFsZm9ybWVk\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with self.assertRaises(ServerAuthError):
         auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
コード例 #17
0
 def test_crammd5_badcreds(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHVzZXIgMTIzNDU2Nzg5MA==\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with self.assertRaises(CredentialsInvalidError):
         auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
コード例 #18
0
 def test_login(self):
     self.sock.sendall('334 UGFzc3dvcmQ6\r\n')
     self.sock.recv(IsA(int)).AndReturn('dGVzdHBhc3N3b3Jk\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'LOGIN dGVzdHVzZXI=')
     self.assertEqual('testidentity', identity)
コード例 #19
0
 def test_plain_canceled(self):
     self.sock.sendall(b'334 \r\n')
     self.sock.recv(IsA(int)).AndReturn(b'*\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt(b'PLAIN')
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt(b'PLAIN *')
コード例 #20
0
 def test_plain_noarg(self):
     self.sock.sendall(b'334 \r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'PLAIN')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(u'testzid', result.authzid)
コード例 #21
0
 def test_plain_noarg(self):
     self.sock.sendall(b'334 \r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'PLAIN')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(u'testzid', result.authzid)
コード例 #22
0
 def test_crammd5(self):
     self.sock.sendall('334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn(
         'dGVzdHVzZXIgNDkzMzA1OGU2ZjgyOTRkZTE0NDJkMTYxOTI3ZGI5NDQ=\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'CRAM-MD5 dGVzdHVzZXI=')
     self.assertEqual('testidentity', identity)
コード例 #23
0
 def test_login(self):
     self.sock.sendall(b'334 UGFzc3dvcmQ6\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHBhc3N3b3Jk\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'LOGIN dGVzdHVzZXI=')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(None, result.authzid)
コード例 #24
0
 def test_plain_noarg(self):
     self.sock.sendall('334 \r\n')
     self.sock.recv(
         IsA(int)).AndReturn('dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'PLAIN')
     self.assertEqual('testidentity', identity)
コード例 #25
0
 def test_login(self):
     self.sock.sendall(b'334 UGFzc3dvcmQ6\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHBhc3N3b3Jk\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt('LOGIN dGVzdHVzZXI=')
     self.assertEqual(u'testuser', result.authcid)
     self.assertEqual(u'testpassword', result.secret)
     self.assertEqual(None, result.authzid)
コード例 #26
0
 def test_client_plain(self):
     self.sock.sendall(
         b'AUTH PLAIN amtsAHRlc3RAZXhhbXBsZS5jb20AYXNkZg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', 'jkl', 'PLAIN')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #27
0
 def test_client_xoauth2(self):
     self.sock.sendall(b'AUTH XOAUTH2 dXNlcj10ZXN0QGV4YW1wbGUuY29tAWF1dGg9QmVhcmVyYXNkZgEB\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth([b'XOAUTH2']), self.io)
     reply = auth.client_attempt(u'*****@*****.**', u'asdf',
                                 None, b'XOAUTH2')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #28
0
 def test_crammd5(self):
     self.sock.sendall(b'334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHVzZXIgNDkzMzA1OGU2ZjgyOTRkZTE0NDJkMTYxOTI3ZGI5NDQ=\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'CRAM-MD5')
     self.assertEqual(u'testuser', result.authcid)
     self.assertTrue(result.check_secret(u'testpassword'))
     self.assertFalse(result.check_secret(u'testwrong'))
     self.assertEqual(None, result.authzid)
コード例 #29
0
 def test_crammd5(self):
     self.sock.sendall(b'334 PHRlc3RAZXhhbXBsZS5jb20+\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'dGVzdHVzZXIgNDkzMzA1OGU2ZjgyOTRkZTE0NDJkMTYxOTI3ZGI5NDQ=\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     result = auth.server_attempt(b'CRAM-MD5')
     self.assertEqual(u'testuser', result.authcid)
     self.assertTrue(result.check_secret(u'testpassword'))
     self.assertFalse(result.check_secret(u'testwrong'))
     self.assertEqual(None, result.authzid)
コード例 #30
0
 def test_plain_canceled(self):
     self.sock.sendall('334 \r\n')
     self.sock.recv(IsA(int)).AndReturn('*\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with assert_raises(AuthenticationCanceled):
         auth.server_attempt(io, 'PLAIN')
     with assert_raises(AuthenticationCanceled):
         auth.server_attempt(io, 'PLAIN *')
コード例 #31
0
 def test_client_login_bad_username(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 VXNlcm5hbWU6\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbQ==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #32
0
 def test_client_login_bad_username(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 VXNlcm5hbWU6\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbQ==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #33
0
 def test_client_crammd5(self):
     self.sock.sendall(b'AUTH CRAM-MD5\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 dGVzdCBjaGFsbGVuZ2U=\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbSA1Yzk1OTBjZGE3ZTgxMDY5Mzk2ZjhiYjlkMzU1MzE1Yg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'CRAM-MD5')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #34
0
 def test_client_xoauth2_error(self):
     self.sock.sendall(b'AUTH XOAUTH2 dXNlcj10ZXN0QGV4YW1wbGUuY29tAWF1dGg9QmVhcmVyYXNkZgEB\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 eyJzdGF0dXMiOiI0MDEiLCJzY2hlbWVzIjoiYmVhcmVyIG1hYyIsInNjb3BlIjoiaHR0cHM6Ly9tYWlsLmdvb2dsZS5jb20vIn0K\r\n')
     self.sock.sendall(b'\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'XOAUTH2')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #35
0
 def test_client_xoauth2_error(self):
     self.sock.sendall(b'AUTH XOAUTH2 dXNlcj10ZXN0QGV4YW1wbGUuY29tAWF1dGg9QmVhcmVyYXNkZgEB\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 eyJzdGF0dXMiOiI0MDEiLCJzY2hlbWVzIjoiYmVhcmVyIG1hYyIsInNjb3BlIjoiaHR0cHM6Ly9tYWlsLmdvb2dsZS5jb20vIn0K\r\n')
     self.sock.sendall(b'\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth([b'XOAUTH2']), self.io)
     reply = auth.client_attempt(u'*****@*****.**', u'asdf',
                                 None, b'XOAUTH2')
     self.assertEqual('535', reply.code)
     self.assertEqual('5.0.0 Nope!', reply.message)
コード例 #36
0
 def test_client_crammd5(self):
     self.sock.sendall(b'AUTH CRAM-MD5\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 dGVzdCBjaGFsbGVuZ2U=\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbSA1Yzk1OTBjZGE3ZTgxMDY5Mzk2ZjhiYjlkMzU1MzE1Yg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt(u'*****@*****.**', u'asdf',
                                 None, b'CRAM-MD5')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #37
0
 def test_client_login(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 VXNlcm5hbWU6\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbQ==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 UGFzc3dvcmQ6\r\n')
     self.sock.sendall(b'YXNkZg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #38
0
 def test_client_login(self):
     self.sock.sendall(b'AUTH LOGIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 VXNlcm5hbWU6\r\n')
     self.sock.sendall(b'dGVzdEBleGFtcGxlLmNvbQ==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'334 UGFzc3dvcmQ6\r\n')
     self.sock.sendall(b'YXNkZg==\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     reply = auth.client_attempt('*****@*****.**', 'asdf', None, 'LOGIN')
     self.assertEqual('235', reply.code)
     self.assertEqual('2.0.0 Ok', reply.message)
コード例 #39
0
 def test_plain_badcreds(self):
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with self.assertRaises(CredentialsInvalidError):
         auth.server_attempt(
             io, 'PLAIN dGVzdHppZAB0ZXN0dXNlcgBiYWRwYXNzd29yZA==')
     with self.assertRaises(ServerAuthError):
         auth.server_attempt(io, 'PLAIN dGVzdGluZw==')
コード例 #40
0
 def test_plain_canceled(self):
     self.sock.sendall(b'334 \r\n')
     self.sock.recv(IsA(int)).AndReturn(b'*\r\n')
     self.mox.ReplayAll()
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt('PLAIN')
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt('PLAIN *')
コード例 #41
0
 def test_auth(self):
     self.sock.sendall(b'220 ESMTP server\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'EHLO there\r\n')
     self.sock.sendall(b'250-Hello there\r\n250 AUTH PLAIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(
         b'AUTH PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.sock.sendall(b'235 2.7.0 Authentication successful\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'QUIT\r\n')
     self.sock.sendall(b'221 2.0.0 Bye\r\n')
     self.mox.ReplayAll()
     s = Server(self.sock, None)
     s.extensions.reset()
     s.extensions.add('AUTH', AuthSession(SASLAuth([b'PLAIN']), s.io))
     s.handle()
     self.assertTrue(s.authed)
コード例 #42
0
 def test_auth(self):
     self.sock.sendall('220 ESMTP server\r\n')
     self.sock.recv(IsA(int)).AndReturn('EHLO there\r\n')
     self.sock.sendall('250-Hello there\r\n250 AUTH PLAIN\r\n')
     self.sock.recv(IsA(int)).AndReturn(
         'AUTH PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=\r\n')
     self.sock.sendall('235 2.7.0 Authentication successful\r\n')
     self.sock.recv(IsA(int)).AndReturn('QUIT\r\n')
     self.sock.sendall('221 2.0.0 Bye\r\n')
     self.mox.ReplayAll()
     s = Server(self.sock, None)
     s.extensions.reset()
     s.extensions.add('AUTH', AuthSession(FakeAuth(), s))
     s.handle()
     self.assertEqual(('testuser', 'testzid'), s.auth_result)
コード例 #43
0
 def test_plain_canceled(self):
     self.sock.sendall('334 \r\n')
     self.sock.recv(IsA(int)).AndReturn('*\r\n')
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt(io, 'PLAIN')
     with self.assertRaises(AuthenticationCanceled):
         auth.server_attempt(io, 'PLAIN *')
コード例 #44
0
 def test_str(self):
     auth = AuthSession(FakeAuthWithGetSecret(), FakeSession(False))
     self.assertEqual('CRAM-MD5', str(auth))
     auth = AuthSession(Auth(), FakeSession(True))
     self.assertEqual('PLAIN LOGIN', str(auth))
コード例 #45
0
 def test_str_no_secure_mechanisms(self):
     auth = AuthSession(FakeAuthNoSecure(), FakeSession(True))
     self.assertEqual('PLAIN LOGIN', str(auth))
     auth = AuthSession(FakeAuthNoSecure(), FakeSession(False))
     with self.assertRaises(ValueError):
         str(auth)
コード例 #46
0
 def test_invalid_mechanism(self):
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt(None, 'TEST')
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt(None, 'B@D')
コード例 #47
0
 def test_invalid_mechanism(self):
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt(b'TEST')
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt(b'B@D')
コード例 #48
0
 def test_invalid_mechanism(self):
     auth = AuthSession(FakeAuth(), FakeSession(True))
     with assert_raises(InvalidMechanismError):
         auth.server_attempt(None, 'TEST')
     with assert_raises(InvalidMechanismError):
         auth.server_attempt(None, 'B@D')
コード例 #49
0
 def test_bytes(self):
     auth = AuthSession(SASLAuth(), self.io)
     self.assertEqual('PLAIN LOGIN CRAM-MD5', str(auth))
コード例 #50
0
 def test_str(self):
     auth = AuthSession(SASLAuth(), self.io)
     self.assertEqual('CRAM-MD5 LOGIN PLAIN', str(auth))
コード例 #51
0
 def test_invalid_mechanism(self):
     auth = AuthSession(SASLAuth(), self.io)
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt('TEST')
     with self.assertRaises(InvalidMechanismError):
         auth.server_attempt('B@D')
コード例 #52
0
 def test_plain(self):
     self.mox.ReplayAll()
     io = IO(self.sock)
     auth = AuthSession(FakeAuth(), FakeSession(True))
     identity = auth.server_attempt(io, 'PLAIN dGVzdHppZAB0ZXN0dXNlcgB0ZXN0cGFzc3dvcmQ=')
     assert_equal('testidentity', identity)