Skip to content

Commit

Permalink
server: Keep default decision path in-sync with manager's config
Browse files Browse the repository at this point in the history
This change attempts to keep the default decision path used by the server
in sync with the one defined on the manager's config. Currently the
server only updates the default decision path when it's initialized and
when there is a commit on the store. The issue happens when the default
decision path is updated via the discovered config. In this case, the
manager's config is updated but there could be no store txn. Hence
the updated value of default decision path is not taken into account by
the server.

Fixes: #6697

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
  • Loading branch information
ashutosh-narkar committed Apr 24, 2024
1 parent f2011b1 commit a400281
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/server.go
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions server/server_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit a400281

Please sign in to comment.