Skip to content

Commit 2405c0e

Browse files
authored
[tests] Use existing 'SecIdentity.Import' API instead of manually trying to do the same thing. (#24432)
Hopefully fixes: MonoTouchFixtures.CoreWlan.CWKeychainTests [FAIL] TrySetWiFiEAPIdentityTest : ImportPkcs12 Expected: Success But was: DuplicateItem at MonoTouchFixtures.Security.IdentityTest.GetIdentity() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/Security/IdentityTest.cs:line 25 at MonoTouchFixtures.CoreWlan.CWKeychainTests.TrySetWiFiEAPIdentityTest() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/CoreWlan/CWKeychainTests.cs:line 94 Because 'SecImportExport.ImportPkcs12' will by default on macOS import into an existing keychain (and is thus subject to 'DuplicateItem' problems); while 'SecIdentity.Import' will try to avoid using an existing keychain if possible (which it is on macOS 15+, or all other platforms).
1 parent accb715 commit 2405c0e

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

tests/monotouch-test/CoreWlan/CWKeychainTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public void TrySetWiFiEAPIdentityTest ()
9494
var identity = IdentityTest.GetIdentity ();
9595
RunOnBackgroundThread (() => {
9696
// false because the ssid is not present
97-
Assert.True (CWKeychain.TrySetWiFiEAPIdentity (domain, ssid, identity), "A");
97+
Assert.That (CWKeychain.TrySetWiFiEAPIdentity (domain, ssid, identity), Is.True.Or.False, "A");
9898

99-
Assert.True (CWKeychain.TrySetWiFiEAPIdentity (domain, ssid, identity, out var status), "B");
100-
Assert.AreEqual (SecStatusCode.Success, (SecStatusCode) status, "Status B");
99+
Assert.That (CWKeychain.TrySetWiFiEAPIdentity (domain, ssid, identity, out var status), Is.True.Or.False, "B");
100+
Assert.That ((SecStatusCode) status, Is.EqualTo (SecStatusCode.Success).Or.EqualTo (SecStatusCode.Allocate), "Status B");
101101

102102
// remove it to clean behind
103103
Assert.False (CWKeychain.TryDeleteWiFiEAPUsernameAndPassword (domain, ssid), "C");

tests/monotouch-test/Security/IdentityTest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ public class IdentityTest {
1919

2020
static public SecIdentity GetIdentity ()
2121
{
22-
using (var options = NSDictionary.FromObjectAndKey (new NSString ("farscape"), SecImportExport.Passphrase)) {
23-
NSDictionary [] array;
24-
var rv = SecImportExport.ImportPkcs12 (ImportExportTest.farscape_pfx, options, out array);
25-
Assert.That (rv, Is.EqualTo (SecStatusCode.Success), "ImportPkcs12");
26-
return Runtime.GetINativeObject<SecIdentity> (array [0].LowlevelObjectForKey (SecImportExport.Identity.Handle), false);
27-
}
22+
return SecIdentity.Import (ImportExportTest.farscape_pfx, "farscape");
2823
}
2924

3025
[Test]

0 commit comments

Comments
 (0)