mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-08 09:15:29 -04:00
AB#2046 : Add option to create SSH users for the first coordinator upon initialization (#133)
* Move `file`, `ssh` and `user` packages to internal * Rename `SSHKey` to `(ssh.)UserKey` * Rename KeyValue / Publickey to PublicKey * Rename SSH key file from "debugd" to "ssh-keys" * Add CreateSSHUsers function to Core * Call CreateSSHUsers users on first control-plane node, when defined in config Tests: * Make StubUserCreator add entries to /etc/passwd * Add NewLinuxUserManagerFake for unit tests * Add unit tests & adjust existing ones to changes
This commit is contained in:
parent
5dc2e71d80
commit
68092f27dd
63 changed files with 879 additions and 554 deletions
66
internal/deploy/user/passwd_test.go
Normal file
66
internal/deploy/user/passwd_test.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
filename := "/etc/passwd"
|
||||
|
||||
testCases := map[string]struct {
|
||||
passwdContents string
|
||||
createFile bool
|
||||
wantEntries Entries
|
||||
wantErr bool
|
||||
}{
|
||||
"parse works": {
|
||||
passwdContents: "root:x:0:0:root:/root:/bin/bash\n",
|
||||
createFile: true,
|
||||
wantEntries: Entries{
|
||||
"root": {
|
||||
Pass: "x",
|
||||
Uid: "0",
|
||||
Gid: "0",
|
||||
Gecos: "root",
|
||||
Home: "/root",
|
||||
Shell: "/bin/bash",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
"passwd is corrupt": {
|
||||
passwdContents: "too:few:fields\n",
|
||||
createFile: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"file does not exist": {
|
||||
createFile: false,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
fs := afero.NewMemMapFs()
|
||||
if tc.createFile {
|
||||
assert.NoError(afero.WriteFile(fs, filename, []byte(tc.passwdContents), 0o644))
|
||||
}
|
||||
passwd := Passwd{}
|
||||
entries, err := passwd.Parse(fs)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
assert.Equal(tc.wantEntries, entries)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue