From 3ab8d3737f51fdd328c972b94e687c161c915f8e Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 26 Jun 2019 14:12:26 +0200 Subject: [PATCH] nsscash: main_test: add plain tests --- main_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/main_test.go b/main_test.go index d28c822..563f683 100644 --- a/main_test.go +++ b/main_test.go @@ -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 -- 2.45.2