@@ -172,5 +172,75 @@ public void CloneDoesNotDisclosePassword()
172
172
Assert . Equal ( connection . ConnectionString , connection2 . ConnectionString ) ;
173
173
Assert . DoesNotContain ( "password" , connection2 . ConnectionString , StringComparison . OrdinalIgnoreCase ) ;
174
174
}
175
+
176
+ #if ! BASELINE
177
+ [ Theory ]
178
+ [ InlineData ( false ) ]
179
+ [ InlineData ( true ) ]
180
+ public void CloneWithUsesNewConnectionString ( bool openConnection )
181
+ {
182
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
183
+ if ( openConnection )
184
+ connection . Open ( ) ;
185
+ using var connection2 = connection . CloneWith ( "user=root;password=pass;server=example.com;database=test" ) ;
186
+ Assert . Equal ( "User Id=root;Password=pass;Server=example.com;Database=test" , connection2 . ConnectionString ) ;
187
+ }
188
+
189
+ [ Fact ]
190
+ public void CloneWithUsesExistingPassword ( )
191
+ {
192
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
193
+ var newConnectionString = "user=root;server=example.com;database=test" ;
194
+ using var connection2 = connection . CloneWith ( newConnectionString ) ;
195
+
196
+ var builder = new MySqlConnectionStringBuilder ( newConnectionString ) ;
197
+ builder . Password = AppConfig . CreateConnectionStringBuilder ( ) . Password ;
198
+ Assert . Equal ( builder . ConnectionString , connection2 . ConnectionString ) ;
199
+ }
200
+
201
+ [ Theory ]
202
+ [ InlineData ( false ) ]
203
+ [ InlineData ( true ) ]
204
+ public void CloneWithDoesNotDiscloseExistingPassword ( bool persistSecurityInfo )
205
+ {
206
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
207
+ connection . Open ( ) ;
208
+
209
+ var newConnectionString = "user=root;server=example.com;database=test;Persist Security Info=" + persistSecurityInfo ;
210
+ using var connection2 = connection . CloneWith ( newConnectionString ) ;
211
+
212
+ var builder = new MySqlConnectionStringBuilder ( newConnectionString ) ;
213
+ Assert . Equal ( builder . ConnectionString , connection2 . ConnectionString ) ;
214
+ }
215
+
216
+ [ Theory ]
217
+ [ InlineData ( false ) ]
218
+ [ InlineData ( true ) ]
219
+ public void CloneWithDoesDiscloseExistingPasswordIfPersistSecurityInfo ( bool persistSecurityInfo )
220
+ {
221
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString + ";Persist Security Info=true" ) ;
222
+ connection . Open ( ) ;
223
+
224
+ var newConnectionString = "user=root;server=example.com;database=test;Persist Security Info=" + persistSecurityInfo ;
225
+ using var connection2 = connection . CloneWith ( newConnectionString ) ;
226
+
227
+ var builder = new MySqlConnectionStringBuilder ( newConnectionString ) ;
228
+ builder . Password = AppConfig . CreateConnectionStringBuilder ( ) . Password ;
229
+ Assert . Equal ( builder . ConnectionString , connection2 . ConnectionString ) ;
230
+ }
231
+
232
+ [ Fact ]
233
+ public void CloneWithCopiesExistingPassword ( )
234
+ {
235
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
236
+ connection . Open ( ) ;
237
+
238
+ var builder = AppConfig . CreateConnectionStringBuilder ( ) ;
239
+ builder . Password = "" ;
240
+ using var connection2 = connection . CloneWith ( builder . ConnectionString ) ;
241
+ connection2 . Open ( ) ;
242
+ Assert . Equal ( ConnectionState . Open , connection2 . State ) ;
243
+ }
244
+ #endif
175
245
}
176
246
}
0 commit comments