I'm setting up unit tests for my application using Xcode. When I tried to access default keychain on MacOS using SecKeychainCopyDefault
, I got error OSStatus -25307
, which means "A default keychain could not be found."
The tests worked locally, and the issue only happened with Github Actions.
Would anyone have any insight on this issue, or point me to some reading I can refer to? Thanks in advance!
Here is some more tests I've done here. I tried to run "security default-keychain" on GithubAction, and I got
> security default-keychain
"/Users/runner/Library/Keychains/login.keychain-db"
However, when I tried to start a shell to run the same security command in my unit test, I got
SecKeychainCopyDefault: A default keychain could not be found.
Here is my test calling security command from shell:
static func run_shell(_ command: String) -> String {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.arguments = ["-c", command]
task.launchPath = "/bin/zsh"
task.standardInput = nil
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)!
return output
}
func testSecurityDefaultKeychain() throws
{
print(TLSContextTests.run_shell("security default-keychain"));
}