t = zero // force download
}
+ oldT := t
status, body, err := fetchIfModified(file.Url,
file.Username, file.Password, file.CA, &t)
if err != nil {
return err
}
if status == http.StatusNotModified {
+ if oldT.IsZero() {
+ return fmt.Errorf("status code 304 " +
+ "but did not send If-Modified-Since")
+ }
log.Printf("%q -> %q: not modified", file.Url, file.Path)
return nil
}
// Perform most tests with passwd for simplicity
fetchPasswdCacheFileDoesNotExist,
fetchPasswd404,
+ fetchPasswdUnexpected304,
fetchPasswdEmpty,
fetchPasswdInvalid,
fetchPasswdLimits,
mustBeOld(a.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(a.t, passwdPath)
+}
+
func fetchPasswdEmpty(a args) {
t := a.t
mustWritePasswdConfig(t, a.url)