1 // Copyright (C) 2019 Simon Ruderich
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Affero General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Affero General Public License for more details.
13 // You should have received a copy of the GNU Affero General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
25 func TestParsePasswd(t *testing.T) {
37 "root:x:0:0:root:/root:/bin/zsh",
39 fmt.Errorf("no newline in last line: \"root:x:0:0:root:/root:/bin/zsh\""),
42 "root:x:0:0:root:/root:/bin/zsh\n",
57 "root:x:0:0:root:/root:/bin/zsh\n" +
58 "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n" +
59 "bin:x:2:3:bin:/bin:/usr/sbin/nologin\n",
77 Shell: "/usr/sbin/nologin",
86 Shell: "/usr/sbin/nologin",
93 for n, tc := range tests {
94 res, err := ParsePasswds(strings.NewReader(tc.data))
95 if !reflect.DeepEqual(err, tc.err) {
96 t.Errorf("%d: err = %v, want %v",
99 if !reflect.DeepEqual(res, tc.exp) {
100 t.Errorf("%d: res = %v, want %v",