diff --git a/src/server/test.rs b/src/server/test.rs index 80e9bdb1be..98d7391f6b 100644 --- a/src/server/test.rs +++ b/src/server/test.rs @@ -373,13 +373,21 @@ fn put_bso() { } #[test] -fn put_meta_storage() { +fn bsos_can_have_a_collection_field() { let start = SyncTimestamp::default(); // test that "collection" is accepted, even if ignored - let body = json!({"id": "global", "collection": "meta", "payload": "SomePayload"}); - let bytes = test_endpoint_with_body(http::Method::PUT, "/1.5/42/storage/meta/global", body); - let result: PutBso = serde_json::from_slice(&bytes).unwrap(); + let bso1 = json!({"id": "global", "collection": "meta", "payload": "SomePayload"}); + let bsos = json!( + [bso1, + {"id": "2", "collection": "foo", "payload": "SomePayload"}, + ]); + let bytes = test_endpoint_with_body(http::Method::POST, "/1.5/42/storage/meta", bsos); + let result: PostBsos = serde_json::from_slice(&bytes.to_vec()).unwrap(); + assert_eq!(result.success.len(), 2); + assert_eq!(result.failed.len(), 0); + let bytes = test_endpoint_with_body(http::Method::PUT, "/1.5/42/storage/meta/global", bso1); + let result: PutBso = serde_json::from_slice(&bytes).unwrap(); assert!(result >= start); } diff --git a/src/web/extractors.rs b/src/web/extractors.rs index 6269bb963c..b0e5dfb6cd 100644 --- a/src/web/extractors.rs +++ b/src/web/extractors.rs @@ -75,8 +75,15 @@ impl BatchBsoBody { /// Function to convert valid raw JSON BSO body to a BatchBsoBody fn from_raw_bso(val: &Value) -> Result { let map = val.as_object().ok_or("invalid json")?; - // Verify all the keys are valid. modified is allowed but ignored - let valid_keys = ["id", "sortindex", "payload", "ttl", "modified"]; + // Verify all the keys are valid. modified/collection are allowed but ignored + let valid_keys = [ + "id", + "sortindex", + "payload", + "ttl", + "modified", + "collection", + ]; for key_name in map.keys() { if !valid_keys.contains(&key_name.as_str()) { return Err(format!("unknown field {}", key_name));