- name rule, existing targets, framework resolution order, inside-checkout refusal - cleanup on failure, key validation, .env 0600, AGENTS.md symlink - first commit identity, configured identity, missing git, --no-git, --no-plugin build - plugin:add relative go.work, plain make:plugin routes, GenerateAppKey, summer new via the CLI
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package lagoon
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/base64"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
)
|
|
|
|
func TestEncryptedKeyGeneratePrints32ByteBase64(t *testing.T) {
|
|
cmd := KeyGenerateCommand()
|
|
if cmd.Name != "key:generate" {
|
|
t.Fatalf("Name = %q", cmd.Name)
|
|
}
|
|
if cmd.Run == nil {
|
|
t.Fatal("Run is nil")
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
out := bonfire.NewOutput(strings.NewReader(""), &buf, &buf)
|
|
if err := cmd.Run(context.Background(), nil, out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
line := strings.TrimSpace(buf.String())
|
|
fields := strings.Fields(line)
|
|
if len(fields) == 0 {
|
|
t.Fatal("key:generate produced no output")
|
|
}
|
|
encoded := fields[len(fields)-1]
|
|
raw, err := base64.StdEncoding.DecodeString(encoded)
|
|
if err != nil {
|
|
t.Fatalf("output %q is not base64: %v", encoded, err)
|
|
}
|
|
if len(raw) != 32 {
|
|
t.Fatalf("decoded key length = %d, want 32", len(raw))
|
|
}
|
|
}
|
|
|
|
// TestGenerateAppKey: 44 characters, 32 decoded bytes, distinct values.
|
|
func TestGenerateAppKey(t *testing.T) {
|
|
a, err := GenerateAppKey()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := GenerateAppKey()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(a) != 44 || a == b {
|
|
t.Fatalf("keys %q and %q: want two distinct 44-character values", a, b)
|
|
}
|
|
raw, err := base64.StdEncoding.DecodeString(a)
|
|
if err != nil || len(raw) != 32 {
|
|
t.Fatalf("key %q decodes to %d bytes, err %v", a, len(raw), err)
|
|
}
|
|
}
|