]> ruderich.org/simon Gitweb - nsscash/nsscash.git/commitdiff
nsscash: main_test: add plain tests
authorSimon Ruderich <simon@ruderich.org>
Wed, 26 Jun 2019 12:12:26 +0000 (14:12 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 26 Jun 2019 14:37:17 +0000 (16:37 +0200)
main_test.go

index d28c822ac3bbb8ef65e44c221ed8fb054b691d85..563f683ab5fb6a3e7d443baa8906b66303bec082 100644 (file)
@@ -191,6 +191,9 @@ func TestMainFetch(t *testing.T) {
                fetchPasswdInvalid,
                fetchPasswdLimits,
                fetchPasswd,
+               // Tests for plain
+               fetchPlainEmpty,
+               fetchPlain,
                // Special tests
                fetchNoConfig,
        }
@@ -439,6 +442,63 @@ func fetchPasswd(a args) {
        mustHaveHash(t, passwdPath, "bbb7db67469b111200400e2470346d5515d64c23")
 }
 
+func fetchPlainEmpty(a args) {
+       t := a.t
+       mustWriteConfig(t, fmt.Sprintf(`
+statepath = "%[1]s"
+
+[[file]]
+type = "plain"
+url = "%[2]s/plain"
+path = "%[3]s"
+`, statePath, a.url, plainPath))
+       mustCreate(t, plainPath)
+
+       *a.handler = func(w http.ResponseWriter, r *http.Request) {
+               // Empty response
+       }
+
+       err := mainFetch(configPath)
+       mustBeErrorWithSubstring(t, err,
+               "refusing to use empty response")
+
+       mustNotExist(t, statePath, passwdPath, groupPath)
+       mustBeOld(t, plainPath)
+}
+
+func fetchPlain(a args) {
+       t := a.t
+       mustWriteConfig(t, fmt.Sprintf(`
+statepath = "%[1]s"
+
+[[file]]
+type = "plain"
+url = "%[2]s/plain"
+path = "%[3]s"
+`, statePath, a.url, plainPath))
+       mustCreate(t, plainPath)
+       mustHaveHash(t, plainPath, "da39a3ee5e6b4b0d3255bfef95601890afd80709")
+
+       *a.handler = func(w http.ResponseWriter, r *http.Request) {
+               if r.URL.Path != "/plain" {
+                       return
+               }
+
+               fmt.Fprintln(w, "some file")
+       }
+
+       err := mainFetch(configPath)
+       if err != nil {
+               t.Error(err)
+       }
+
+       mustNotExist(t, passwdPath, groupPath)
+       mustBeNew(t, plainPath, statePath)
+       mustHaveHash(t, plainPath, "0e08b5e8c10abc3e455b75286ba4a1fbd56e18a5")
+
+       // Remaining functionality already tested in fetchPasswd()
+}
+
 func fetchNoConfig(a args) {
        t := a.t