Skip to content

Commit

Permalink
Add blackBox negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemric committed Mar 9, 2022
1 parent 927b71d commit 07d1f1a
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
127 changes: 127 additions & 0 deletions tests/negative/systemd/units.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright 2018 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package systemd

import (
"github.com/coreos/ignition/v2/tests/register"
"github.com/coreos/ignition/v2/tests/types"
)

func init() {
register.Register(register.NegativeTest, CreateSystemdUserServiceNouser())
}

func CreateDefaultDisk(Disk []types.Disk) []types.Disk {
Disk[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "passwd",
Directory: "etc",
},
Contents: "root:x:0:0:root:/root:/bin/bash\ncore:x:500:500:CoreOS Admin:/home/core:/bin/bash\nsystemd-coredump:x:998:998:systemd Core Dumper:/:/sbin/nologin\nfleet:x:253:253::/:/sbin/nologin\n",
},
{
Node: types.Node{
Name: "shadow",
Directory: "etc",
},
Contents: "root:*:15887:0:::::\ncore:*:15887:0:::::\nsystemd-coredump:!!:17301::::::\nfleet:!!:17301::::::\n",
},
{
Node: types.Node{
Name: "group",
Directory: "etc",
},
Contents: "root:x:0:root\nwheel:x:10:root,core\nsudo:x:150:\ndocker:x:233:core\nsystemd-coredump:x:998:\nfleet:x:253:core\ncore:x:500:\nrkt-admin:x:999:\nrkt:x:251:core\n",
},
{
Node: types.Node{
Name: "gshadow",
Directory: "etc",
},
Contents: "root:*::root\nusers:*::\nsudo:*::\nwheel:*::root,core\nsudo:*::\ndocker:*::core\nsystemd-coredump:!!::\nfleet:!!::core\nrkt-admin:!!::\nrkt:!!::core\ncore:*::\n",
},
{
Node: types.Node{
Name: "nsswitch.conf",
Directory: "etc",
},
Contents: "# /etc/nsswitch.conf:\n\npasswd: files\nshadow: files\ngroup: files\n\nhosts: files dns myhostname\nnetworks: files dns\n\nservices: files\nprotocols: files\nrpc: files\n\nethers: files\nnetmasks: files\nnetgroup: files\nbootparams: files\nautomount: files\naliases: files\n",
},
{
Node: types.Node{
Name: "login.defs",
Directory: "etc",
},
Contents: `MAIL_DIR /var/spool/mail
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 201
SYS_UID_MAX 999
GID_MIN 1000
GID_MAX 60000
SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
UMASK 077
USERGROUPS_ENAB yes
ENCRYPT_METHOD SHA512
`,
},
})
return Disk
}

func CreateSystemdUserServiceNouser() types.Test {
name := "systemd.unit.userunit.wronguser"
in := CreateDefaultDisk(types.GetBaseDisk())
out := in
config := `{
"passwd": {
"users": [{
"name": "tester1"
}
]
},
"ignition": {
"version": "$version"
},
"systemd": {
"units": [
{
"contents": "[Unit]\nDescription=promtail.service\n[Install]\nWantedBy=multi-user.target default.target",
"enabled": true,
"name": "unit1.service",
"scope": "user",
"users" : ["tester2"]
}
]
}
}`

configMinVersion := "3.4.0-experimental"

return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}
1 change: 1 addition & 0 deletions tests/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
_ "github.com/coreos/ignition/v2/tests/negative/proxy"
_ "github.com/coreos/ignition/v2/tests/negative/regression"
_ "github.com/coreos/ignition/v2/tests/negative/security"
_ "github.com/coreos/ignition/v2/tests/negative/systemd"
_ "github.com/coreos/ignition/v2/tests/negative/timeouts"
_ "github.com/coreos/ignition/v2/tests/positive/files"
_ "github.com/coreos/ignition/v2/tests/positive/filesystems"
Expand Down

0 comments on commit 07d1f1a

Please sign in to comment.