]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - main_test.go
nsscash: main_test: test new server response which causes an update
[nsscash/nsscash.git] / main_test.go
index 38499da197bb6fd0be3276e48d11527215a30a8c..ee79db903c3416a7327a04372b08f239f8bdbda6 100644 (file)
@@ -33,11 +33,11 @@ import (
 )
 
 const (
-       configPath = "testdata/config.toml"
-       statePath  = "testdata/state.json"
-       passwdPath = "testdata/passwd.nsscash"
-       plainPath  = "testdata/plain"
-       groupPath  = "testdata/group.nsscash"
+       configPath  = "testdata/config.toml"
+       statePath   = "testdata/state.json"
+       passwdPath  = "testdata/passwd.nsscash"
+       plainPath   = "testdata/plain"
+       groupPath   = "testdata/group.nsscash"
        tlsCAPath   = "testdata/ca.crt"
        tlsCertPath = "testdata/server.crt"
        tlsKeyPath  = "testdata/server.key"
@@ -426,6 +426,7 @@ func fetchPasswd(a args) {
        mustMakeOld(t, passwdPath, statePath)
 
        lastChange := time.Now()
+       change := false
        *a.handler = func(w http.ResponseWriter, r *http.Request) {
                if r.URL.Path != "/passwd" {
                        return
@@ -438,16 +439,19 @@ func fetchPasswd(a args) {
                                t.Fatalf("invalid If-Modified-Since %v",
                                        modified)
                        }
-                       if !x.Before(lastChange) {
+                       if !x.Before(lastChange.Truncate(time.Second)) {
                                w.WriteHeader(http.StatusNotModified)
                                return
                        }
                }
 
                w.Header().Add("Last-Modified",
-                       lastChange.Format(http.TimeFormat))
+                       lastChange.UTC().Format(http.TimeFormat))
                fmt.Fprintln(w, "root:x:0:0:root:/root:/bin/bash")
                fmt.Fprintln(w, "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin")
+               if change {
+                       fmt.Fprintln(w, "bin:x:2:2:bin:/bin:/usr/sbin/nologin")
+               }
        }
 
        err = mainFetch(configPath)
@@ -487,6 +491,22 @@ func fetchPasswd(a args) {
        mustNotExist(t, plainPath, groupPath)
        mustBeNew(t, passwdPath, statePath)
        mustHaveHash(t, passwdPath, "bbb7db67469b111200400e2470346d5515d64c23")
+
+       t.Log("Fetch again with newer server response")
+
+       change = true
+       lastChange = time.Now().Add(time.Second)
+
+       mustMakeOld(t, passwdPath, statePath)
+
+       err = mainFetch(configPath)
+       if err != nil {
+               t.Error(err)
+       }
+
+       mustNotExist(t, plainPath, groupPath)
+       mustBeNew(t, passwdPath, statePath)
+       mustHaveHash(t, passwdPath, "ca9c7477cb425667fc9ecbd79e8e1c2ad0e84423")
 }
 
 func fetchPlainEmpty(a args) {