mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-11 21:39:01 +00:00
7cda0d7896
Migrates from xarmian/pad to PerpetualSoftware/pad across the entire
repo and updates the product subtitle to "Collaborate with your AI
agents".
Go module rename
- go.mod: github.com/xarmian/pad → github.com/PerpetualSoftware/pad
- All Go imports updated across cmd/pad, internal/{cli,server,store,
models,collections,items,events,metrics,webhooks} (~130 files)
- Test fixtures with the literal repo slug ("xarmian/pad" in JSON
shapes, SSH/HTTPS git URL strings, workspace_context fixtures)
also updated, including the secondary repo entry
(xarmian/pad-web → PerpetualSoftware/pad-web — pad-web was also
moved to the org per branch context)
Docs / config
- README badges, install instructions, brew tap, Docker image, source
build path, sponsor link (sponsor link kept as personal @xarmian)
- Subtitle: "Project management for developers and AI agents." →
"Collaborate with your AI agents." (README, manifests, web layout
meta, .goreleaser homebrew description)
- CONTRIBUTING.md, SECURITY.md, skills/INSTALL.md
- .goreleaser.yaml: homebrew_casks owner, GHCR image, release github
owner, cosign cert-identity regex, comments
- .github/workflows/release.yml: tap/release comments
- deploy/k8s/deployment.yaml: container image
- docs/deployment.md: clone URL
- web/static/{site.webmanifest,manifest.json}: description
- web/src/routes/+layout.svelte: meta description + og:description
Brew tap path is PerpetualSoftware/tap/pad (CamelCase, matches
GitHub user case). GHCR image is ghcr.io/perpetualsoftware/pad
(lowercased per GHCR's URL normalization). CODEOWNERS @xarmian and
FUNDING.yml github: xarmian intentionally retained — those are the
personal maintainer / sponsor account, separate from the org repo.
Verification: go build ./..., go test ./... (all pkgs pass), web
build, and make install all clean (TASK-844, TASK-845).
141 lines
3.1 KiB
Go
141 lines
3.1 KiB
Go
package store
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/PerpetualSoftware/pad/internal/models"
|
|
)
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
s := testStore(t)
|
|
|
|
// Generate a random 32-byte key
|
|
key := make([]byte, 32)
|
|
if _, err := rand.Read(key); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s.SetEncryptionKey(key)
|
|
|
|
// Test basic encrypt/decrypt
|
|
original := "JBSWY3DPEHPK3PXP"
|
|
encrypted, err := s.encrypt(original)
|
|
if err != nil {
|
|
t.Fatalf("encrypt: %v", err)
|
|
}
|
|
if encrypted == original {
|
|
t.Error("encrypted value should differ from original")
|
|
}
|
|
if encrypted[:4] != "enc:" {
|
|
t.Errorf("encrypted value should start with 'enc:', got %q", encrypted[:4])
|
|
}
|
|
|
|
decrypted, err := s.decrypt(encrypted)
|
|
if err != nil {
|
|
t.Fatalf("decrypt: %v", err)
|
|
}
|
|
if decrypted != original {
|
|
t.Errorf("expected %q, got %q", original, decrypted)
|
|
}
|
|
}
|
|
|
|
func TestDecryptPlaintext(t *testing.T) {
|
|
s := testStore(t)
|
|
|
|
key := make([]byte, 32)
|
|
rand.Read(key)
|
|
s.SetEncryptionKey(key)
|
|
|
|
// Plaintext values (no "enc:" prefix) should pass through unchanged
|
|
plain := "JBSWY3DPEHPK3PXP"
|
|
result, err := s.decrypt(plain)
|
|
if err != nil {
|
|
t.Fatalf("decrypt plaintext: %v", err)
|
|
}
|
|
if result != plain {
|
|
t.Errorf("expected %q, got %q", plain, result)
|
|
}
|
|
}
|
|
|
|
func TestEncryptWithoutKey(t *testing.T) {
|
|
s := testStore(t)
|
|
|
|
// No encryption key — encrypt should return plaintext
|
|
original := "JBSWY3DPEHPK3PXP"
|
|
result, err := s.encrypt(original)
|
|
if err != nil {
|
|
t.Fatalf("encrypt without key: %v", err)
|
|
}
|
|
if result != original {
|
|
t.Errorf("without key, encrypt should return plaintext, got %q", result)
|
|
}
|
|
}
|
|
|
|
func TestEncryptDecryptEmpty(t *testing.T) {
|
|
s := testStore(t)
|
|
|
|
key := make([]byte, 32)
|
|
rand.Read(key)
|
|
s.SetEncryptionKey(key)
|
|
|
|
// Empty strings should pass through
|
|
encrypted, err := s.encrypt("")
|
|
if err != nil {
|
|
t.Fatalf("encrypt empty: %v", err)
|
|
}
|
|
if encrypted != "" {
|
|
t.Errorf("expected empty, got %q", encrypted)
|
|
}
|
|
|
|
decrypted, err := s.decrypt("")
|
|
if err != nil {
|
|
t.Fatalf("decrypt empty: %v", err)
|
|
}
|
|
if decrypted != "" {
|
|
t.Errorf("expected empty, got %q", decrypted)
|
|
}
|
|
}
|
|
|
|
func TestTOTPEncryptionRoundTrip(t *testing.T) {
|
|
s := testStore(t)
|
|
|
|
key := make([]byte, 32)
|
|
rand.Read(key)
|
|
s.SetEncryptionKey(key)
|
|
|
|
// Create a user
|
|
u, err := s.CreateUser(models.UserCreate{
|
|
Email: "totp@test.com",
|
|
Name: "TOTP Tester",
|
|
Password: "password123",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("create user: %v", err)
|
|
}
|
|
|
|
// Set TOTP secret (should be encrypted in DB)
|
|
secret := "JBSWY3DPEHPK3PXP"
|
|
if err := s.SetTOTPSecret(u.ID, secret); err != nil {
|
|
t.Fatalf("set totp secret: %v", err)
|
|
}
|
|
|
|
// Read it back — should be decrypted automatically
|
|
fetched, err := s.GetUser(u.ID)
|
|
if err != nil {
|
|
t.Fatalf("get user: %v", err)
|
|
}
|
|
if fetched.TOTPSecret != secret {
|
|
t.Errorf("expected %q, got %q", secret, fetched.TOTPSecret)
|
|
}
|
|
|
|
// Verify the raw value in DB is encrypted
|
|
var rawSecret string
|
|
s.db.QueryRow(s.q("SELECT totp_secret FROM users WHERE id = ?"), u.ID).Scan(&rawSecret)
|
|
if rawSecret == secret {
|
|
t.Error("raw DB value should be encrypted, not plaintext")
|
|
}
|
|
if rawSecret[:4] != "enc:" {
|
|
t.Errorf("raw DB value should start with 'enc:', got %q", rawSecret[:10])
|
|
}
|
|
}
|