}
}
-// mustMakeOld verifies that all paths have a modification time in the past,
-// as set by mustMakeOld().
+// mustBeOld verifies that all paths have a modification time in the past, as
+// set by mustMakeOld.
func mustBeOld(t *testing.T, paths ...string) {
for _, p := range paths {
i, err := os.Stat(p)
}
mtime := i.ModTime()
- now := time.Now()
- if now.Sub(mtime) < time.Hour {
+ if time.Since(mtime) < time.Hour {
t.Errorf("%q was recently modified", p)
}
}
}
mtime := i.ModTime()
- now := time.Now()
- if now.Sub(mtime) > time.Hour {
+ if time.Since(mtime) > time.Hour {
t.Errorf("%q was not recently modified", p)
}
}
// Perform most tests with passwd for simplicity
fetchPasswdCacheFileDoesNotExist,
fetchPasswd404,
+ fetchPasswdUnexpected304,
fetchPasswdEmpty,
fetchPasswdInvalid,
fetchPasswdLimits,
"status code 404")
mustNotExist(t, statePath, plainPath, groupPath)
- mustBeOld(a.t, passwdPath)
+ mustBeOld(t, passwdPath)
+}
+
+func fetchPasswdUnexpected304(a args) {
+ t := a.t
+ mustWritePasswdConfig(t, a.url)
+ mustCreate(t, passwdPath)
+
+ *a.handler = func(w http.ResponseWriter, r *http.Request) {
+ // 304
+ w.WriteHeader(http.StatusNotModified)
+ }
+
+ err := mainFetch(configPath)
+ mustBeErrorWithSubstring(t, err,
+ "status code 304 but did not send If-Modified-Since")
+
+ mustNotExist(t, statePath, plainPath, groupPath)
+ mustBeOld(t, passwdPath)
}
func fetchPasswdEmpty(a args) {
statePath+": permission denied")
mustNotExist(t, passwdPath, plainPath, groupPath)
+ mustBeOld(t, statePath)
}
func fetchStateInvalid(a args) {
err = mainFetch(configPath)
mustBeErrorWithSubstring(t, err,
"file[0].username/passsword in use and unsafe permissions "+
- "-rw-r--r-- on \"testdata/config.toml\"")
+ "-rw-r--r-- on \""+configPath+"\"")
mustNotExist(t, statePath, groupPath, plainPath)
mustBeOld(t, passwdPath)