Skip to content

Commit a400281

Browse files
server: Keep default decision path in-sync with manager's config
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 <[email protected]>
1 parent f2011b1 commit a400281

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ func (s *Server) v0QueryPath(w http.ResponseWriter, r *http.Request, urlPath str
10501050
}
10511051

10521052
if useDefaultDecisionPath {
1053-
urlPath = s.defaultDecisionPath
1053+
urlPath = s.generateDefaultDecisionPath()
10541054
}
10551055

10561056
logger := s.getDecisionLogger(br)

server/server_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,46 @@ func TestUnversionedPost(t *testing.T) {
38733873
if f.recorder.Body.String() != expectedBody {
38743874
t.Errorf("Expected %s got %s", expectedBody, f.recorder.Body.String())
38753875
}
3876+
3877+
// update the default decision path
3878+
s := "http/authz"
3879+
f.server.manager.Config.DefaultDecision = &s
3880+
3881+
f.reset()
3882+
f.server.Handler.ServeHTTP(f.recorder, post())
3883+
3884+
if f.recorder.Code != 404 {
3885+
t.Fatalf("Expected not found before policy added but got %v", f.recorder)
3886+
}
3887+
3888+
expectedBody = `{
3889+
"code": "undefined_document",
3890+
"message": "document missing: data.http.authz"
3891+
}
3892+
`
3893+
if f.recorder.Body.String() != expectedBody {
3894+
t.Fatalf("Expected %s got %s", expectedBody, f.recorder.Body.String())
3895+
}
3896+
3897+
module = `
3898+
package http.authz
3899+
3900+
agg = x {
3901+
sum(input.foo.bar, x)
3902+
}
3903+
`
3904+
3905+
if err := f.v1("PUT", "/policies/test", module, 200, ""); err != nil {
3906+
t.Fatal(err)
3907+
}
3908+
3909+
f.reset()
3910+
f.server.Handler.ServeHTTP(f.recorder, post())
3911+
3912+
expected = "{\"agg\":6}\n"
3913+
if f.recorder.Code != 200 || f.recorder.Body.String() != expected {
3914+
t.Fatalf(`Expected HTTP 200 / %v but got: %v`, expected, f.recorder)
3915+
}
38763916
}
38773917

38783918
func TestQueryV1Explain(t *testing.T) {

0 commit comments

Comments
 (0)