Exemplo n.º 1
0
    def test_write_simple(self):
        username = u"john"
        password = u"doefsajfsakfj"
        comment = u"Created by MiniPyWin32Cred test suite"

        target = "{0}@{1}".format(username, password)

        credentials = {"Type": CRED_TYPE_GENERIC,
                       "TargetName": target,
                       "UserName": username,
                       "CredentialBlob": password,
                       "Comment": comment,
                       "Persist": CRED_PERSIST_ENTERPRISE}

        CredWrite(credentials)

        res = win32cred.CredRead(
            TargetName=target, Type=CRED_TYPE_GENERIC)

        self.assertEqual(res["Type"], CRED_TYPE_GENERIC)
        self.assertEqual(res["UserName"], username)
        self.assertEqual(res["TargetName"], target)
        self.assertEqual(res["Comment"], comment)
        self.assertEqual(
            res["CredentialBlob"].decode('utf-16'), password)
Exemplo n.º 2
0
    def test_delete_simple(self):
        username = "******"
        password = "******"
        comment = "Created by MiniPyWin32Cred test suite"

        target = "{0}@{1}".format(username, password)

        r_credentials = {
            "Type": CRED_TYPE_GENERIC,
            "TargetName": target,
            "UserName": username,
            "CredentialBlob": password,
            "Comment": comment,
            "Persist": CRED_PERSIST_ENTERPRISE}
        CredWrite(r_credentials, 0)

        credentials = win32cred.CredRead(target, CRED_TYPE_GENERIC)
        self.assertTrue(credentials is not None)

        CredDelete(target, CRED_TYPE_GENERIC)

        with self.assertRaises(error) as ctx:
            CredRead(target, CRED_TYPE_GENERIC)
        self.assertEqual(ctx.exception.winerror, ERROR_NOT_FOUND)
        self.assertEqual(ctx.exception.funcname, "CredRead")
Exemplo n.º 3
0
    def test_read_write(self):
        username = "******"
        password = "******"
        comment = u"Created by MiniPyWin32Cred test suite"

        target = u"{0}@{1}".format(username, password)

        r_credentials = {
            u"Type": CRED_TYPE_GENERIC,
            u"TargetName": target,
            u"UserName": username,
            u"CredentialBlob": password,
            u"Comment": comment,
            u"Persist": CRED_PERSIST_ENTERPRISE
        }
        CredWrite(r_credentials)

        credentials = CredRead(target, CRED_TYPE_GENERIC)

        # XXX: the fact that we have to decode the password when reading, but
        # not encode when writing is a bit strange, but that's what pywin32
        # seems to do as well, and we try to be backward compatible here.
        self.assertEqual(credentials["UserName"], username)
        self.assertEqual(credentials["TargetName"], target)
        self.assertEqual(credentials["Comment"], comment)
        self.assertEqual(credentials["CredentialBlob"].decode("utf-16"),
                         password)