Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/config"
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/integration"
|
|
)
|
|
|
|
// TestRenderSettingsList covers `member-console config list`'s rendering
|
|
// rules (design D11, task 2.6): a secret key's value and stored override
|
|
// are masked to "set"/"not set" rather than ever printed, an unrecognized
|
|
// row is marked as such instead of given a winner, and the output always
|
|
// ends with the one fact this process can state about a running app it is
|
|
// not.
|
|
func TestRenderSettingsList(t *testing.T) {
|
|
rows := []integration.SettingsRow{
|
|
{Key: "acme-widget-color", Declared: true, Environment: "blue", Winner: config.SourceDefault},
|
|
{Key: "acme-widget-scheme", Declared: true, Environment: "https", HasOverride: true, Override: "http", Winner: config.SourceOverride},
|
|
{Key: "acme-widget-token", Declared: true, Secret: true, SecretSet: true, HasOverride: true, Winner: config.SourceEnvironment},
|
|
{Key: "acme-widget-key2", Declared: true, Secret: true, SecretSet: false, Winner: config.SourceEnvironment},
|
|
{Key: "acme-orphan-key", Declared: false, HasOverride: true, Override: "x"},
|
|
}
|
|
out := renderSettingsList(rows)
|
|
|
|
for _, want := range []string{
|
|
"acme-widget-color", "blue", "Default",
|
|
"acme-widget-scheme", "https", "http", "Override",
|
|
"acme-widget-key2", "not set",
|
|
"acme-orphan-key", "(unrecognized)", "x",
|
|
"The running app applies changes on restart.",
|
|
} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("output missing %q:\n%s", want, out)
|
|
}
|
|
}
|
|
|
|
// The secret key's value and stored override never appear unmasked.
|
|
if strings.Contains(out, "hunter2") {
|
|
t.Error("a secret value must never be printed")
|
|
}
|
|
lines := strings.Split(strings.TrimRight(out, "\n"), "\n")
|
|
tokenLine := ""
|
|
for _, line := range lines {
|
|
if strings.HasPrefix(line, "acme-widget-token") {
|
|
tokenLine = line
|
|
}
|
|
}
|
|
if tokenLine == "" || !strings.Contains(tokenLine, "set") {
|
|
t.Fatalf("secret row line = %q, want masked to set/not set", tokenLine)
|
|
}
|
|
}
|
|
|
|
func TestFilterSettingsRows(t *testing.T) {
|
|
rows := []integration.SettingsRow{
|
|
{Key: "acme-widget-color", Declared: true},
|
|
{Key: "widget-other-key", Declared: true},
|
|
{Key: "acme-orphan-key", Declared: false},
|
|
}
|
|
got := filterSettingsRows(rows, map[string]bool{"acme-widget-color": true})
|
|
if len(got) != 1 || got[0].Key != "acme-widget-color" {
|
|
t.Fatalf("filtered rows = %+v, want only acme-widget-color", got)
|
|
}
|
|
}
|