|
@@ -213,6 +213,7 @@ func TestParseEntryFiltersPreservesEndpointCompatibility(t *testing.T) {
|
|
|
{routeCategoryID: 10, query: "category_id=20", categoryID: 10},
|
|
{routeCategoryID: 10, query: "category_id=20", categoryID: 10},
|
|
|
{routeCategoryID: 10, query: "category_id=0", categoryID: 10},
|
|
{routeCategoryID: 10, query: "category_id=0", categoryID: 10},
|
|
|
{routeCategoryID: 10, query: "feed_id=12", feedID: 12, categoryID: 10},
|
|
{routeCategoryID: 10, query: "feed_id=12", feedID: 12, categoryID: 10},
|
|
|
|
|
+ {routeFeedID: 11, query: "feed_id=&category_id=", feedID: 11},
|
|
|
{query: "starred=1", starred: new(true)},
|
|
{query: "starred=1", starred: new(true)},
|
|
|
{query: "starred=0", starred: new(false)},
|
|
{query: "starred=0", starred: new(false)},
|
|
|
{query: "starred=invalid"},
|
|
{query: "starred=invalid"},
|
|
@@ -244,6 +245,70 @@ func TestParseEntryFiltersPreservesEndpointCompatibility(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestParseEntryFiltersRejectsInvalidRouteScopedQueryIDs(t *testing.T) {
|
|
|
|
|
+ for _, route := range []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ feedID, categoryID int64
|
|
|
|
|
+ }{
|
|
|
|
|
+ {"feed", 11, 0},
|
|
|
|
|
+ {"category", 0, 10},
|
|
|
|
|
+ } {
|
|
|
|
|
+ for _, query := range []string{
|
|
|
|
|
+ "feed_id=-1",
|
|
|
|
|
+ "category_id=-1",
|
|
|
|
|
+ "feed_id=invalid",
|
|
|
|
|
+ "category_id=invalid",
|
|
|
|
|
+ "feed_id=9223372036854775808",
|
|
|
|
|
+ "category_id=9223372036854775808",
|
|
|
|
|
+ } {
|
|
|
|
|
+ t.Run(route.name+"/"+query, func(t *testing.T) {
|
|
|
|
|
+ r := httptest.NewRequest(http.MethodGet, "/v1/entries?"+query, nil)
|
|
|
|
|
+ if _, err := parseEntryFilters(r, route.feedID, route.categoryID); err == nil {
|
|
|
|
|
+ t.Fatal("Expected invalid scope query ID to be rejected")
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TestRouteScopedEntryHandlersRejectInvalidScopeQueryIDs(t *testing.T) {
|
|
|
|
|
+ tests := []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ path string
|
|
|
|
|
+ pathValues map[string]string
|
|
|
|
|
+ handle func(*handler, http.ResponseWriter, *http.Request)
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "feed route",
|
|
|
|
|
+ path: "/v1/feeds/11/entries?category_id=-1",
|
|
|
|
|
+ pathValues: map[string]string{"feedID": "11"},
|
|
|
|
|
+ handle: (*handler).getFeedEntriesHandler,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "category route",
|
|
|
|
|
+ path: "/v1/categories/10/entries?feed_id=invalid",
|
|
|
|
|
+ pathValues: map[string]string{"categoryID": "10"},
|
|
|
|
|
+ handle: (*handler).getCategoryEntriesHandler,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, test := range tests {
|
|
|
|
|
+ t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
+ r := httptest.NewRequest(http.MethodGet, test.path, nil)
|
|
|
|
|
+ for name, value := range test.pathValues {
|
|
|
|
|
+ r.SetPathValue(name, value)
|
|
|
|
|
+ }
|
|
|
|
|
+ w := httptest.NewRecorder()
|
|
|
|
|
+
|
|
|
|
|
+ test.handle(&handler{}, w, r)
|
|
|
|
|
+
|
|
|
|
|
+ if w.Code != http.StatusBadRequest {
|
|
|
|
|
+ t.Fatalf("Unexpected status code: got %d, want %d", w.Code, http.StatusBadRequest)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestParseEntryIDsParamsDefaults(t *testing.T) {
|
|
func TestParseEntryIDsParamsDefaults(t *testing.T) {
|
|
|
r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids", nil)
|
|
r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids", nil)
|
|
|
limit, offset := parseEntryIDsParams(r)
|
|
limit, offset := parseEntryIDsParams(r)
|