Skip to content

Commit d7d6049

Browse files
committed
Merge branch 'master' into release/0.1
2 parents 55e89c2 + e1149b9 commit d7d6049

File tree

13 files changed

+63
-35
lines changed

13 files changed

+63
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ service-account.json
3434

3535

3636
config/local.toml
37+
venv

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
run-local:
1+
run_local:
22
RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --config config/local.toml

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ Mozilla Sync Storage built with [Rust](https://rust-lang.org).
2929
- MySQL 5.7 (or compatible)
3030
-\* libmysqlclient (`brew install mysql` on macOS, `apt-get install libmysqlclient-dev` on Ubuntu)
3131
- [Go](https://golang.org/doc/install)
32+
- Cmake
33+
- Pkg-config
34+
- Openssl
3235

3336
Depending on your OS, you may also need to install `libgrpcdev`, and `protobuf-compiler-grpc`.
3437

3538
## Local Setup
3639

3740
1. Follow the instructions below to use either MySQL or Spanner as your DB.
3841
2. Now `cp config/local.example.toml config/local.toml`. Open `config/local.toml` and make sure you have the desired settings configured. For a complete list of available configuration options, check out [docs/config.md](docs/config.md).
39-
3. `make run-local` starts the server in debug mode, using your new `local.toml` file for config options. Or, simply `cargo run` with your own config options provided as env vars.
42+
3. `make run_local` starts the server in debug mode, using your new `local.toml` file for config options. Or, simply `cargo run` with your own config options provided as env vars.
4043
4. Visit `http://localhost:8000/__heartbeat__` to make sure the server is running.
4144

4245
### MySQL

config/local.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
database_url = "mysql://sample_user:sample_password@localhost/syncstorage_rs"
2-
master_secret = "some_secret_here"
2+
master_secret = "INSERT_SECRET_KEY_HERE"
33
# removing this line will default to moz_json formatted logs (which is preferred for production envs)
44
human_logs = 1

shell.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Nix is a powerful package manager for Linux and other Unix systems that makes
2+
# package management reliable and reproducible: https://nixos.org/nix/.
3+
# This file is intended to be used with `nix-shell`
4+
# (https://nixos.org/nix/manual/#sec-nix-shell) to setup a fully-functional
5+
# syncstorage-rs build environment by installing all required dependencies.
6+
with import <nixpkgs> {};
7+
stdenv.mkDerivation {
8+
name = "syncstorage-rs";
9+
buildInputs = [
10+
rustc
11+
cargo
12+
libmysqlclient
13+
pkgconfig
14+
openssl
15+
cmake
16+
protobuf
17+
go
18+
];
19+
NIX_LDFLAGS = "-L${libmysqlclient}/lib/mysql";
20+
}

spanner-2019-10-01.ddl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CREATE TABLE bsos (
3737
INTERLEAVE IN user_collections;
3838

3939
CREATE INDEX BsoExpiry
40-
ON bsos(expiry),
40+
ON bsos(fxa_uid, fxa_kid, collection_id, expiry),
4141
INTERLEAVE IN user_collections;
4242

4343
CREATE TABLE collections (

src/server/test.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,17 @@ fn put_bso() {
371371
assert!(result >= start);
372372
}
373373

374+
#[test]
375+
fn put_meta_storage() {
376+
let start = SyncTimestamp::default();
377+
// test that "collection" is accepted, even if ignored
378+
let body = json!({"id": "global", "collection": "meta", "payload": "SomePayload"});
379+
let bytes = test_endpoint_with_body(http::Method::PUT, "/1.5/42/storage/meta/global", body);
380+
let result: PutBso = serde_json::from_slice(&bytes).unwrap();
381+
382+
assert!(result >= start);
383+
}
384+
374385
#[test]
375386
fn invalid_content_type() {
376387
let path = "/1.5/42/storage/bookmarks/wibble";

src/web/extractors.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use actix_web::{
88
dev::{ConnectionInfo, Extensions, Payload},
99
error::ErrorInternalServerError,
1010
http::{
11-
header::{qitem, Accept, ContentType, Header, HeaderMap, HeaderValue},
11+
header::{qitem, Accept, ContentType, Header, HeaderMap},
1212
Uri,
1313
},
1414
web::{Json, Query},
@@ -313,9 +313,11 @@ pub struct BsoBody {
313313
pub payload: Option<String>,
314314
#[validate(custom = "validate_body_bso_ttl")]
315315
pub ttl: Option<u32>,
316-
/// Any client-supplied value for this field is ignored
316+
/// Any client-supplied value for these fields are ignored
317317
#[serde(rename(deserialize = "modified"), skip_serializing)]
318318
pub _ignored_modified: Option<IgnoredAny>,
319+
#[serde(rename(deserialize = "collection"), skip_serializing)]
320+
pub _ignored_collection: Option<IgnoredAny>,
319321
}
320322

321323
impl FromRequest for BsoBody {
@@ -367,26 +369,6 @@ impl FromRequest for BsoBody {
367369

368370
let max_payload_size = state.limits.max_record_payload_bytes as usize;
369371

370-
// The `meta/global` BSO is special in that it's used as a command to
371-
// reset the timestamp. A possible client bug is sending an empty
372-
// body. Handle it, but issue an info so we can track the event.
373-
if req.path().ends_with("/meta/global")
374-
&& req
375-
.headers()
376-
.get("content-length")
377-
.unwrap_or(&HeaderValue::from(0))
378-
== HeaderValue::from(0)
379-
{
380-
info!("⚠️ Got an empty meta BSO");
381-
return Box::new(future::ok(BsoBody {
382-
id: None,
383-
sortindex: None,
384-
payload: None,
385-
ttl: None,
386-
_ignored_modified: None,
387-
}));
388-
}
389-
390372
let fut = <Json<BsoBody>>::from_request(&req, payload)
391373
.map_err(|e| {
392374
warn!("⚠️ Could not parse BSO Body: {:?}", e);

tools/examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Example scripts for working with syncstorage-rs
2+
3+
* `put.bash` - First `chmod +x put.bash` then `./put.bash` to simulate a PUT.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
22
NODE="http://localhost:8000"
33
URI="/1.5/1/storage/col2/DEADBEEF"
4-
AUTH=`../hawk/venv/bin/python ../hawk/make_hawk_token.py --node $NODE --uri $URI --as_header`
4+
METHOD="PUT"
5+
SYNC_MASTER_SECRET="INSERT_SECRET_KEY_HERE"
6+
AUTH=`../hawk/venv/bin/python ../hawk/make_hawk_token.py --node $NODE --uri $URI --method $METHOD --secret=$SYNC_MASTER_SECRET --as_header`
57
curl -vv -X PUT "$NODE$URI" \
6-
-H "Authorization: $AUTH" \
8+
-H "$AUTH" \
79
-H 'Content-Type: application/json' \
810
-H 'Accept: application/json' \
911
-d '{"id": "womble", "payload": "mary had a little lamb with a nice mint jelly", "sortindex": 0, "ttl": 86400}'

0 commit comments

Comments
 (0)