File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ pub(crate) struct RawSeekPayload(String);
248
248
249
249
impl RawSeekPayload {
250
250
pub ( crate ) fn decode < D : for < ' a > Deserialize < ' a > > ( & self ) -> AppResult < D > {
251
- decode_seek ( & self . 0 )
251
+ decode_seek ( & self . 0 ) . map_err ( |_| bad_request ( "invalid seek parameter" ) )
252
252
}
253
253
}
254
254
@@ -294,7 +294,7 @@ pub(crate) fn encode_seek<S: Serialize>(params: S) -> AppResult<String> {
294
294
}
295
295
296
296
/// Decode a list of params previously encoded with [`encode_seek`].
297
- pub ( crate ) fn decode_seek < D : for < ' a > Deserialize < ' a > > ( seek : & str ) -> AppResult < D > {
297
+ pub ( crate ) fn decode_seek < D : for < ' a > Deserialize < ' a > > ( seek : & str ) -> anyhow :: Result < D > {
298
298
let decoded = serde_json:: from_slice ( & general_purpose:: URL_SAFE_NO_PAD . decode ( seek) ?) ?;
299
299
Ok ( decoded)
300
300
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use crates_io::schema::crates;
6
6
use diesel:: { dsl:: * , prelude:: * , update} ;
7
7
use googletest:: prelude:: * ;
8
8
use http:: StatusCode ;
9
+ use insta:: assert_json_snapshot;
9
10
10
11
#[ test]
11
12
fn index ( ) {
@@ -793,6 +794,15 @@ fn test_pages_work_even_with_seek_based_pagination() {
793
794
assert ! ( second. meta. next_page. unwrap( ) . contains( "page=3" ) ) ;
794
795
}
795
796
797
+ #[ test]
798
+ fn invalid_seek_parameter ( ) {
799
+ let ( _app, anon, _cookie) = TestApp :: init ( ) . with_user ( ) ;
800
+
801
+ let response = anon. get :: < ( ) > ( "/api/v1/crates?seek=broken" ) ;
802
+ assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
803
+ assert_json_snapshot ! ( response. into_json( ) ) ;
804
+ }
805
+
796
806
#[ test]
797
807
fn pagination_parameters_only_accept_integers ( ) {
798
808
let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
Original file line number Diff line number Diff line change
1
+ -- -
2
+ source : src / tests / routes / crates / list .rs
3
+ expression : response .into_json ()
4
+ -- -
5
+ {
6
+ " errors" : [
7
+ {
8
+ " detail" : " invalid seek parameter"
9
+ }
10
+ ]
11
+ }
You can’t perform that action at this time.
0 commit comments