Skip to content

Commit

Permalink
Home directory for non-existent user should not fall back to /var/emp…
Browse files Browse the repository at this point in the history
…ty or %ALLUSERSPROFILE% (#5142)
  • Loading branch information
jmschonfeld authored Dec 6, 2024
1 parent c28bf23 commit 8255a77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions Tests/Foundation/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,8 @@ class TestFileManager : XCTestCase {

func test_homedirectoryForUser() {
let filemanger = FileManager.default
XCTAssertNotNil(filemanger.homeDirectory(forUser: "someuser"))
XCTAssertNotNil(filemanger.homeDirectory(forUser: ""))
XCTAssertNil(filemanger.homeDirectory(forUser: "someuser"))
XCTAssertNil(filemanger.homeDirectory(forUser: ""))
XCTAssertNotNil(filemanger.homeDirectoryForCurrentUser)
}

Expand Down Expand Up @@ -1268,15 +1268,13 @@ class TestFileManager : XCTestCase {
let fm = FileManager.default

#if os(Windows)
let defaultHomeDirectory = ProcessInfo.processInfo.environment["ALLUSERSPROFILE"]!
let emptyFileNameError: CocoaError.Code? = .fileReadInvalidFileName
#else
let defaultHomeDirectory = "/var/empty"
let emptyFileNameError: CocoaError.Code? = nil
#endif

XCTAssertEqual(fm.homeDirectory(forUser: ""), URL(filePath: defaultHomeDirectory, directoryHint: .isDirectory))
XCTAssertEqual(NSHomeDirectoryForUser(""), defaultHomeDirectory)
XCTAssertNil(fm.homeDirectory(forUser: ""))
XCTAssertNil(NSHomeDirectoryForUser(""))

XCTAssertThrowsError(try fm.contentsOfDirectory(atPath: "")) {
let code = ($0 as? CocoaError)?.code
Expand Down
6 changes: 1 addition & 5 deletions Tests/Foundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1047,11 +1047,7 @@ class TestNSString: LoopbackServerTest {
let path = NSString(string: "~\(userName)/")
let result = path.expandingTildeInPath
// next assert fails in VirtualBox because home directory for unknown user resolved to /var/run/vboxadd
#if os(Windows)
XCTAssertEqual(result, ProcessInfo.processInfo.environment["ALLUSERSPROFILE"])
#else
XCTAssertEqual(result, "/var/empty", "Return copy of receiver if home directory could not be resolved.")
#endif
XCTAssertEqual(result, "~\(userName)", "Return copy of receiver if home directory could not be resolved.")
}
}

Expand Down

0 comments on commit 8255a77

Please sign in to comment.