[pywin32-checkins] pywin32/win32/test test_sspi.py,1.1,1.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2005-03-07 11:16:47
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29814/test Modified Files: test_sspi.py Log Message: * Have encrypt/sign etc return the data and the security info as discrete objects rather than merging them. * Support sequence-numbering - Kerberos appears to insist in incrementing sequence numbers with our default flags - passing zero does not work. * Demos tests updated accordingly. Index: test_sspi.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_sspi.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_sspi.py 6 Mar 2005 23:27:02 -0000 1.1 --- test_sspi.py 7 Mar 2005 11:16:36 -0000 1.2 *************** *** 7,10 **** --- 7,17 ---- class TestSSPI(unittest.TestCase): + def assertRaisesHRESULT(self, hr, func, *args): + try: + return func(*args) + raise RuntimeError, "expecting %s failure" % (hr,) + except win32security.error, (hr_got, func, msg): + self.failUnlessEqual(hr_got, hr) + def _doAuth(self, pkg_name): sspiclient=sspi.ClientAuth(pkg_name,targetspn=win32api.GetUserName()) *************** *** 46,51 **** self.failUnlessEqual(msg, encbuf[0].Buffer) # and test the higher-level functions ! self.assertEqual(sspiserver.decrypt(sspiclient.encrypt("hello")), "hello") ! self.assertEqual(sspiclient.decrypt(sspiserver.encrypt("hello")), "hello") def testEncryptNTLM(self): --- 53,61 ---- self.failUnlessEqual(msg, encbuf[0].Buffer) # and test the higher-level functions ! data, sig = sspiclient.encrypt("hello") ! self.assertEqual(sspiserver.decrypt(data, sig), "hello") ! ! data, sig = sspiserver.encrypt("hello") ! self.assertEqual(sspiclient.decrypt(data, sig), "hello") def testEncryptNTLM(self): *************** *** 67,76 **** sigbuf.append(win32security.SecBufferType(sigsize, sspicon.SECBUFFER_TOKEN)) sigbuf[0].Buffer=msg ! sspiclient.ctxt.MakeSignature(0,sigbuf,1) ! sspiserver.ctxt.VerifySignature(sigbuf,1) # and test the higher-level functions ! self.assertEqual(sspiserver.unsign(sspiclient.sign("hello")), "hello") # and the other way ! self.assertEqual(sspiclient.unsign(sspiserver.sign("hello")), "hello") def testSignNTLM(self): --- 77,97 ---- sigbuf.append(win32security.SecBufferType(sigsize, sspicon.SECBUFFER_TOKEN)) sigbuf[0].Buffer=msg ! sspiclient.ctxt.MakeSignature(0,sigbuf,0) ! sspiserver.ctxt.VerifySignature(sigbuf,0) # and test the higher-level functions ! sspiclient.next_seq_num = 1 ! sspiserver.next_seq_num = 1 ! key = sspiclient.sign("hello") ! sspiserver.verify("hello", key) ! key = sspiclient.sign("hello") ! self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiserver.verify, "hellox", key) ! # and the other way ! key = sspiserver.sign("hello") ! sspiclient.verify("hello", key) ! key = sspiserver.sign("hello") ! self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiclient.verify, "hellox", key) def testSignNTLM(self): *************** *** 80,83 **** --- 101,120 ---- self._doTestSign("Kerberos") + def testSequenceSign(self): + # Only Kerberos supports sequence detection. + sspiclient, sspiserver = self._doAuth("Kerberos") + key = sspiclient.sign("hello") + sspiclient.sign("hello") + self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, + sspiserver.verify, 'hello', key) + + def testSequenceEncrypt(self): + # Only Kerberos supports sequence detection. + sspiclient, sspiserver = self._doAuth("Kerberos") + blob, key = sspiclient.encrypt("hello",) + blob, key = sspiclient.encrypt("hello") + self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, + sspiserver.decrypt, blob, key) + if __name__=='__main__': unittest.main() |