Skip to content

Commit df3ecee

Browse files
committed
restrict writing one credential attribute for ctypes
1 parent 335105d commit df3ecee

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

win32ctypes/core/ctypes/_authentication.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ def fromdict(cls, credential):
7272
count = len(attributes)
7373
if count == 0:
7474
continue
75-
data = (PCREDENTIAL_ATTRIBUTE * count)()
76-
for index in range(count):
77-
attribute = CREDENTIAL_ATTRIBUTE.fromdict(
78-
attributes[index])
79-
data[index] = PCREDENTIAL_ATTRIBUTE(attribute)
80-
c_credentials.Attributes = cast(data, PCREDENTIAL_ATTRIBUTE)
75+
elif count > 1:
76+
raise ValueError('Multiple attributes are not supported')
77+
c_attribute = CREDENTIAL_ATTRIBUTE.fromdict(attributes[0])
78+
c_pattribute = PCREDENTIAL_ATTRIBUTE(c_attribute)
79+
c_credentials.Attributes = c_pattribute
8180
c_credentials.AttributeCount = count
8281
else:
8382
setattr(c_credentials, key, credential[key])

win32ctypes/tests/test_authentication.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ def test_roundtrip(self):
5656
keyword = 'mysecret-attribute'
5757
value = b'Created by MiniPyWin32Cred test suite'
5858
attribute1 = {'Keyword': keyword, 'Value': value, 'Flags': 2}
59-
attribute2 = {
60-
'Keyword': keyword + '12', 'Value': value[:10], 'Flags': 1}
6159
data = {
6260
'Type': CRED_TYPE_GENERIC,
6361
'TargetName': target,
6462
'UserName': username,
6563
'CredentialBlob': password,
6664
'Comment': comment,
67-
'Attributes': (attribute1, attribute2),
65+
'Attributes': (attribute1,),
6866
'Persist': CRED_PERSIST_ENTERPRISE}
6967

7068
# when
@@ -80,9 +78,6 @@ def test_roundtrip(self):
8078
del result['CredentialBlobSize']
8179
del result['AttributeCount']
8280
result['CredentialBlob'] = result['CredentialBlob'].decode('utf-16')
83-
for attribute in result['Attributes']:
84-
if 'Value' in attribute:
85-
attribute['Value'] = attribute['Value']
8681
self.assertEqual(result, data)
8782

8883

win32ctypes/tests/test_win32cred.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _demo_attributes(self):
4646
attribute2 = {
4747
'Keyword': keyword + '12',
4848
'Value': b'Attribute from MiniPyWin32', 'Flags': 0}
49-
return (attribute1, attribute2)
49+
return (attribute1,)
5050

5151
def _demo_credentials(self, UserName=u'jone'):
5252
return {
@@ -61,6 +61,7 @@ def _demo_credentials(self, UserName=u'jone'):
6161
@unittest.skipIf(
6262
pywin32_build == '223' and sys.version_info[:2] == (3, 7),
6363
'pywin32 version 223 bug with CredRead (mhammond/pywin32#1232)')
64+
6465
def test_write_to_pywin32(self):
6566
# given
6667
target = u'jone@doe'

0 commit comments

Comments
 (0)