MCPcopy Index your code
hub / github.com/jetify-com/devbox / TestConfigIsUserTrusted

Function TestConfigIsUserTrusted

internal/nix/config_test.go:9–104  ·  view source on GitHub ↗

nolint:revive

(t *testing.T)

Source from the content-addressed store, hash-verified

7
8//nolint:revive
9func TestConfigIsUserTrusted(t *testing.T) {
10 curUser, err := user.Current()
11 if err != nil {
12 t.Fatal("lookup current user:", err)
13 }
14
15 t.Run("UsernameInList", func(t *testing.T) {
16 t.Setenv("NIX_CONFIG", "trusted-users = "+curUser.Username)
17
18 ctx := t.Context()
19 cfg, err := CurrentConfig(ctx)
20 if err != nil {
21 t.Fatal(err)
22 }
23
24 trusted, err := cfg.IsUserTrusted(ctx, curUser.Username)
25 if err != nil {
26 t.Fatal(err)
27 }
28 if !trusted {
29 t.Error("got trusted = false, want true")
30 }
31 })
32 t.Run("UserGroupInList", func(t *testing.T) {
33 g, err := user.LookupGroupId(curUser.Gid)
34 if err != nil {
35 t.Fatal(err)
36 }
37 t.Setenv("NIX_CONFIG", "trusted-users = @"+g.Name)
38
39 ctx := t.Context()
40 cfg, err := CurrentConfig(ctx)
41 if err != nil {
42 t.Fatal(err)
43 }
44
45 trusted, err := cfg.IsUserTrusted(ctx, curUser.Username)
46 if err != nil {
47 t.Fatal(err)
48 }
49 if !trusted {
50 t.Error("got trusted = false, want true")
51 }
52 })
53 t.Run("NotInList", func(t *testing.T) {
54 t.Setenv("NIX_CONFIG", "trusted-users = root")
55
56 ctx := t.Context()
57 cfg, err := CurrentConfig(ctx)
58 if err != nil {
59 t.Fatal(err)
60 }
61
62 trusted, err := cfg.IsUserTrusted(ctx, curUser.Username)
63 if err != nil {
64 t.Fatal(err)
65 }
66 if trusted {

Callers

nothing calls this directly

Calls 4

CurrentConfigFunction · 0.85
IsUserTrustedMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected