From 379122928e507ed8aacf47959306b2e3abf42d45 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 2 Aug 2019 21:00:51 +0200 Subject: [PATCH] nsscash: main_test: test new server response which causes an update 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main_test.go b/main_test.go index 0279bb7..ee79db9 100644 --- a/main_test.go +++ b/main_test.go @@ -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) { -- 2.43.2