@@ -458,7 +458,7 @@ extension SubprocessWindowsTests {
458
458
extension SubprocessWindowsTests {
459
459
@Test ( . enabled( if: SubprocessWindowsTests . hasAdminPrivileges ( ) ) )
460
460
func testPlatformOptionsRunAsUser( ) async throws {
461
- try await self . withTemporaryUser { username, password in
461
+ try await self . withTemporaryUser { username, password, succeed in
462
462
// Use public directory as working directory so the newly created user
463
463
// has access to it
464
464
let workingDirectory = FilePath ( " C: \\ Users \\ Public " )
@@ -501,6 +501,12 @@ extension SubprocessWindowsTests {
501
501
}
502
502
return String ( decodingCString: pointer, as: UTF16 . self)
503
503
}
504
+ // On CI, we might failed to create user due to privilege issues
505
+ // There's nothing much we can do in this case
506
+ guard succeed else {
507
+ // If we fail to create the user, skip this test
508
+ return true
509
+ }
504
510
// CreateProcessWithLogonW doesn't appear to work when running in a container
505
511
return whoamiResult. terminationStatus == . unhandledException( STATUS_DLL_INIT_FAILED) && userName ( ) == " ContainerAdministrator "
506
512
}
@@ -735,16 +741,16 @@ extension SubprocessWindowsTests {
735
741
// MARK: - User Utils
736
742
extension SubprocessWindowsTests {
737
743
private func withTemporaryUser(
738
- _ work: ( String , String ) async throws -> Void
744
+ _ work: ( String , String , Bool ) async throws -> Void
739
745
) async throws {
740
746
let username : String = " TestUser \( randomString ( length: 5 , lettersOnly: true ) ) "
741
747
let password : String = " Password \( randomString ( length: 10 ) ) "
742
748
743
- func createUser( withUsername username: String , password: String ) {
744
- username. withCString (
749
+ func createUser( withUsername username: String , password: String ) -> Bool {
750
+ return username. withCString (
745
751
encodedAs: UTF16 . self
746
752
) { usernameW in
747
- password. withCString (
753
+ return password. withCString (
748
754
encodedAs: UTF16 . self
749
755
) { passwordW in
750
756
var userInfo : USER_INFO_1 = USER_INFO_1 ( )
@@ -765,15 +771,19 @@ extension SubprocessWindowsTests {
765
771
& error
766
772
)
767
773
guard status == NERR_Success else {
768
- Issue . record ( " Failed to create user with error: \( error) " )
769
- return
774
+ return false
770
775
}
776
+ return true
771
777
}
772
778
}
773
779
}
774
780
775
- createUser ( withUsername: username, password: password)
781
+ let succeed = createUser ( withUsername: username, password: password)
782
+
776
783
defer {
784
+ guard succeed else {
785
+ return
786
+ }
777
787
// Now delete the user
778
788
let status = username. withCString (
779
789
encodedAs: UTF16 . self
@@ -785,7 +795,7 @@ extension SubprocessWindowsTests {
785
795
}
786
796
}
787
797
// Run work
788
- try await work ( username, password)
798
+ try await work ( username, password, succeed )
789
799
}
790
800
791
801
private static func hasAdminPrivileges( ) -> Bool {
0 commit comments