ft.CreateFile("no-changes.example.org/permissions.yaml",
noChangePermissions, 0644)
- skipUnlessCiRun := len(os.Getenv("SAFCM_CI_RUN")) == 0
+ ciRun := len(os.Getenv("SAFCM_CI_RUN")) != 0
+ isRoot := os.Getuid() == 0
+ skipUnlessHarmless := !(ciRun || !isRoot)
tests := []struct {
name string
nil,
},
- // NOTE: We use -n on regular runs to prevent changing anything
- // important on the host when running as root!
+ // NOTE: We use -n on regular runs when running as root to prevent
+ // changing anything important on the host
{
"no changes (dry-run)",
},
{
"no changes",
- skipUnlessCiRun,
+ skipUnlessHarmless,
true,
[]string{"no-changes.example.org"},
`<LOG>[info] [no-changes.example.org] remote helper upload in progress
},
{
"no changes (-log debug2)",
- skipUnlessCiRun,
+ skipUnlessHarmless,
true,
[]string{"-log", "debug2", "no-changes.example.org"},
`<LOG>[info] [no-changes.example.org] remote helper upload in progress
}
user, uid, group, gid := ft.CurrentUserAndGroup()
- skipUnlessCiRun := len(os.Getenv("SAFCM_CI_RUN")) == 0
-
- tmpTestFilePath := "/tmp/safcm-sync-files-test-file"
+ ciRun := len(os.Getenv("SAFCM_CI_RUN")) != 0
+ isRoot := os.Getuid() == 0
+ skipUnlessHarmless := !(ciRun || !isRoot)
+
+ tmpTestFilePath := "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file"
+ _, err := os.Stat(tmpTestFilePath)
+ if err == nil {
+ // Very unlikely, but just in case
+ t.Fatalf("%q already exists, aborting to prevent data loss",
+ tmpTestFilePath)
+ }
tests := []struct {
name string
// Use numeric IDs as not all systems use root/root; for example
// BSDs use root/wheel.
"absolute paths: no change",
- skipUnlessCiRun,
+ skipUnlessHarmless,
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
{
"triggers: absolute paths",
- skipUnlessCiRun,
+ skipUnlessHarmless,
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
"/",
"/tmp",
// Don't use variable for more robust test
- "/tmp/safcm-sync-files-test-file",
+ "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file",
},
[]ft.File{
root,
safcm.MsgSyncResp{
FileChanges: []safcm.FileChange{
{
- Path: "/tmp/safcm-sync-files-test-file",
+ Path: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file",
Created: true,
New: safcm.FileChangeInfo{
Mode: 0600,
[]string{
`4: files: "/" (group): unchanged`,
`4: files: "/tmp" (group): unchanged`,
- `4: files: "/tmp/safcm-sync-files-test-file" (group): will create`,
- `3: files: "/tmp/safcm-sync-files-test-file" (group): creating`,
- `4: files: "/tmp/safcm-sync-files-test-file" (group): creating temporary file "/tmp/.safcm-sync-files-test-file*"`,
- `4: files: "/tmp/safcm-sync-files-test-file" (group): renaming "/tmp/.safcm-sync-files-test-fileRND"`,
- `3: files: "/tmp/safcm-sync-files-test-file": queuing trigger on "/"`,
- `3: files: "/tmp/safcm-sync-files-test-file": queuing trigger on "/tmp"`,
- `3: files: "/tmp/safcm-sync-files-test-file": queuing trigger on "/tmp/safcm-sync-files-test-file"`,
+ `4: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file" (group): will create`,
+ `3: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file" (group): creating`,
+ `4: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file" (group): creating temporary file "/tmp/.kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file*"`,
+ `4: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file" (group): renaming "/tmp/.kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-fileRND"`,
+ `3: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file": queuing trigger on "/"`,
+ `3: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file": queuing trigger on "/tmp"`,
+ `3: files: "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file": queuing trigger on "/tmp/kjn8W3OR4LFwo4Iw7YLY5-safcm-sync-files-test-file"`,
},
nil,
},