2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIngnitionUser(t *testing.T) {
|
|
|
|
testIgnition(t, `
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_user" "foo" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "foo"
|
|
|
|
password_hash = "password"
|
|
|
|
ssh_authorized_keys = ["keys"]
|
|
|
|
uid = 42
|
|
|
|
gecos = "gecos"
|
|
|
|
home_dir = "home"
|
|
|
|
no_create_home = true
|
|
|
|
primary_group = "primary_group"
|
|
|
|
groups = ["group"]
|
|
|
|
no_user_group = true
|
|
|
|
no_log_init = true
|
|
|
|
shell = "shell"
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_user" "qux" {
|
2017-01-03 12:29:14 +01:00
|
|
|
name = "qux"
|
2017-01-27 20:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
data "ignition_config" "test" {
|
2017-01-03 12:29:14 +01:00
|
|
|
users = [
|
2017-03-06 13:23:04 +01:00
|
|
|
"${data.ignition_user.foo.id}",
|
|
|
|
"${data.ignition_user.qux.id}",
|
2017-01-03 12:29:14 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
`, func(c *types.Config) error {
|
|
|
|
if len(c.Passwd.Users) != 2 {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Lenght of field Users didn't match. Expected: %d, Given: %d", 2, len(c.Passwd.Users))
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u := c.Passwd.Users[0]
|
|
|
|
|
|
|
|
if u.Name != "foo" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Name didn't match. Expected: %s, Given: %s", "foo", u.Name)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.PasswordHash != "password" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field PasswordHash didn't match. Expected: %s, Given: %s", "password", u.PasswordHash)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
2017-06-01 12:37:20 +02:00
|
|
|
if len(u.SSHAuthorizedKeys) != 1 {
|
|
|
|
return fmt.Errorf("Lenght of field SSHAuthorizedKeys didn't match. Expected: %d, Given: %d", 1, len(u.SSHAuthorizedKeys))
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.SSHAuthorizedKeys[0] != "keys" {
|
|
|
|
return fmt.Errorf("Field SSHAuthorizedKeys didn't match. Expected: %s, Given: %s", "keys", u.SSHAuthorizedKeys[0])
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if *u.Create.Uid != uint(42) {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Uid didn't match. Expected: %d, Given: %d", uint(42), u.Create.Uid)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.GECOS != "gecos" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field GECOS didn't match. Expected: %s, Given: %s", "gecos", u.Create.GECOS)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.Homedir != "home" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Homedir didn't match. Expected: %s, Given: %s", "home", u.Create.Homedir)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.NoCreateHome != true {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field NoCreateHome didn't match. Expected: %t, Given: %t", true, u.Create.NoCreateHome)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.PrimaryGroup != "primary_group" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field PrimaryGroup didn't match. Expected: %s, Given: %s", "primary_group", u.Create.PrimaryGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(u.Create.Groups) != 1 {
|
|
|
|
return fmt.Errorf("Lenght of field Groups didn't match. Expected: %d, Given: %d", 1, len(u.Create.Groups))
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
2017-06-01 12:37:20 +02:00
|
|
|
if u.Create.Groups[0] != "group" {
|
|
|
|
return fmt.Errorf("Field Groups didn't match. Expected: %s, Given: %s", "group", u.Create.Groups[0])
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.NoUserGroup != true {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field NoUserGroup didn't match. Expected: %t, Given: %t", true, u.Create.NoUserGroup)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.NoLogInit != true {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field NoLogInit didn't match. Expected: %t, Given: %t", true, u.Create.NoLogInit)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if u.Create.Shell != "shell" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Shell didn't match. Expected: %s, Given: %s", "shell", u.Create.Shell)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u = c.Passwd.Users[1]
|
|
|
|
|
|
|
|
if u.Name != "qux" {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Name didn't match. Expected: %s, Given: %s", "qux", u.Name)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
2017-01-27 20:24:37 +01:00
|
|
|
if u.Create != nil {
|
2017-06-01 12:37:20 +02:00
|
|
|
return fmt.Errorf("Field Create didn't match. Expected: %v, Given: %v", nil, u.Create)
|
2017-01-03 12:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|