1
2
3
4
5 package fips140
6
7 import (
8 "internal/godebug"
9 "os"
10 "testing"
11 )
12
13 func TestImmutableGODEBUG(t *testing.T) {
14 defer func(v string) { os.Setenv("GODEBUG", v) }(os.Getenv("GODEBUG"))
15
16 fips140Enabled := Enabled()
17 fips140Setting := godebug.New("fips140")
18 fips140SettingValue := fips140Setting.Value()
19
20 os.Setenv("GODEBUG", "fips140=off")
21 if Enabled() != fips140Enabled {
22 t.Errorf("Enabled() changed after setting GODEBUG=fips140=off")
23 }
24 if fips140Setting.Value() != fips140SettingValue {
25 t.Errorf("fips140Setting.Value() changed after setting GODEBUG=fips140=off")
26 }
27
28 os.Setenv("GODEBUG", "fips140=on")
29 if Enabled() != fips140Enabled {
30 t.Errorf("Enabled() changed after setting GODEBUG=fips140=on")
31 }
32 if fips140Setting.Value() != fips140SettingValue {
33 t.Errorf("fips140Setting.Value() changed after setting GODEBUG=fips140=on")
34 }
35
36 os.Setenv("GODEBUG", "fips140=")
37 if Enabled() != fips140Enabled {
38 t.Errorf("Enabled() changed after setting GODEBUG=fips140=")
39 }
40 if fips140Setting.Value() != fips140SettingValue {
41 t.Errorf("fips140Setting.Value() changed after setting GODEBUG=fips140=")
42 }
43
44 os.Setenv("GODEBUG", "")
45 if Enabled() != fips140Enabled {
46 t.Errorf("Enabled() changed after setting GODEBUG=")
47 }
48 if fips140Setting.Value() != fips140SettingValue {
49 t.Errorf("fips140Setting.Value() changed after setting GODEBUG=")
50 }
51 }
52
View as plain text