Skip to content

Commit 4cd1a11

Browse files
committed
test: invalid car content type params
1 parent 5ac5e33 commit 4cd1a11

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

gateway/handler_car_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ func TestCarParams(t *testing.T) {
110110
require.Equal(t, test.expectedDuplicates.String(), params.Duplicates.String())
111111
}
112112
})
113+
114+
t.Run("buildCarParams from Accept header: order and dups parsing (invalid)", func(t *testing.T) {
115+
t.Parallel()
116+
117+
// below ensure the implicit default (DFS and no duplicates) is correctly inferred
118+
// from the value read from Accept header
119+
tests := []string{
120+
"application/vnd.ipld.car; dups=invalid",
121+
"application/vnd.ipld.car; order=invalid",
122+
"application/vnd.ipld.car; order=dfs; dups=invalid",
123+
"application/vnd.ipld.car; order=invalid; dups=y",
124+
}
125+
for _, test := range tests {
126+
r := mustNewRequest(t, http.MethodGet, "http://example.com/", nil)
127+
r.Header.Set("Accept", test)
128+
129+
mediaType, formatParams, err := customResponseFormat(r)
130+
assert.NoError(t, err)
131+
assert.Equal(t, carResponseFormat, mediaType)
132+
133+
_, err = buildCarParams(r, formatParams)
134+
assert.ErrorContains(t, err, "unsupported application/vnd.ipld.car content type")
135+
}
136+
})
113137
}
114138

115139
func TestContentTypeFromCarParams(t *testing.T) {

0 commit comments

Comments
 (0)