Skip to content

Commit

Permalink
bug: allow "collection" in BSOs (although we ignore it)
Browse files Browse the repository at this point in the history
Closes: #342
  • Loading branch information
jrconlin committed Dec 5, 2019
1 parent 4a9f2ce commit 013eaaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
11 changes: 11 additions & 0 deletions src/server/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ fn put_bso() {
assert!(result >= start);
}

#[test]
fn put_meta_storage() {
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();

assert!(result >= start);
}

#[test]
fn invalid_content_type() {
let path = "/1.5/42/storage/bookmarks/wibble";
Expand Down
26 changes: 4 additions & 22 deletions src/web/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use actix_web::{
dev::{ConnectionInfo, Extensions, Payload},
error::ErrorInternalServerError,
http::{
header::{qitem, Accept, ContentType, Header, HeaderMap, HeaderValue},
header::{qitem, Accept, ContentType, Header, HeaderMap},
Uri,
},
web::{Json, Query},
Expand Down Expand Up @@ -313,9 +313,11 @@ pub struct BsoBody {
pub payload: Option<String>,
#[validate(custom = "validate_body_bso_ttl")]
pub ttl: Option<u32>,
/// Any client-supplied value for this field is ignored
/// Any client-supplied value for these fields are ignored
#[serde(rename(deserialize = "modified"), skip_serializing)]
pub _ignored_modified: Option<IgnoredAny>,
#[serde(rename(deserialize = "collection"), skip_serializing)]
pub _ignored_collection: Option<IgnoredAny>,
}

impl FromRequest for BsoBody {
Expand Down Expand Up @@ -367,26 +369,6 @@ impl FromRequest for BsoBody {

let max_payload_size = state.limits.max_record_payload_bytes as usize;

// The `meta/global` BSO is special in that it's used as a command to
// reset the timestamp. A possible client bug is sending an empty
// body. Handle it, but issue an info so we can track the event.
if req.path().ends_with("/meta/global")
&& req
.headers()
.get("content-length")
.unwrap_or(&HeaderValue::from(0))
== HeaderValue::from(0)
{
info!("⚠️ Got an empty meta BSO");
return Box::new(future::ok(BsoBody {
id: None,
sortindex: None,
payload: None,
ttl: None,
_ignored_modified: None,
}));
}

let fut = <Json<BsoBody>>::from_request(&req, payload)
.map_err(|e| {
warn!("⚠️ Could not parse BSO Body: {:?}", e);
Expand Down
4 changes: 2 additions & 2 deletions tools/hawk/make_hawk_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
FXA_KID = "DEADBEEF00004be4ae957006c0ceb620"
DEVICE_ID = "device1"
NODE = "http://localhost:8000"
SECRET = "Ted Koppel is a robot"
SECRET = "Ted_Koppel_is_a_robot"
HMAC_KEY = b"foo"

# 10 years
Expand Down Expand Up @@ -120,7 +120,7 @@ def main():
print("\nPath: ", path)
print("Hawk Authorization Header: ", header)
else:
print(header)
print("Authorization:", header)


if __name__ == '__main__':
Expand Down

0 comments on commit 013eaaf

Please sign in to comment.