diff --git a/server/server.go b/server/server.go index 436d89662d..740695592b 100644 --- a/server/server.go +++ b/server/server.go @@ -1050,7 +1050,7 @@ func (s *Server) v0QueryPath(w http.ResponseWriter, r *http.Request, urlPath str } if useDefaultDecisionPath { - urlPath = s.defaultDecisionPath + urlPath = s.generateDefaultDecisionPath() } logger := s.getDecisionLogger(br) diff --git a/server/server_test.go b/server/server_test.go index c0de6b6ad3..d9f2577a6e 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -3873,6 +3873,46 @@ func TestUnversionedPost(t *testing.T) { if f.recorder.Body.String() != expectedBody { t.Errorf("Expected %s got %s", expectedBody, f.recorder.Body.String()) } + + // update the default decision path + s := "http/authz" + f.server.manager.Config.DefaultDecision = &s + + f.reset() + f.server.Handler.ServeHTTP(f.recorder, post()) + + if f.recorder.Code != 404 { + t.Fatalf("Expected not found before policy added but got %v", f.recorder) + } + + expectedBody = `{ + "code": "undefined_document", + "message": "document missing: data.http.authz" +} +` + if f.recorder.Body.String() != expectedBody { + t.Fatalf("Expected %s got %s", expectedBody, f.recorder.Body.String()) + } + + module = ` + package http.authz + + agg = x { + sum(input.foo.bar, x) + } + ` + + if err := f.v1("PUT", "/policies/test", module, 200, ""); err != nil { + t.Fatal(err) + } + + f.reset() + f.server.Handler.ServeHTTP(f.recorder, post()) + + expected = "{\"agg\":6}\n" + if f.recorder.Code != 200 || f.recorder.Body.String() != expected { + t.Fatalf(`Expected HTTP 200 / %v but got: %v`, expected, f.recorder) + } } func TestQueryV1Explain(t *testing.T) {