437aab39b4
P0a1 — Re-architecture Foundation (path resolver + config demotion). Path resolver (REQ-070, R-002): - internal/paths/paths.go: 23 functions for the multi-namespace layout (Root/ClusterDir/NamespaceDir/NS*/DefaultNamespace/CA/MasterKey/CacheDB/ Txn/Peers/KnownHosts/SSH/Server/Config). Honors $ORCA_HOME. 100% coverage. - internal/certpaths/certpaths.go: refactored as thin shim delegating to paths, preserving the v0.8 flat-layout API for backward compat during the dual-write window (REQ-090). Package doc explains the v0.10-P14 migration plan. certpaths deleted after v0.10-P14. 100% coverage. Config demotion (REQ-069, R-014): - internal/config/markdown.go: minimal hand-rolled YAML frontmatter parser (no new dep — yaml.v3 not in go.mod). Returns same *Config struct as HCL. - internal/config/config.go: renamed Load body to LoadHCL (// Deprecated per R-013), added dispatcher Load() routing on extension (.hcl->HCL, .md->Markdown, .yaml->Markdown). Signature preserved so root.go unchanged. - dispatch_test.go + markdown_test.go: 89.8% coverage on config package. Known_hosts flock (REQ-063, deferred P1 from REVIEW_v0.8 A2): - internal/security/flock.go: stdlib syscall.Flock advisory lock helper. - internal/proxmox/bootstrap.go: TOFUHostKeyCallback capture + ResetHostKey both acquire the flock before read-modify-write on known_hosts. Prevents concurrent writers under v0.9 parallel SSH fan-out. 3 flock tests. CA migration spec (grill C-07): - .ciagent/CA_MIGRATION_SPEC_v0.9.md: Option A (preserve trust root, RECOMMENDED) vs Option B (forced re-bootstrap). Pre-flight checks, migration steps, rollback, post-migration invariants, spike plan. Verification: build pass, 17/17 Go packages pass, 20/20 bats pass, gofmt clean, go vet clean, verify-reqs 90 consistent. Coverage: paths 100%, certpaths 100%, config 89.8%, emit covered. ---ci--- project: orca phase: P0a1 milestone: v0.9 status: execute ---/ci---
185 lines
5.3 KiB
Go
185 lines
5.3 KiB
Go
package certpaths
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.cloudinit.dev/coreci/orca/internal/paths"
|
|
)
|
|
|
|
const defaultHomeSubdir = ".orca"
|
|
|
|
func TestPaths_HonorORCAHOME(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
t.Setenv("ORCA_DB", "")
|
|
|
|
cases := []struct {
|
|
name string
|
|
got string
|
|
file string
|
|
}{
|
|
{"CACertPath", CACertPath(), "ca.crt"},
|
|
{"CAKeyPath", CAKeyPath(), "ca.key"},
|
|
{"ServerCertPath", ServerCertPath(), "server.crt"},
|
|
{"ServerKeyPath", ServerKeyPath(), "server.key"},
|
|
{"SSHKeyPath", SSHKeyPath(), "orca_ssh_key"},
|
|
{"SSHPubPath", SSHPubPath(), "orca_ssh_key.pub"},
|
|
{"KnownHostsPath", KnownHostsPath(), "known_hosts"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
want := filepath.Join(dir, tc.file)
|
|
if tc.got != want {
|
|
t.Errorf("%s = %q, want %q", tc.name, tc.got, want)
|
|
}
|
|
})
|
|
}
|
|
|
|
if got, want := DBPath(), filepath.Join(dir, "orca.db"); got != want {
|
|
t.Errorf("DBPath = %q, want %q", got, want)
|
|
}
|
|
|
|
if got, want := Dir(), dir; got != want {
|
|
t.Errorf("Dir = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestShim_DelegatesDirToPaths(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
if got, want := Dir(), paths.Root(); got != want {
|
|
t.Errorf("Dir() = %q, paths.Root() = %q (shim must delegate)", got, want)
|
|
}
|
|
if got, want := Dir(), dir; got != want {
|
|
t.Errorf("Dir() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDBPath_OrcaDBOverride(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ORCA_HOME", home)
|
|
custom := filepath.Join(t.TempDir(), "custom.db")
|
|
t.Setenv("ORCA_DB", custom)
|
|
|
|
if got := DBPath(); got != custom {
|
|
t.Errorf("DBPath = %q, want %q (ORCA_DB override)", got, custom)
|
|
}
|
|
}
|
|
|
|
func TestDBPath_OrcaDBEmptyStringFallsBackToHome(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ORCA_HOME", home)
|
|
t.Setenv("ORCA_DB", "")
|
|
|
|
want := filepath.Join(home, "orca.db")
|
|
if got := DBPath(); got != want {
|
|
t.Errorf("DBPath = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDir_DefaultHomeFallback(t *testing.T) {
|
|
os.Unsetenv("ORCA_HOME")
|
|
os.Unsetenv("ORCA_DB")
|
|
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
t.Skipf("os.UserHomeDir: %v (cannot verify default fallback)", err)
|
|
}
|
|
want := filepath.Join(home, defaultHomeSubdir)
|
|
if got := Dir(); got != want {
|
|
t.Errorf("Dir() default = %q, want %q", got, want)
|
|
}
|
|
if got := CACertPath(); got != filepath.Join(want, "ca.crt") {
|
|
t.Errorf("CACertPath default = %q, want %q", got, filepath.Join(want, "ca.crt"))
|
|
}
|
|
}
|
|
|
|
func TestDir_ORCAHOMEEmptyFallsBack(t *testing.T) {
|
|
t.Setenv("ORCA_HOME", "")
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
t.Skipf("os.UserHomeDir: %v", err)
|
|
}
|
|
want := filepath.Join(home, defaultHomeSubdir)
|
|
if got := Dir(); got != want {
|
|
t.Errorf("Dir() with empty ORCA_HOME = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDir_ORCAHOMERelativePath(t *testing.T) {
|
|
t.Setenv("ORCA_HOME", "relative/orca/home")
|
|
if got, want := Dir(), "relative/orca/home"; got != want {
|
|
t.Errorf("Dir() relative = %q, want %q", got, want)
|
|
}
|
|
if got, want := CACertPath(), filepath.Join("relative/orca/home", "ca.crt"); got != want {
|
|
t.Errorf("CACertPath relative = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAllPaths_AreConsistentWithDir(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
t.Setenv("ORCA_DB", "")
|
|
|
|
base := Dir()
|
|
for _, p := range []string{
|
|
CACertPath(), CAKeyPath(),
|
|
ServerCertPath(), ServerKeyPath(),
|
|
SSHKeyPath(), SSHPubPath(),
|
|
KnownHostsPath(), DBPath(),
|
|
} {
|
|
if !strings.HasPrefix(p, base+string(filepath.Separator)) && p != filepath.Join(base, filepath.Base(p)) {
|
|
t.Errorf("path %q is not under Dir() %q", p, base)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestShim_ReturnsV08FlatPaths(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
t.Setenv("ORCA_DB", "")
|
|
|
|
root := paths.Root()
|
|
if got, want := CACertPath(), filepath.Join(root, "ca.crt"); got != want {
|
|
t.Errorf("CACertPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := CAKeyPath(), filepath.Join(root, "ca.key"); got != want {
|
|
t.Errorf("CAKeyPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := ServerCertPath(), filepath.Join(root, "server.crt"); got != want {
|
|
t.Errorf("ServerCertPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := ServerKeyPath(), filepath.Join(root, "server.key"); got != want {
|
|
t.Errorf("ServerKeyPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := SSHKeyPath(), filepath.Join(root, "orca_ssh_key"); got != want {
|
|
t.Errorf("SSHKeyPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := SSHPubPath(), filepath.Join(root, "orca_ssh_key.pub"); got != want {
|
|
t.Errorf("SSHPubPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := KnownHostsPath(), filepath.Join(root, "known_hosts"); got != want {
|
|
t.Errorf("KnownHostsPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
if got, want := DBPath(), filepath.Join(root, "orca.db"); got != want {
|
|
t.Errorf("DBPath = %q, want v0.8 flat %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSSHPaths_Filenames(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
if got, want := filepath.Base(SSHKeyPath()), "orca_ssh_key"; got != want {
|
|
t.Errorf("SSHKeyPath base = %q, want %q", got, want)
|
|
}
|
|
if got, want := filepath.Base(SSHPubPath()), "orca_ssh_key.pub"; got != want {
|
|
t.Errorf("SSHPubPath base = %q, want %q", got, want)
|
|
}
|
|
if got, want := filepath.Base(KnownHostsPath()), "known_hosts"; got != want {
|
|
t.Errorf("KnownHostsPath base = %q, want %q", got, want)
|
|
}
|
|
}
|