Skip to content

Commit 870f4d5

Browse files
authored
Skip errors relating to interaction not being allowed (#259)
1 parent e3c198a commit 870f4d5

1 file changed

Lines changed: 38 additions & 26 deletions

File tree

Tests/X509Tests/SecKeyWrapperTests.swift

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,52 @@ final class SecKeyWrapperTests: XCTestCase {
2828
}
2929

3030
func generateCandidateKeys() throws -> [CandidateKey] {
31-
var keys: [CandidateKey] = []
31+
do {
32+
var keys: [CandidateKey] = []
3233

33-
// RSA
34-
keys.append(
35-
CandidateKey(
36-
key: try SignatureTests.generateSecKey(keyType: kSecAttrKeyTypeRSA, keySize: 2048, useSEP: false),
37-
type: "RSA",
38-
keySize: 2048,
39-
sep: false
34+
// RSA
35+
keys.append(
36+
CandidateKey(
37+
key: try SignatureTests.generateSecKey(keyType: kSecAttrKeyTypeRSA, keySize: 2048, useSEP: false),
38+
type: "RSA",
39+
keySize: 2048,
40+
sep: false
41+
)
4042
)
41-
)
4243

43-
// eliptic curves
44-
var keyTypes = [kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyTypeEC]
45-
#if os(macOS)
46-
keyTypes.append(kSecAttrKeyTypeECDSA)
47-
#endif
44+
// eliptic curves
45+
var keyTypes = [kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyTypeEC]
46+
#if os(macOS)
47+
keyTypes.append(kSecAttrKeyTypeECDSA)
48+
#endif
4849

49-
for keyType in keyTypes {
50-
for keySize in [256, 384] {
51-
for useSEP in [true, false] {
52-
keys.append(
53-
CandidateKey(
54-
key: try SignatureTests.generateSecKey(keyType: keyType, keySize: keySize, useSEP: useSEP),
55-
type: "EC-\(keyType)",
56-
keySize: keySize,
57-
sep: useSEP
50+
for keyType in keyTypes {
51+
for keySize in [256, 384] {
52+
for useSEP in [true, false] {
53+
keys.append(
54+
CandidateKey(
55+
key: try SignatureTests.generateSecKey(
56+
keyType: keyType,
57+
keySize: keySize,
58+
useSEP: useSEP
59+
),
60+
type: "EC-\(keyType)",
61+
keySize: keySize,
62+
sep: useSEP
63+
)
5864
)
59-
)
65+
}
6066
}
6167
}
62-
}
6368

64-
return keys
69+
return keys
70+
} catch let err as NSError {
71+
if err.domain == NSOSStatusErrorDomain && err.code == errSecInteractionNotAllowed {
72+
// Suppress this error
73+
throw XCTSkip("Unable to run this test without interactive prompting")
74+
}
75+
throw err
76+
}
6577
}
6678

6779
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, macCatalyst 14, visionOS 1.0, *)

0 commit comments

Comments
 (0)