@@ -38,11 +38,11 @@ def setUp(self):
3838 except error :
3939 pass
4040
41- def _demo_credentials (self ):
41+ def _demo_credentials (self , UserName = u'jone' ):
4242 return {
4343 "Type" : CRED_TYPE_GENERIC ,
4444 "TargetName" : u'jone@doe' ,
45- "UserName" : u'jone' ,
45+ "UserName" : UserName ,
4646 "CredentialBlob" : u"doefsajfsakfj" ,
4747 "Comment" : u"Created by MiniPyWin32Cred test suite" ,
4848 "Persist" : CRED_PERSIST_ENTERPRISE }
@@ -66,6 +66,9 @@ def test_write_to_pywin32(self):
6666 self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
6767 self .assertEqual (
6868 credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
69+ # XXX: the fact that we have to decode the password when reading, but
70+ # not encode when writing is a bit strange, but that's what pywin32
71+ # seems to do and we try to be backward compatible here.
6972 self .assertEqual (
7073 credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
7174
@@ -79,16 +82,45 @@ def test_read_from_pywin32(self):
7982 credentials = CredRead (target , CRED_TYPE_GENERIC )
8083
8184 # then
82- # XXX: the fact that we have to decode the password when reading, but
83- # not encode when writing is a bit strange, but that's what pywin32
84- # seems to do as well, and we try to be backward compatible here.
8585 self .assertEqual (credentials ["UserName" ], u"jone" )
8686 self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
8787 self .assertEqual (
8888 credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
8989 self .assertEqual (
9090 credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
9191
92+ def test_read_from_pywin32_with_none_usename (self ):
93+ # given
94+ target = u'jone@doe'
95+ r_credentials = self ._demo_credentials (None )
96+ win32cred .CredWrite (r_credentials )
97+
98+ # when
99+ credentials = CredRead (target , CRED_TYPE_GENERIC )
100+
101+ self .assertEqual (credentials ["UserName" ], None )
102+ self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
103+ self .assertEqual (
104+ credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
105+ self .assertEqual (
106+ credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
107+
108+ def test_write_to_pywin32_with_none_usename (self ):
109+ # given
110+ target = u'jone@doe'
111+ r_credentials = self ._demo_credentials (None )
112+ CredWrite (r_credentials )
113+
114+ # when
115+ credentials = win32cred .CredRead (target , CRED_TYPE_GENERIC )
116+
117+ self .assertEqual (credentials ["UserName" ], None )
118+ self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
119+ self .assertEqual (
120+ credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
121+ self .assertEqual (
122+ credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
123+
92124 def test_read_write (self ):
93125 # given
94126 target = u'jone@doe'
@@ -98,17 +130,30 @@ def test_read_write(self):
98130 CredWrite (r_credentials )
99131 credentials = CredRead (target , CRED_TYPE_GENERIC )
100132
101- # then
102- # XXX: the fact that we have to decode the password when reading, but
103- # not encode when writing is a bit strange, but that's what pywin32
104- # seems to do as well, and we try to be backward compatible here.
105133 self .assertEqual (credentials ["UserName" ], u"jone" )
106134 self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
107135 self .assertEqual (
108136 credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
109137 self .assertEqual (
110138 credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
111139
140+ def test_read_write_with_none_username (self ):
141+ # given
142+ target = u'jone@doe'
143+ r_credentials = self ._demo_credentials (None )
144+
145+ # when
146+ CredWrite (r_credentials )
147+ credentials = CredRead (target , CRED_TYPE_GENERIC )
148+
149+ # then
150+ self .assertEqual (credentials ["UserName" ], None )
151+ self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
152+ self .assertEqual (
153+ credentials ["Comment" ], u"Created by MiniPyWin32Cred test suite" )
154+ self .assertEqual (
155+ credentials ["CredentialBlob" ].decode ('utf-16' ), u"doefsajfsakfj" )
156+
112157 def test_enumerate_filter (self ):
113158 # given
114159 r_credentials = self ._demo_credentials ()
@@ -118,9 +163,6 @@ def test_enumerate_filter(self):
118163 credentials = CredEnumerate ('jone*' )[0 ]
119164
120165 # then
121- # XXX: the fact that we have to decode the password when reading, but
122- # not encode when writing is a bit strange, but that's what pywin32
123- # seems to do as well, and we try to be backward compatible here.
124166 self .assertEqual (credentials ["UserName" ], u"jone" )
125167 self .assertEqual (credentials ["TargetName" ], u'jone@doe' )
126168 self .assertEqual (
0 commit comments