fix(platform): guard unscoped raw field queries
This commit is contained in:
@@ -941,6 +941,47 @@ func TestHandlerRawFramesPostAcceptsKeyword(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerRawFramesRejectsUnscopedIncludeFields(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
cases := []struct {
|
||||
name string
|
||||
req *http.Request
|
||||
}{
|
||||
{
|
||||
name: "get",
|
||||
req: httptest.NewRequest(http.MethodGet, "/api/history/raw-frames?limit=1&includeFields=true", nil),
|
||||
},
|
||||
{
|
||||
name: "post",
|
||||
req: httptest.NewRequest(http.MethodPost, "/api/history/raw-frames/query", strings.NewReader(`{"limit":1,"includeFields":true}`)),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, tc.req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Error struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("response JSON should decode: %v body=%s", err, rec.Body.String())
|
||||
}
|
||||
if body.Error.Code != "RAW_FRAME_SCOPE_REQUIRED" {
|
||||
t.Fatalf("error code = %q body=%s", body.Error.Code, rec.Body.String())
|
||||
}
|
||||
if !strings.Contains(body.Error.Message, "车辆或时间范围") {
|
||||
t.Fatalf("error message should explain required scope: %s", rec.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerRawFramesKeepsUnresolvedKeywordEmpty(t *testing.T) {
|
||||
handler := NewHandler(NewService(NewMockStore()))
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user