feat(chat): Claude Code chats use a service token from a private file when the server runs in the background
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package claude
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServiceTokenIsPassedOnlyFromAPrivateFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "claude-token")
|
||||
t.Setenv(ServiceTokenEnvKey, path)
|
||||
base := []string{"HOME=/home/x"}
|
||||
|
||||
if got := withServiceToken(base); !slices.Equal(got, base) {
|
||||
t.Fatalf("no file: env = %v", got)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte("sk-test-token\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := withServiceToken(base); !slices.Equal(got, base) {
|
||||
t.Fatalf("readable by others: env = %v", got)
|
||||
}
|
||||
if err := os.Chmod(path, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := withServiceToken(base)
|
||||
if !slices.Contains(got, "CLAUDE_CODE_OAUTH_TOKEN=sk-test-token") || !HasServiceToken() {
|
||||
t.Fatalf("private file: env = %v", got)
|
||||
}
|
||||
explicit := []string{"CLAUDE_CODE_OAUTH_TOKEN=mine"}
|
||||
if got := withServiceToken(explicit); !slices.Equal(got, explicit) {
|
||||
t.Fatalf("explicit token replaced: %v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user