Skip to content

Commit d12a1ea

Browse files
committed
chore: format the code
1 parent 352de91 commit d12a1ea

File tree

4 files changed

+119
-36
lines changed

4 files changed

+119
-36
lines changed

syncserver/src/server/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ pub struct ServerState {
7171
/// This state object will be made available to all HTTP API calls.
7272
pub struct ReverseProxyState {
7373
/// public facing URL of the server
74-
pub public_url: Option<String>
74+
pub public_url: Option<String>,
7575
}
7676

7777
impl ReverseProxyState {
7878
pub fn from_settings(settings: &Settings) -> ReverseProxyState {
7979
ReverseProxyState {
80-
public_url: settings.public_url.clone()
80+
public_url: settings.public_url.clone(),
8181
}
8282
}
8383

@@ -86,8 +86,8 @@ impl ReverseProxyState {
8686
None => "".to_owned(),
8787
Some(url) => match url.parse::<Uri>() {
8888
Err(_) => "".to_owned(),
89-
Ok(uri) => uri.path().to_owned()
90-
}
89+
Ok(uri) => uri.path().to_owned(),
90+
},
9191
}
9292
}
9393
}

syncserver/src/server/test.rs

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,19 @@ fn create_request(
145145
path: &str,
146146
headers: Option<HashMap<&'static str, String>>,
147147
payload: Option<serde_json::Value>,
148-
settings: Option<&Settings>
148+
settings: Option<&Settings>,
149149
) -> test::TestRequest {
150150
let test_settings = get_test_settings();
151151
let settings = settings.unwrap_or(&test_settings);
152152
let mut req = test::TestRequest::with_uri(path)
153153
.method(method.clone())
154154
.insert_header((
155155
"Authorization",
156-
create_hawk_header(method.as_str(), settings.port, &(ReverseProxyState::from_settings(&settings).get_webroot() + path)),
156+
create_hawk_header(
157+
method.as_str(),
158+
settings.port,
159+
&(ReverseProxyState::from_settings(&settings).get_webroot() + path),
160+
),
157161
))
158162
.insert_header(("Accept", "application/json"))
159163
.insert_header((
@@ -237,9 +241,7 @@ async fn test_endpoint(
237241

238242
let app = match settings.clone() {
239243
None => init_app!().await,
240-
Some(settings) => {
241-
init_app!(settings).await
242-
}
244+
Some(settings) => init_app!(settings).await,
243245
};
244246

245247
let req = create_request(&method, path, None, None, settings.as_ref()).to_request();
@@ -539,7 +541,7 @@ async fn invalid_content_type() {
539541

540542
let mut headers = HashMap::new();
541543
headers.insert("Content-Type", "application/javascript".to_owned());
542-
let req = create_request(
544+
let req = create_request(
543545
&http::Method::PUT,
544546
path,
545547
Some(headers.clone()),
@@ -709,8 +711,14 @@ async fn reject_old_ios() {
709711
#[actix_rt::test]
710712
async fn info_configuration_xlm() {
711713
let app = init_app!().await;
712-
let req =
713-
create_request(&http::Method::GET, "/1.5/42/info/configuration", None, None, None).to_request();
714+
let req = create_request(
715+
&http::Method::GET,
716+
"/1.5/42/info/configuration",
717+
None,
718+
None,
719+
None,
720+
)
721+
.to_request();
714722
let response = app.call(req).await.unwrap();
715723
assert_eq!(response.status(), StatusCode::OK);
716724
let xlm = response.headers().get(X_LAST_MODIFIED);
@@ -734,7 +742,14 @@ async fn overquota() {
734742
let app = init_app!(settings).await;
735743

736744
// Clear out any data that's already in the store.
737-
let req = create_request(&http::Method::DELETE, "/1.5/42/storage", None, None, Some(&settings)).to_request();
745+
let req = create_request(
746+
&http::Method::DELETE,
747+
"/1.5/42/storage",
748+
None,
749+
None,
750+
Some(&settings),
751+
)
752+
.to_request();
738753
let resp = app.call(req).await.unwrap();
739754
assert!(resp.response().status().is_success());
740755

@@ -785,7 +800,14 @@ async fn overquota() {
785800

786801
// XXX: this should run as cleanup regardless of test failure but it's
787802
// difficult. e.g. FutureExt::catch_unwind isn't compatible w/ actix-web
788-
let req = create_request(&http::Method::DELETE, "/1.5/42/storage", None, None, Some(&settings)).to_request();
803+
let req = create_request(
804+
&http::Method::DELETE,
805+
"/1.5/42/storage",
806+
None,
807+
None,
808+
Some(&settings),
809+
)
810+
.to_request();
789811
let resp = app.call(req).await.unwrap();
790812
assert!(resp.response().status().is_success());
791813
}
@@ -798,7 +820,14 @@ async fn lbheartbeat_max_pool_size_check() {
798820
let app = init_app!(settings).await;
799821

800822
// Test all is well.
801-
let lb_req = create_request(&http::Method::GET, "/__lbheartbeat__", None, None, Some(&settings)).to_request();
823+
let lb_req = create_request(
824+
&http::Method::GET,
825+
"/__lbheartbeat__",
826+
None,
827+
None,
828+
Some(&settings),
829+
)
830+
.to_request();
802831
let sresp = app.call(lb_req).await.unwrap();
803832
let status = sresp.status();
804833
// dbg!(status, test::read_body(sresp).await);
@@ -823,8 +852,14 @@ async fn lbheartbeat_max_pool_size_check() {
823852

824853
// check duration for exhausted connections
825854
actix_rt::time::sleep(Duration::from_secs(1)).await;
826-
let req =
827-
create_request(&http::Method::GET, "/__lbheartbeat__", Some(headers), None, Some(&settings)).to_request();
855+
let req = create_request(
856+
&http::Method::GET,
857+
"/__lbheartbeat__",
858+
Some(headers),
859+
None,
860+
Some(&settings),
861+
)
862+
.to_request();
828863
let sresp = app.call(req).await.unwrap();
829864
let status = sresp.status();
830865
let body = test::read_body(sresp).await;
@@ -838,8 +873,14 @@ async fn lbheartbeat_max_pool_size_check() {
838873
let mut headers: HashMap<&str, String> = HashMap::new();
839874
headers.insert("TEST_CONNECTIONS", "5".to_owned());
840875
headers.insert("TEST_IDLES", "5".to_owned());
841-
let req =
842-
create_request(&http::Method::GET, "/__lbheartbeat__", Some(headers), None, Some(&settings)).to_request();
876+
let req = create_request(
877+
&http::Method::GET,
878+
"/__lbheartbeat__",
879+
Some(headers),
880+
None,
881+
Some(&settings),
882+
)
883+
.to_request();
843884
let sresp = app.call(req).await.unwrap();
844885
let status = sresp.status();
845886
// dbg!(status, test::read_body(sresp).await);
@@ -854,13 +895,27 @@ async fn lbheartbeat_ttl_check() {
854895

855896
let app = init_app!(settings).await;
856897

857-
let lb_req = create_request(&http::Method::GET, "/__lbheartbeat__", None, None, Some(&settings)).to_request();
898+
let lb_req = create_request(
899+
&http::Method::GET,
900+
"/__lbheartbeat__",
901+
None,
902+
None,
903+
Some(&settings),
904+
)
905+
.to_request();
858906
let sresp = app.call(lb_req).await.unwrap();
859907
assert!(sresp.status().is_success());
860908

861909
actix_rt::time::sleep(Duration::from_secs(3)).await;
862910

863-
let lb_req = create_request(&http::Method::GET, "/__lbheartbeat__", None, None, Some(&settings)).to_request();
911+
let lb_req = create_request(
912+
&http::Method::GET,
913+
"/__lbheartbeat__",
914+
None,
915+
None,
916+
Some(&settings),
917+
)
918+
.to_request();
864919
let sresp = app.call(lb_req).await.unwrap();
865920
assert_eq!(sresp.status(), StatusCode::INTERNAL_SERVER_ERROR);
866921
}

syncserver/src/web/auth.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ use super::{
2626
error::{HawkErrorKind, ValidationErrorKind},
2727
extractors::RequestErrorLocation,
2828
};
29-
use crate::{error::{ApiErrorKind, ApiResult}, server::ReverseProxyState};
3029
use crate::label;
30+
use crate::{
31+
error::{ApiErrorKind, ApiResult},
32+
server::ReverseProxyState,
33+
};
3134

3235
/// A parsed and authenticated JSON payload
3336
/// extracted from the signed `id` property
@@ -198,7 +201,15 @@ impl HawkPayload {
198201
Utc::now().timestamp() as u64
199202
};
200203

201-
HawkPayload::new(header, method, (reverse_proxy_state.get_webroot() + path.as_str()).as_str(), host, port, secrets, expiry)
204+
HawkPayload::new(
205+
header,
206+
method,
207+
(reverse_proxy_state.get_webroot() + path.as_str()).as_str(),
208+
host,
209+
port,
210+
secrets,
211+
expiry,
212+
)
202213
}
203214
}
204215

syncserver/src/web/extractors.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use syncstorage_db::{
3434
use tokenserver_auth::TokenserverOrigin;
3535
use validator::{Validate, ValidationError};
3636

37-
use crate::{error::{ApiError, ApiErrorKind}, server::ReverseProxyState};
3837
use crate::label;
3938
use crate::server::{MetricsWrapper, ServerState, BSO_ID_REGEX, COLLECTION_ID_REGEX};
4039
use crate::web::{
@@ -43,6 +42,10 @@ use crate::web::{
4342
transaction::DbTransactionPool,
4443
DOCKER_FLOW_ENDPOINTS,
4544
};
45+
use crate::{
46+
error::{ApiError, ApiErrorKind},
47+
server::ReverseProxyState,
48+
};
4649
const BATCH_MAX_IDS: usize = 100;
4750

4851
// BSO const restrictions
@@ -1094,7 +1097,14 @@ impl HawkIdentifier {
10941097
uri: &Uri,
10951098
exts: &mut Extensions,
10961099
) -> Result<Self, Error> {
1097-
let payload = HawkPayload::extrude(header, method, &reverse_proxy_state, secrets, connection_info, uri)?;
1100+
let payload = HawkPayload::extrude(
1101+
header,
1102+
method,
1103+
&reverse_proxy_state,
1104+
secrets,
1105+
connection_info,
1106+
uri,
1107+
)?;
10981108
let puid = Self::uid_from_path(uri)?;
10991109
if payload.user_id != puid {
11001110
warn!("⚠️ Hawk UID not in URI: {:?} {:?}", payload.user_id, uri);
@@ -1149,13 +1159,15 @@ impl FromRequest for HawkIdentifier {
11491159
let connection_info = req.connection_info().clone();
11501160
let method = req.method().clone();
11511161

1152-
let reverse_proxy_state: &ReverseProxyState = match &req.app_data::<Data<ReverseProxyState>>() {
1153-
Some(data) => data,
1154-
None => {
1155-
let err: ApiError = ApiErrorKind::Internal("No app_data ReverseProxyState".to_owned()).into();
1156-
return future::ready(Err(err.into()));
1157-
}
1158-
};
1162+
let reverse_proxy_state: &ReverseProxyState =
1163+
match &req.app_data::<Data<ReverseProxyState>>() {
1164+
Some(data) => data,
1165+
None => {
1166+
let err: ApiError =
1167+
ApiErrorKind::Internal("No app_data ReverseProxyState".to_owned()).into();
1168+
return future::ready(Err(err.into()));
1169+
}
1170+
};
11591171

11601172
// Tried collapsing this to a `.or_else` and hit problems with the return resolving
11611173
// to an appropriate error state. Can't use `?` since the function does not return a result.
@@ -1167,7 +1179,14 @@ impl FromRequest for HawkIdentifier {
11671179
}
11681180
};
11691181

1170-
let result = Self::extrude(&req, method.as_str(), uri, &connection_info, &reverse_proxy_state, secrets);
1182+
let result = Self::extrude(
1183+
&req,
1184+
method.as_str(),
1185+
uri,
1186+
&connection_info,
1187+
&reverse_proxy_state,
1188+
secrets,
1189+
);
11711190

11721191
if let Ok(ref hawk_id) = result {
11731192
// Store the origin of the token as an extra to be included when emitting a Sentry error
@@ -1814,9 +1833,7 @@ mod tests {
18141833
}
18151834

18161835
fn make_reverse_proxy_state() -> ReverseProxyState {
1817-
ReverseProxyState {
1818-
public_url: None
1819-
}
1836+
ReverseProxyState { public_url: None }
18201837
}
18211838

18221839
fn extract_body_as_str(sresponse: ServiceResponse) -> String {

0 commit comments

Comments
 (0)