Skip to content

Commit

Permalink
Fix: change selinux path to name and add module
Browse files Browse the repository at this point in the history
  • Loading branch information
yasminvalim committed Oct 10, 2023
1 parent d79bea2 commit 2a7e202
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var (

// Selinux Module
ErrContentInvalid = errors.New("Content is empty, please provide content.")
ErrPathInvalid = errors.New("Path is empty, please provide a valid path.")
ErrNameInvalid = errors.New("Name is empty, please provide a valid name.")
)

type ErrUnmarshal struct {
Expand Down
16 changes: 10 additions & 6 deletions config/fcos/v1_6_exp/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
)

type Config struct {
base.Config `yaml:",inline"`
BootDevice BootDevice `yaml:"boot_device"`
Grub Grub `yaml:"grub"`
SelinuxModule []SelinuxModule `yaml:"selinux_module"`
base.Config `yaml:",inline"`
BootDevice BootDevice `yaml:"boot_device"`
Grub Grub `yaml:"grub"`
Selinux []Selinux `yaml:"selinux"`
}

type BootDevice struct {
Expand Down Expand Up @@ -51,7 +51,11 @@ type GrubUser struct {
PasswordHash *string `yaml:"password_hash"`
}

type SelinuxModule struct {
type Selinux struct {
Module []Module `yaml:"module"`
}

type Module struct {
Name string `yaml:"name"`
Content string `yaml:"content"`
Path string `yaml:"path"`
}
8 changes: 4 additions & 4 deletions config/fcos/v1_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func (user GrubUser) Validate(c path.ContextPath) (r report.Report) {
return
}

func (se SelinuxModule) Validate(c path.ContextPath) (r report.Report) {
if se.Path != "" && se.Content == "" {
func (m Module) Validate(c path.ContextPath) (r report.Report) {
if m.Name != "" && m.Content == "" {
r.AddOnError(c.Append("content"), common.ErrContentInvalid)
}

if se.Content != "" && se.Path == "" {
r.AddOnError(c.Append("path"), common.ErrPathInvalid)
if m.Content != "" && m.Name == "" {
r.AddOnError(c.Append("name"), common.ErrNameInvalid)
}
return r
}
30 changes: 15 additions & 15 deletions config/fcos/v1_6_exp/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,41 +480,41 @@ func TestValidateConfig(t *testing.T) {
}
}

func TestValidateSelinuxModule(t *testing.T) {
func TestValidateModule(t *testing.T) {
tests := []struct {
in SelinuxModule
in Module
out error
errPath path.ContextPath
}{
{
// content is empty, path is specified
in: SelinuxModule{
// name is empty, path is specified
in: Module{
Content: "",
Path: "/some/path",
Name: "some name",
},
out: common.ErrContentInvalid,
errPath: path.New("yaml", "content"),
},
{
// path is empty, content is specified
in: SelinuxModule{
Path: "",
// name is empty, content is specified
in: Module{
Name: "",
Content: "some content",
},
out: common.ErrPathInvalid,
errPath: path.New("yaml", "path"),
out: common.ErrNameInvalid,
errPath: path.New("yaml", "name"),
},
{
// path and content are empty
in: SelinuxModule{},
// name and content are empty
in: Module{},
out: nil,
errPath: path.New("yaml"),
},
{
// path and content are specified
in: SelinuxModule{
// name and content are specified
in: Module{
Content: "some content",
Path: "/some/path",
Name: "some name",
},
out: nil,
errPath: path.New("yaml"),
Expand Down

0 comments on commit 2a7e202

Please sign in to comment.