Export the reviewed allowlisted snapshot from private source commit 07c1655921f21ee5e4fc4d85639d199e8867b17d. This records the Docker Compose activation, schema-compatible rollback, and stateful migration resource findings from Observatory Preview 19 dogfooding. AI-Assisted: OpenAI Codex Signed-off-by: Cole Speelman <crspeelman@gmail.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package eventlog
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAppendBoundedEvent(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "events.jsonl")
|
|
id, err := OperationID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
event := Event{Version: 1, OperationID: id, Service: "site", ArtifactDigest: strings.Repeat("a", 64), Commit: strings.Repeat("b", 40), ReleaseVersion: "v0.2.0-preview.1", Phase: "activation", Slot: "green", Outcome: "succeeded", ObservedAt: time.Now().UTC().Format(time.RFC3339Nano)}
|
|
if err := Append(path, event); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var decoded Event
|
|
if err := json.Unmarshal(b, &decoded); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if decoded.OperationID != id || strings.Contains(string(b), "secret") {
|
|
t.Fatalf("unexpected event: %s", b)
|
|
}
|
|
if info, _ := os.Stat(path); info.Mode().Perm() != 0o640 {
|
|
t.Fatalf("mode=%04o", info.Mode().Perm())
|
|
}
|
|
}
|
|
|
|
func TestAppendRejectsUnboundedValuesAndSymlink(t *testing.T) {
|
|
id, _ := OperationID()
|
|
event := Event{Version: 1, OperationID: id, Service: "site\nsecret", ArtifactDigest: "digest", Commit: "commit", ReleaseVersion: "version", Phase: "activation", Outcome: "failed", ObservedAt: time.Now().UTC().Format(time.RFC3339Nano)}
|
|
if err := Append(filepath.Join(t.TempDir(), "events.jsonl"), event); err == nil {
|
|
t.Fatal("expected unsafe value rejection")
|
|
}
|
|
dir := t.TempDir()
|
|
target := filepath.Join(dir, "target")
|
|
if err := os.WriteFile(target, nil, 0o640); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
link := filepath.Join(dir, "events.jsonl")
|
|
if err := os.Symlink(target, link); err != nil {
|
|
t.Skip(err)
|
|
}
|
|
event.Service = "site"
|
|
if err := Append(link, event); err == nil {
|
|
t.Fatal("expected symlink rejection")
|
|
}
|
|
}
|