@@ -2,6 +2,7 @@ package settings_test
22
33import (
44 prefs "common/preferences"
5+ "common/registry"
56 "common/settings"
67 "os/exec"
78 "reflect"
@@ -10,6 +11,43 @@ import (
1011
1112const firewallSettingsTestRoot = "HKCU/Software/NVMTest/firewall_settings"
1213
14+ func TestEnforcementSource (t * testing.T ) {
15+ oldSecurity := append ([]string (nil ), prefs .SECURITY_POLICY_ROOTS ... )
16+ oldMachine := prefs .MACHINE_PREFERENCE_ROOT
17+ oldUser := prefs .USER_PREFERENCE_ROOT
18+ root := "HKCU/Software/NVMTest/enforcement_source"
19+ prefs .SECURITY_POLICY_ROOTS = []string {root + "/policy" }
20+ prefs .MACHINE_PREFERENCE_ROOT = root + "/machine"
21+ prefs .USER_PREFERENCE_ROOT = root + "/user"
22+ t .Cleanup (func () {
23+ _ = exec .Command ("reg" , "delete" , `HKCU\Software\NVMTest\enforcement_source` , "/f" ).Run ()
24+ prefs .SECURITY_POLICY_ROOTS = oldSecurity
25+ prefs .MACHINE_PREFERENCE_ROOT = oldMachine
26+ prefs .USER_PREFERENCE_ROOT = oldUser
27+ })
28+
29+ if err := registry .Put ([]string {"https://user.example/trust" }, root + "/user/ApprovedModules" ); err != nil {
30+ t .Fatalf ("seed user: %v" , err )
31+ }
32+ if got := settings .EnforcementSource ("approved_modules" ); got != "your settings" {
33+ t .Fatalf ("user source=%q" , got )
34+ }
35+
36+ if err := registry .Put ([]string {"https://machine.example/trust" }, root + "/machine/ApprovedModules" ); err != nil {
37+ t .Fatalf ("seed machine: %v" , err )
38+ }
39+ if got := settings .EnforcementSource ("approved_modules" ); got != "machine settings" {
40+ t .Fatalf ("machine source=%q" , got )
41+ }
42+
43+ if err := registry .Put ([]string {"https://policy.example/trust" }, root + "/policy/ApprovedModules" ); err != nil {
44+ t .Fatalf ("seed policy: %v" , err )
45+ }
46+ if got := settings .EnforcementSource ("approved_modules" ); got != "machine policy" {
47+ t .Fatalf ("policy source=%q" , got )
48+ }
49+ }
50+
1351func withFirewallPrefs (t * testing.T ) {
1452 t .Helper ()
1553
0 commit comments