mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat: Sandbox implementation with seatbelt * refactor: Remove concept of PM_CACHE * fix: Misc fixes * refactor: Sandbox for separation of boundaries * fix: Apply API * fix: Add support for sandbox cleanup * test: Add variable interpolation test * fix: Misc cleanup fixes * chore: Cleanup sandbox registry * chore: Cleanup sandbox policy * chore: Cleanup sandbox * fix: Misc cleanup fixes * fix: Remove violation mode * fix: Update config template * chore: Go mod cleanup * fix: Handle the case when package manager policy is explicitly disabled * fix: Sandbox executor * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com> * test: Remove unused var * test: Add test for seatbelt sandbox driver * fix: Sandbox profile loader from file should use path for caching * test: Add policy test * feat: Add support for config templates * fix: Seatbelt translator handle glob * fix: Merge conflicts * fix: Fix sandbox policy generator for MacOS min permissions * fix: Sandbox path handling bugs * fix: Deny read to dangerous directories * fix: Deny read to dangerous directories * add sandbox e2e (#112) * fix: Sandbox E2E test * fix: Code review fixes * fix: Code review fixes * doc: Add sandbox debugging guide * doc: Update sandbox doc * docs: Add sandbox usage doc * fix: Use better error for sandbox without policy * fix: Add sandbox for npx * fix: Enable PTY for npm --------- Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sahil Bansal <bansalsahil315@gmail.com>
64 lines
2.4 KiB
Go
64 lines
2.4 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, false, cfg.SkipEventLogging, "expected SkipEventLogging false")
|
|
assert.Equal(t, 7, cfg.EventLogRetentionDays, "expected EventLogRetentionDays 7")
|
|
assert.Len(t, cfg.TrustedPackages, 1)
|
|
}
|
|
|
|
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.SkipEventLogging, parsed.SkipEventLogging, "skip_event_logging mismatch")
|
|
assert.Equal(t, def.EventLogRetentionDays, parsed.EventLogRetentionDays, "event_log_retention_days 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")
|
|
}
|