Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

64 lines
2.4 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package allowlist
import (
"strings"
"testing"
"github.com/larksuite/cli/internal/qualitygate/report"
)
func TestLegacyFlagAllowlistRequiresOwnerReasonAndAddedAt(t *testing.T) {
raw := "docs +fetch\tapi_version\tcli-owner\tlegacy public flag\t2026-06-05\n"
items, diags := ParseLegacyFlags(strings.NewReader(raw))
if len(diags) != 0 || len(items) != 1 {
t.Fatalf("parse allowlist = %#v %#v", items, diags)
}
if items[0].Command != "docs +fetch" || items[0].Flag != "api_version" {
t.Fatalf("item = %#v", items[0])
}
}
func TestLegacyFlagAllowlistRejectsExtraExpiryColumn(t *testing.T) {
raw := "docs +fetch\tapi_version\tcli-owner\tlegacy public flag\t2026-01-01\t2026-02-01\n"
_, diags := ParseLegacyFlags(strings.NewReader(raw))
if len(diags) != 1 || diags[0].Action != report.ActionReject || diags[0].Rule != "allowlist_format" {
t.Fatalf("expected format reject, got %#v", diags)
}
}
func TestLegacyCommandAllowlistRequiresOwnerReasonAndAddedAt(t *testing.T) {
raw := "drive +task_result\tcli-owner\tlegacy public shortcut\t2026-06-05\n"
items, diags := ParseLegacyCommands(strings.NewReader(raw))
if len(diags) != 0 || len(items) != 1 {
t.Fatalf("parse command allowlist = %#v %#v", items, diags)
}
if items[0].Command != "drive +task_result" {
t.Fatalf("command = %q", items[0].Command)
}
}
func TestMalformedLegacyCommandAllowlistRejects(t *testing.T) {
raw := "drive +task_result\tcli-owner\n"
_, diags := ParseLegacyCommands(strings.NewReader(raw))
if len(diags) != 1 || diags[0].Action != report.ActionReject || diags[0].Rule != "allowlist_format" {
t.Fatalf("expected format reject, got %#v", diags)
}
}
func TestLegacyCommandAllowlistTrimsSurroundingWhitespace(t *testing.T) {
// Surrounding spaces around tab-separated columns must be trimmed so the
// stored key matches exact lookups and the date still parses. Internal
// spaces in the command name are preserved.
raw := " drive +task_result \t cli-owner \t legacy public shortcut \t 2026-06-05 \n"
items, diags := ParseLegacyCommands(strings.NewReader(raw))
if len(diags) != 0 || len(items) != 1 {
t.Fatalf("expected one clean row, items=%#v diags=%#v", items, diags)
}
if items[0].Command != "drive +task_result" || items[0].Owner != "cli-owner" || items[0].Reason != "legacy public shortcut" {
t.Fatalf("columns not trimmed: %#v", items[0])
}
}