mirror of
https://github.com/coder/coder.git
synced 2026-06-04 05:28:20 +00:00
5e85663ce3
Add support for storing the CLI session token in the OS keyring on macOS when the --use-keyring flag is provided. https://github.com/coder/coder/issues/19403 https://www.notion.so/coderhq/CLI-Session-Token-in-OS-Keyring-293d579be592808b8b7fd235304e50d5
35 lines
609 B
Go
35 lines
609 B
Go
//go:build darwin
|
|
|
|
package sessionstore_test
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
execPathKeychain = "/usr/bin/security"
|
|
fixedUsername = "coder-login-credentials"
|
|
)
|
|
|
|
func readRawKeychainCredential(t *testing.T, service string) []byte {
|
|
t.Helper()
|
|
|
|
out, err := exec.Command(
|
|
execPathKeychain,
|
|
"find-generic-password",
|
|
"-s", service,
|
|
"-wa", fixedUsername).CombinedOutput()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
dst := make([]byte, base64.StdEncoding.DecodedLen(len(out)))
|
|
n, err := base64.StdEncoding.Decode(dst, out)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return dst[:n]
|
|
}
|