func (s *createUserSuite) TestAddSudoUser(c *check.C) { mockSudoers := c.MkDir() restorer := osutil.MockSudoersDotD(mockSudoers) defer restorer() err := osutil.AddUser("karl.sagan", &osutil.AddUserOptions{ Gecos: "my gecos", Sudoer: true, ExtraUsers: true, }) c.Assert(err, check.IsNil) c.Check(s.mockAddUser.Calls(), check.DeepEquals, [][]string{ {"adduser", "--force-badname", "--gecos", "my gecos", "--disabled-password", "--extrausers", "karl.sagan"}, }) fs, _ := filepath.Glob(filepath.Join(mockSudoers, "*")) c.Assert(fs, check.HasLen, 1) c.Assert(filepath.Base(fs[0]), check.Equals, "create-user-karl%2Esagan") bs, err := ioutil.ReadFile(fs[0]) c.Assert(err, check.IsNil) c.Check(string(bs), check.Equals, ` # Created by snap create-user # User rules for karl.sagan karl.sagan ALL=(ALL) NOPASSWD:ALL `) }
func (s *createUserSuite) TestAddUserWithPassword(c *check.C) { mockSudoers := c.MkDir() restorer := osutil.MockSudoersDotD(mockSudoers) defer restorer() err := osutil.AddUser("karl.sagan", &osutil.AddUserOptions{ Gecos: "my gecos", Password: "******", }) c.Assert(err, check.IsNil) c.Check(s.mockAddUser.Calls(), check.DeepEquals, [][]string{ {"adduser", "--force-badname", "--gecos", "my gecos", "--disabled-password", "karl.sagan"}, }) c.Check(s.mockUserMod.Calls(), check.DeepEquals, [][]string{ {"usermod", "--password", "$6$salt$hash", "karl.sagan"}, }) }