X-Git-Url: https://ruderich.org/simon/gitweb/?p=nsscash%2Fnsscash.git;a=blobdiff_plain;f=main_test.go;h=31c9e50064f21276776f5e344edc62da53f9aad0;hp=181930f29da7034c7bac6d94b16b09ea7f11cd7d;hb=a8a8f9daebe164d067d004458679dd7e7f0dc087;hpb=1fd1cdf4c15d3736aad506ce1ce6e73bdb0b2c94 diff --git a/main_test.go b/main_test.go index 181930f..31c9e50 100644 --- a/main_test.go +++ b/main_test.go @@ -25,6 +25,7 @@ import ( "net/http" "net/http/httptest" "os" + "path/filepath" "reflect" "runtime" "strings" @@ -34,7 +35,7 @@ import ( const ( configPath = "testdata/config.toml" - statePath = "testdata/state.json" + statePath = "testdata/var/state.json" passwdPath = "testdata/passwd.nsscash" plainPath = "testdata/plain" groupPath = "testdata/group.nsscash" @@ -269,6 +270,13 @@ func runMainTest(t *testing.T, f func(args), tls *tls.Config) { // Remove the file at the end of this test run, if it // was created defer os.Remove(p) + + dir := filepath.Dir(p) + err = os.MkdirAll(dir, 0755) + if err != nil { + t.Fatal(err) + } + defer os.Remove(dir) // remove empty directories } var handler func(http.ResponseWriter, *http.Request) @@ -710,23 +718,27 @@ func fetchStateCannotWrite(a args) { mustHaveHash(t, groupPath, "da39a3ee5e6b4b0d3255bfef95601890afd80709") *a.handler = func(w http.ResponseWriter, r *http.Request) { - // To prevent mainFetch() from trying to update groupPath - // which will also fail - w.WriteHeader(http.StatusNotModified) + if r.URL.Path != "/group" { + return + } + + fmt.Fprintln(w, "root:x:0:") + fmt.Fprintln(w, "daemon:x:1:andariel,duriel,mephisto,diablo,baal") } - err := os.Chmod("testdata", 0500) + err := os.Chmod(filepath.Dir(statePath), 0500) if err != nil { t.Fatal(err) } - defer os.Chmod("testdata", 0755) + defer os.Chmod(filepath.Dir(statePath), 0755) err = mainFetch(configPath) mustBeErrorWithSubstring(t, err, "permission denied") mustNotExist(t, statePath, passwdPath, plainPath) - mustBeOld(t, groupPath) + mustBeNew(t, groupPath) + mustHaveHash(t, groupPath, "8c27a8403278ba2e392b86d98d4dff1fdefcafdd") } func fetchCannotDeploy(a args) {