]> ruderich.org/simon Gitweb - nsscash/nsscash.git/commitdiff
nsscash: main_test: test new server response which causes an update
authorSimon Ruderich <simon@ruderich.org>
Fri, 2 Aug 2019 19:00:51 +0000 (21:00 +0200)
committerSimon Ruderich <simon@ruderich.org>
Fri, 2 Aug 2019 19:00:51 +0000 (21:00 +0200)
The existing tests only tested that a modified local version of the file
causes a download from the server. However, the modified local version
is caught by the checksum in the state file and does not verify that an
update from the server is properly applied. Thus, add this new test.

main_test.go

index 0279bb74ea7e8e709fd6a34d311d30650e1f532c..ee79db903c3416a7327a04372b08f239f8bdbda6 100644 (file)
@@ -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
@@ -448,6 +449,9 @@ func fetchPasswd(a args) {
                        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) {