9
9
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
-
13
- import XCTest
12
+ import Foundation
13
+ import Testing
14
14
15
15
import Basics
16
16
@testable import PackageSigning
17
17
import _InternalTestSupport
18
18
import X509
19
19
20
- final class SigningEntityTests : XCTestCase {
21
- func testTwoADPSigningEntitiesAreEqualIfTeamIDEqual( ) {
20
+ struct SigningEntityTests {
21
+ @Test
22
+ func twoADPSigningEntitiesAreEqualIfTeamIDEqual( ) {
22
23
let adp1 = SigningEntity . recognized (
23
24
type: . adp,
24
25
name: " A. Appleseed " ,
@@ -37,74 +38,58 @@ final class SigningEntityTests: XCTestCase {
37
38
organizationalUnit: " SwiftPM Test Unit Y " ,
38
39
organization: " C "
39
40
)
40
- XCTAssertEqual ( adp1, adp2) // Only team ID (org unit) needs to match
41
- XCTAssertNotEqual ( adp1, adp3)
41
+ #expect ( adp1 == adp2) // Only team ID (org unit) needs to match
42
+ #expect ( adp1 != adp3)
42
43
}
43
44
44
- func testFromECKeyCertificate( ) throws {
45
+ @Test (
46
+ " From certificate key " ,
47
+ arguments: [
48
+ ( certificateFilename: " Test_ec.cer " , id: " EC Key " ) ,
49
+ ( certificateFilename: " Test_rsa.cer " , id: " RSA Key " )
50
+ ]
51
+ )
52
+ func fromCertificate( certificateFilename: String , id: String ) throws {
45
53
try fixture ( name: " Signing " , createGitRepo: false ) { fixturePath in
46
54
let certificateBytes = try readFileContents (
47
55
in: fixturePath,
48
56
pathComponents: " Certificates " ,
49
- " Test_ec.cer "
57
+ certificateFilename
50
58
)
51
59
let certificate = try Certificate ( certificateBytes)
52
60
53
61
let signingEntity = SigningEntity . from ( certificate: certificate)
54
62
guard case . unrecognized( let name, let organizationalUnit, let organization) = signingEntity else {
55
- return XCTFail ( " Expected SigningEntity.unrecognized but got \( signingEntity) " )
63
+ Issue . record ( " Expected SigningEntity.unrecognized but got \( signingEntity) " )
64
+ return
56
65
}
57
- XCTAssertEqual ( name, certificate. subject. commonName)
58
- XCTAssertEqual ( organizationalUnit, certificate. subject. organizationalUnitName)
59
- XCTAssertEqual ( organization, certificate. subject. organizationName)
66
+ #expect ( name == certificate. subject. commonName)
67
+ #expect ( organizationalUnit == certificate. subject. organizationalUnitName)
68
+ #expect ( organization == certificate. subject. organizationName)
60
69
}
61
70
}
62
71
63
- func testFromRSAKeyCertificate( ) throws {
64
- try fixture ( name: " Signing " , createGitRepo: false ) { fixturePath in
65
- let certificateBytes = try readFileContents (
66
- in: fixturePath,
67
- pathComponents: " Certificates " ,
68
- " Test_rsa.cer "
69
- )
70
- let certificate = try Certificate ( certificateBytes)
72
+ @Test (
73
+ . enabled( if: isMacOS ( ) && isRealSigningIdentityTestEnabled ( ) && isEnvironmentVariableSet ( " REAL_SIGNING_IDENTITY_LABEL " ) )
74
+ )
75
+ func fromKeychainCertificate( ) async throws {
76
+ let label = try #require( Environment . current [ " REAL_SIGNING_IDENTITY_LABEL " ] )
71
77
72
- let signingEntity = SigningEntity . from ( certificate: certificate)
73
- guard case . unrecognized( let name, let organizationalUnit, let organization) = signingEntity else {
74
- return XCTFail ( " Expected SigningEntity.unrecognized but got \( signingEntity) " )
75
- }
76
- XCTAssertEqual ( name, certificate. subject. commonName)
77
- XCTAssertEqual ( organizationalUnit, certificate. subject. organizationalUnitName)
78
- XCTAssertEqual ( organization, certificate. subject. organizationName)
79
- }
80
- }
81
-
82
- #if os(macOS)
83
- func testFromKeychainCertificate( ) async throws {
84
- #if ENABLE_REAL_SIGNING_IDENTITY_TEST
85
- #else
86
- try XCTSkipIf ( true )
87
- #endif
88
-
89
- guard let label = Environment . current [ " REAL_SIGNING_IDENTITY_LABEL " ] else {
90
- throw XCTSkip ( " Skipping because 'REAL_SIGNING_IDENTITY_LABEL' env var is not set " )
91
- }
92
78
let identityStore = SigningIdentityStore ( observabilityScope: ObservabilitySystem . NOOP)
93
79
let matches = identityStore. find ( by: label)
94
- XCTAssertTrue ( !matches. isEmpty)
80
+ #expect ( !matches. isEmpty)
95
81
96
82
let certificate = try Certificate ( secIdentity: matches [ 0 ] as! SecIdentity )
97
83
let signingEntity = SigningEntity . from ( certificate: certificate)
98
84
switch signingEntity {
99
- case . recognized( _, let name, let organizationalUnit, let organization) :
100
- XCTAssertEqual ( name, certificate. subject. commonName)
101
- XCTAssertEqual ( organizationalUnit, certificate. subject. organizationalUnitName)
102
- XCTAssertEqual ( organization, certificate. subject. organizationName)
103
- case . unrecognized( let name, let organizationalUnit, let organization) :
104
- XCTAssertEqual ( name, certificate. subject. commonName)
105
- XCTAssertEqual ( organizationalUnit, certificate. subject. organizationalUnitName)
106
- XCTAssertEqual ( organization, certificate. subject. organizationName)
85
+ case . recognized( _, let name, let organizationalUnit, let organization) :
86
+ #expect ( name == certificate. subject. commonName)
87
+ #expect ( organizationalUnit == certificate. subject. organizationalUnitName)
88
+ #expect ( organization == certificate. subject. organizationName)
89
+ case . unrecognized( let name, let organizationalUnit, let organization) :
90
+ #expect ( name == certificate. subject. commonName)
91
+ #expect ( organizationalUnit == certificate. subject. organizationalUnitName)
92
+ #expect ( organization == certificate. subject. organizationName)
107
93
}
108
94
}
109
- #endif
110
95
}
0 commit comments