2023-02-08 11:02:13 +01:00
|
|
|
package config_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-03-30 14:18:53 +03:00
|
|
|
. "github.com/kairos-io/kairos/v2/pkg/config/schemas"
|
2023-02-08 11:02:13 +01:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Users Schema", func() {
|
|
|
|
var config *KConfig
|
|
|
|
var err error
|
|
|
|
var yaml string
|
|
|
|
|
|
|
|
JustBeforeEach(func() {
|
2023-02-14 16:15:13 +01:00
|
|
|
config, err = NewConfigFromYAML(yaml, UserSchema{})
|
2023-02-08 11:02:13 +01:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("When a user has no name", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
yaml = `#cloud-config
|
|
|
|
passwd: foobar`
|
|
|
|
})
|
|
|
|
|
|
|
|
It("errors", func() {
|
|
|
|
Expect(config.IsValid()).NotTo(BeTrue())
|
2023-02-14 16:15:13 +01:00
|
|
|
Expect(config.ValidationError.Error()).To(MatchRegexp("missing properties: 'name'"))
|
2023-02-08 11:02:13 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("When a user name doesn't fit the pattern", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
yaml = `#cloud-config
|
|
|
|
name: "007"
|
|
|
|
passwd: "bond"`
|
|
|
|
})
|
|
|
|
|
|
|
|
It("errors", func() {
|
|
|
|
Expect(config.IsValid()).NotTo(BeTrue())
|
|
|
|
Expect(
|
2023-02-14 16:15:13 +01:00
|
|
|
strings.Contains(config.ValidationError.Error(),
|
2023-02-08 11:02:13 +01:00
|
|
|
"does not match pattern '([a-z_][a-z0-9_]{0,30})'",
|
|
|
|
),
|
|
|
|
).To(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("With only the required attributes", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
yaml = `#cloud-config
|
|
|
|
name: "kairos"`
|
|
|
|
})
|
|
|
|
|
|
|
|
It("succeeds", func() {
|
|
|
|
Expect(config.IsValid()).To(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("With all possible attributes", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
yaml = `#cloud-config
|
|
|
|
name: "kairos"
|
|
|
|
passwd: "kairos"
|
|
|
|
lock_passwd: true
|
2023-03-10 15:25:53 +01:00
|
|
|
groups:
|
|
|
|
- "admin"
|
2023-02-08 11:02:13 +01:00
|
|
|
ssh_authorized_keys:
|
|
|
|
- github:mudler`
|
|
|
|
})
|
|
|
|
|
|
|
|
It("succeeds", func() {
|
|
|
|
Expect(config.IsValid()).To(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|