-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance CredDelete to work with dictionaries (#2198)
- Loading branch information
1 parent
b622db4
commit 1d29e4a
Showing
2 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import copy | ||
import unittest | ||
|
||
import win32cred | ||
|
||
|
||
class TestCredFunctions(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.flags = 0 | ||
self.dummy_cred = { | ||
"TargetName": "DumyyUser", | ||
"Type": win32cred.CRED_TYPE_GENERIC, | ||
"Flags": self.flags, | ||
} | ||
|
||
def create_dummy_cred(self): | ||
cred = copy.deepcopy(self.dummy_cred) | ||
cred.update( | ||
{ | ||
"Persist": win32cred.CRED_PERSIST_SESSION, | ||
} | ||
) | ||
try: | ||
win32cred.CredWrite(cred, self.flags) | ||
except Exception as e: | ||
print(e) | ||
|
||
def is_dummy_cred(self): | ||
return ( | ||
len( | ||
[ | ||
e | ||
for e in win32cred.CredEnumerate() | ||
if e["TargetName"] == self.dummy_cred["TargetName"] | ||
] | ||
) | ||
== 1 | ||
) | ||
|
||
def test_creddelete(self): | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertIsNone(win32cred.CredDelete(**self.dummy_cred)) | ||
self.assertFalse(self.is_dummy_cred()) | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertIsNone(win32cred.CredDelete(*self.dummy_cred.values())) | ||
self.assertFalse(self.is_dummy_cred()) | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertIsNone( | ||
win32cred.CredDelete(self.dummy_cred["TargetName"], self.dummy_cred["Type"]) | ||
) | ||
self.assertFalse(self.is_dummy_cred()) | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertIsNone(win32cred.CredDelete(self.dummy_cred)) | ||
self.assertFalse(self.is_dummy_cred()) | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertIsNone(win32cred.CredDelete(Target=self.dummy_cred)) | ||
self.assertFalse(self.is_dummy_cred()) | ||
self.create_dummy_cred() | ||
self.assertTrue(self.is_dummy_cred()) | ||
self.assertRaises(TypeError, win32cred.CredDelete, "") | ||
self.assertRaises(KeyError, win32cred.CredDelete, {}) | ||
self.assertRaises(KeyError, win32cred.CredDelete, {"TargetName": ""}) | ||
self.assertRaises( | ||
TypeError, win32cred.CredDelete, {"TargetName": "", "Type": 3.141593} | ||
) | ||
self.assertIsNone(win32cred.CredDelete(self.dummy_cred)) | ||
self.assertFalse(self.is_dummy_cred()) |