diff options
author | jhwz <[email protected]> | 2022-07-13 06:23:55 +1200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-07-12 12:23:55 -0600 |
commit | ad3a83fb9169899226ce12a61c16b5bf4d03c482 (patch) | |
tree | 62f19bf05422fe5844c9c90c73402b12f639a7a4 /admin_test.go | |
parent | 53c4d788d4bbc00d396be743a2c0b36482e53c6e (diff) | |
download | caddy-ad3a83fb9169899226ce12a61c16b5bf4d03c482.tar.gz caddy-ad3a83fb9169899226ce12a61c16b5bf4d03c482.zip |
admin: expect quoted ETags (#4879)v2.5.2
* expect quoted etags
* admin: Minor refactor of etag facilities
Co-authored-by: Matthew Holt <[email protected]>
Diffstat (limited to 'admin_test.go')
-rw-r--r-- | admin_test.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/admin_test.go b/admin_test.go index 32f20c627..f64df75a4 100644 --- a/admin_test.go +++ b/admin_test.go @@ -15,8 +15,8 @@ package caddy import ( - "encoding/hex" "encoding/json" + "fmt" "net/http" "reflect" "sync" @@ -168,7 +168,7 @@ func TestETags(t *testing.T) { const key = "/" + rawConfigKey + "/apps/foo" // try update the config with the wrong etag - err := changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 1}}`), "/"+rawConfigKey+" not_an_etag", false) + err := changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 1}}`), fmt.Sprintf(`"/%s not_an_etag"`, rawConfigKey), false) if apiErr, ok := err.(APIError); !ok || apiErr.HTTPStatus != http.StatusPreconditionFailed { t.Fatalf("expected precondition failed; got %v", err) } @@ -180,13 +180,13 @@ func TestETags(t *testing.T) { } // do the same update with the correct key - err = changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 1}`), key+" "+hex.EncodeToString(hash.Sum(nil)), false) + err = changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 1}`), makeEtag(key, hash), false) if err != nil { t.Fatalf("expected update to work; got %v", err) } // now try another update. The hash should no longer match and we should get precondition failed - err = changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 2}`), key+" "+hex.EncodeToString(hash.Sum(nil)), false) + err = changeConfig(http.MethodPost, key, []byte(`{"strField": "abc", "intField": 2}`), makeEtag(key, hash), false) if apiErr, ok := err.(APIError); !ok || apiErr.HTTPStatus != http.StatusPreconditionFailed { t.Fatalf("expected precondition failed; got %v", err) } |