mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-05 20:26:26 +02:00
Merge pull request #380 from mozilla-services/fix/376
fix: ignore the collection field in POSTS also
This commit is contained in:
commit
6f68721c6f
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -75,8 +75,15 @@ impl BatchBsoBody {
|
||||
/// Function to convert valid raw JSON BSO body to a BatchBsoBody
|
||||
fn from_raw_bso(val: &Value) -> Result<BatchBsoBody, String> {
|
||||
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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user