mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* docs(specs): add custom block messages and package blocklist spec * docs(specs): add custom block messages and package blocklist implementation plan * feat(config): add blocked_packages list and custom block messages * feat(audit): add package_blocklist_blocked event and blocklist model * feat(proxy): block blocklisted packages in the policy gate before analysis * feat(guard): block blocklisted packages before trust skip and analysis * feat(ui): render blocklist blocks and custom messages, fix silent-mode block output * feat(proxy): append custom messages to malware and go-cooldown block bodies * test(proxye2e): cover blocklist enforcement and custom block messages * docs(specs): remove spec and plan documents * refactor: drop guard-flow blocklist enforcement and trim docs Guard mode is being deprecated; the blocklist is enforced in proxy mode only. Remove the trusted_packages mirroring references outside the docs. * refactor(config): consolidate blocklist and block message under top-level block section Replace dependency_cooldown.message, malware.message and blocked_packages with a single block section: block.message is appended to every block output regardless of which control blocked, and block.packages is the package blocklist. * fix(ui): render block.message as info note with clean spacing * fix(ui): indent wrapped continuation lines in block reasons and messages * update config template * refactor(config): replace block section with top-level advisory_message Remove the package blocklist (will be implemented as part of policies in the future) and replace block.message with an optional top-level advisory_message appended to every block output. * chore(config): move advisory_message near top-level scalar configs in template
74 lines
3.1 KiB
Go
74 lines
3.1 KiB
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/spf13/viper"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestTemplateParsesAsYAML(t *testing.T) {
|
|
var cfg Config
|
|
|
|
// Defensive check: Ensure template is valid YAML (not used for mapstructure mapping)
|
|
var raw map[string]any
|
|
err := yaml.Unmarshal([]byte(templateConfig), &raw)
|
|
assert.NoError(t, err, "templateConfig must be valid YAML")
|
|
|
|
// Ensure Viper (mapstructure) maps to Config as expected
|
|
v := viper.New()
|
|
v.SetConfigType("yaml")
|
|
err = v.ReadConfig(strings.NewReader(templateConfig))
|
|
assert.NoError(t, err, "expected no error while reading config")
|
|
|
|
err = v.Unmarshal(&cfg)
|
|
assert.NoError(t, err, "expected no error while unmarshalling config")
|
|
|
|
assert.True(t, true, cfg.Transitive, "expected Transitive true")
|
|
assert.Equal(t, 5, cfg.TransitiveDepth, "expected TransitiveDepth 5")
|
|
assert.False(t, false, cfg.IncludeDevDependencies, "expected IncludeDevDependencies false")
|
|
assert.False(t, false, cfg.Paranoid, "expected Paranoid false")
|
|
assert.False(t, cfg.DisableTelemetry, "expected DisableTelemetry false")
|
|
assert.False(t, false, cfg.SkipEventLogging, "expected SkipEventLogging false")
|
|
assert.Equal(t, 7, cfg.EventLogRetentionDays, "expected EventLogRetentionDays 7")
|
|
assert.Len(t, cfg.TrustedPackages, 1)
|
|
assert.Empty(t, cfg.AdvisoryMessage)
|
|
}
|
|
|
|
func TestTemplateMatchesDefaults(t *testing.T) {
|
|
var parsed Config
|
|
|
|
v := viper.New()
|
|
v.SetConfigType("yaml")
|
|
err := v.ReadConfig(strings.NewReader(templateConfig))
|
|
assert.NoError(t, err, "expected no error while reading config")
|
|
|
|
err = v.Unmarshal(&parsed)
|
|
assert.NoError(t, err, "expected no error while unmarshalling config")
|
|
|
|
def := DefaultConfig().Config
|
|
|
|
assert.Equal(t, def.Transitive, parsed.Transitive, "transitive mismatch")
|
|
assert.Equal(t, def.TransitiveDepth, parsed.TransitiveDepth, "transitive_depth mismatch")
|
|
assert.Equal(t, def.IncludeDevDependencies, parsed.IncludeDevDependencies, "include_dev_dependencies mismatch")
|
|
assert.Equal(t, def.Paranoid, parsed.Paranoid, "paranoid mismatch")
|
|
assert.Equal(t, def.DisableTelemetry, parsed.DisableTelemetry, "disable_telemetry mismatch")
|
|
assert.Equal(t, def.SkipEventLogging, parsed.SkipEventLogging, "skip_event_logging mismatch")
|
|
assert.Equal(t, def.EventLogRetentionDays, parsed.EventLogRetentionDays, "event_log_retention_days mismatch")
|
|
assert.Equal(t, def.Verbosity, parsed.Verbosity, "verbosity mismatch")
|
|
|
|
assert.NotEmpty(t, parsed.TrustedPackages, "expected at least one trusted_packages entry")
|
|
|
|
first := parsed.TrustedPackages[0]
|
|
assert.NotEmpty(t, first.Purl, "first trusted package has empty purl")
|
|
assert.NotEmpty(t, first.Reason, "first trusted package has empty reason")
|
|
|
|
assert.Equal(t, def.DependencyCooldown.Enabled, parsed.DependencyCooldown.Enabled, "dependency_cooldown.enabled mismatch")
|
|
assert.Equal(t, def.DependencyCooldown.Days, parsed.DependencyCooldown.Days, "dependency_cooldown.days mismatch")
|
|
assert.Equal(t, def.AdvisoryMessage, parsed.AdvisoryMessage, "advisory_message mismatch")
|
|
|
|
assert.Equal(t, def.Cloud.Enabled, parsed.Cloud.Enabled, "cloud.enabled mismatch")
|
|
}
|