fixed issues with CA now generates its own new cert
All checks were successful
release / build-and-upload (push) Successful in 16m53s

This commit is contained in:
404errordeveloper 2026-10-08 20:16:08 +02:00
parent a930a697fa
commit c1948a1439
11 changed files with 458 additions and 34 deletions

61
apps/pkg/proxy/ca_test.go Normal file
View file

@ -0,0 +1,61 @@
package proxy
import (
"os"
"path/filepath"
"testing"
)
func TestEnsureLocalCAGeneratesUniquePair(t *testing.T) {
root := t.TempDir()
cert1, err := EnsureLocalCA(root)
if err != nil {
t.Fatal(err)
}
want := filepath.Join(root, "data", "proxy-ca.crt")
if cert1 != want {
t.Fatalf("cert path: got %q want %q", cert1, want)
}
key1 := filepath.Join(root, "data", "proxy-ca.key")
if _, err := os.Stat(key1); err != nil {
t.Fatal("missing key", err)
}
hash1, err := AndroidCAHashFile(cert1)
if err != nil || hash1 == "" {
t.Fatalf("hash: %q %v", hash1, err)
}
// Second call reuses the same pair.
cert2, err := EnsureLocalCA(root)
if err != nil {
t.Fatal(err)
}
if cert2 != cert1 {
t.Fatalf("expected reuse, got %q vs %q", cert2, cert1)
}
// A different install root gets a different CA.
rootB := t.TempDir()
certB, err := EnsureLocalCA(rootB)
if err != nil {
t.Fatal(err)
}
hashB, _ := AndroidCAHashFile(certB)
if hashB == hash1 {
t.Fatal("expected different installs to get different CA hashes")
}
}
func TestFindLocalCAIgnoresCertWithoutKey(t *testing.T) {
root := t.TempDir()
dir := filepath.Join(root, "apps", "proxy")
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "rteproxy-ca.crt"), []byte("not-a-real-cert"), 0o644); err != nil {
t.Fatal(err)
}
if p := FindLocalCA(root); p != "" {
t.Fatalf("expected empty without key, got %q", p)
}
}