1- // Copyright 2022, 2023 Chainguard, Inc.
1+ // Copyright 2022-2026 Chainguard, Inc.
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ import (
1818 "bytes"
1919 "testing"
2020
21+ "github.com/stretchr/testify/assert"
2122 "github.com/stretchr/testify/require"
2223
2324 apkfs "chainguard.dev/apko/pkg/apk/fs"
@@ -28,15 +29,40 @@ func TestGroupParser(t *testing.T) {
2829 gf , err := ReadOrCreateGroupFile (fsys , "group" )
2930 require .NoError (t , err )
3031
32+ require .NotEmpty (t , gf , "group file in existing testdata file should not be empty" )
33+
34+ found_root := false
35+ found_daemon := false
36+ found_nobody := false
3137 for _ , ge := range gf .Entries {
3238 if ge .GID == 0 {
33- require .Equal (t , "root" , ge .GroupName , "gid 0 is not root" )
39+ assert .Equal (t , "root" , ge .GroupName , "gid 0 is not root" )
40+ assert .Equal (t , "x" , ge .Password , "gid 0 password entry is not set to x" )
41+ assert .Equal (t , []string {"root" }, ge .Members , "gid 0 members should just be the root user" )
42+ found_root = true
43+ }
44+
45+ if ge .GID == 2 {
46+ assert .Equal (t , "daemon" , ge .GroupName , "gid 2 is not daemon" )
47+ assert .Equal (t , "x" , ge .Password , "gid 2 password entry is not set to x" )
48+ assert .ElementsMatch (t , []string {"root" , "bin" , "daemon" }, ge .Members , "gid 2 members should contain root, bin, and daemon users" )
49+ found_daemon = true
3450 }
3551
3652 if ge .GID == 65534 {
37- require .Equal (t , "nobody" , ge .GroupName , "gid 65534 is not nobody" )
53+ assert .Equal (t , "nobody" , ge .GroupName , "gid 65534 is not nobody" )
54+ assert .Equal (t , "x" , ge .Password , "gid 65534 password entry is not set to x" )
55+ // XXX if there's no users listed as group members, Parse
56+ // returns a list with one empty string as a result, not
57+ // sure if that's intended behavior.
58+ assert .Equal (t , []string {"" }, ge .Members , "gid 65534 members should be empty" )
59+ found_nobody = true
3860 }
3961 }
62+
63+ assert .True (t , found_root , "group file should contain the root group" )
64+ assert .True (t , found_daemon , "group file should contain the daemon group" )
65+ assert .True (t , found_nobody , "group file should contain the nobody group" )
4066}
4167
4268func TestGroupWriter (t * testing.T ) {
0 commit comments