Skip to content

Commit 0ab6273

Browse files
committed
fix formatting
1 parent b5cc1de commit 0ab6273

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

sentry/src/access.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ mod test {
157157
use primitives::event_submission::{RateLimit, Rule};
158158
use primitives::sentry::Event;
159159
use primitives::util::tests::prep_db::DUMMY_CHANNEL;
160-
use primitives::{Channel, EventSubmission, Config};
160+
use primitives::{Channel, Config, EventSubmission};
161161

162162
use crate::db::redis_connection;
163163
use crate::Session;
@@ -169,7 +169,9 @@ mod test {
169169
let config = configuration("development", None).expect("Failed to get dev configuration");
170170

171171
// run `FLUSHALL` to clean any leftovers of other tests
172-
let _ = redis::cmd("FLUSHALL").query_async::<_, String>(&mut redis).await;
172+
let _ = redis::cmd("FLUSHALL")
173+
.query_async::<_, String>(&mut redis)
174+
.await;
173175

174176
(config, redis)
175177
}

sentry/src/middleware/auth.rs

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ fn get_request_ip(req: &Request<Body>) -> Option<String> {
8686
.and_then(|hv| hv.to_str().map(ToString::to_string).ok())
8787
}
8888

89-
9089
#[cfg(test)]
9190
mod test {
92-
use hyper::Request;
9391
use super::*;
94-
use adapter::DummyAdapter;
95-
use primitives::config::configuration;
9692
use crate::db::redis_connection;
97-
use primitives::ValidatorId;
93+
use adapter::DummyAdapter;
94+
use hyper::Request;
9895
use primitives::adapter::DummyAdapterOptions;
96+
use primitives::config::configuration;
9997
use primitives::util::tests::prep_db::{AUTH, IDS};
98+
use primitives::ValidatorId;
10099

101100
async fn setup() -> (DummyAdapter, SharedConnection) {
102101
let adapter_options = DummyAdapterOptions {
@@ -107,29 +106,51 @@ mod test {
107106
let config = configuration("development", None).expect("Dev config should be available");
108107
let mut redis = redis_connection().await.expect("Couldn't connect to Redis");
109108
// run `FLUSHALL` to clean any leftovers of other tests
110-
let _ = redis::cmd("FLUSHALL").query_async::<_, String>(&mut redis).await;
109+
let _ = redis::cmd("FLUSHALL")
110+
.query_async::<_, String>(&mut redis)
111+
.await;
111112
(DummyAdapter::init(adapter_options, &config), redis)
112113
}
113114

114115
#[tokio::test]
115116
async fn no_authentication_or_incorrect_value_should_not_add_session() {
116-
let no_auth_req = Request::builder().body(Body::empty()).expect("should never fail!");
117+
let no_auth_req = Request::builder()
118+
.body(Body::empty())
119+
.expect("should never fail!");
117120

118121
let (dummy_adapter, redis) = setup().await;
119-
let no_auth = for_request(no_auth_req, &dummy_adapter, redis.clone()).await
122+
let no_auth = for_request(no_auth_req, &dummy_adapter, redis.clone())
123+
.await
120124
.expect("Handling the Request shouldn't have failed");
121125

122-
assert!(no_auth.extensions().get::<Session>().is_none(), "There shouldn't be a Session in the extensions");
123-
assert_eq!(Some(dummy_adapter.whoami()), no_auth.extensions().get::<ValidatorId>(), "There should be the whoami() ValidatorId of the adapter in the extensions");
126+
assert!(
127+
no_auth.extensions().get::<Session>().is_none(),
128+
"There shouldn't be a Session in the extensions"
129+
);
130+
assert_eq!(
131+
Some(dummy_adapter.whoami()),
132+
no_auth.extensions().get::<ValidatorId>(),
133+
"There should be the whoami() ValidatorId of the adapter in the extensions"
134+
);
124135

125136
// there is a Header, but it has wrong format
126-
let incorrect_auth_req = Request::builder().header(AUTHORIZATION, "Wrong Header").body(Body::empty()).unwrap();
127-
let incorrect_auth = for_request(incorrect_auth_req, &dummy_adapter, redis.clone()).await
137+
let incorrect_auth_req = Request::builder()
138+
.header(AUTHORIZATION, "Wrong Header")
139+
.body(Body::empty())
140+
.unwrap();
141+
let incorrect_auth = for_request(incorrect_auth_req, &dummy_adapter, redis.clone())
142+
.await
128143
.expect("Handling the Request shouldn't have failed");
129-
assert!(incorrect_auth.extensions().get::<Session>().is_none(), "There shouldn't be a Session in the extensions");
144+
assert!(
145+
incorrect_auth.extensions().get::<Session>().is_none(),
146+
"There shouldn't be a Session in the extensions"
147+
);
130148

131149
// Token doesn't exist in the Adapter nor in Redis
132-
let non_existent_token_req = Request::builder().header(AUTHORIZATION, "Bearer wrong-token").body(Body::empty()).unwrap();
150+
let non_existent_token_req = Request::builder()
151+
.header(AUTHORIZATION, "Bearer wrong-token")
152+
.body(Body::empty())
153+
.unwrap();
133154
match for_request(non_existent_token_req, &dummy_adapter, redis).await {
134155
Err(ResponseError::BadRequest(error)) => {
135156
assert!(error.to_string().contains("no session token for this auth: wrong-token"), "Wrong error received");
@@ -144,12 +165,20 @@ mod test {
144165

145166
let token = AUTH["leader"].clone();
146167
let auth_header = format!("Bearer {}", token);
147-
let req = Request::builder().header(AUTHORIZATION, auth_header).body(Body::empty()).unwrap();
148-
149-
let altered_request = for_request(req, &dummy_adapter, redis).await.expect("Valid requests should succeed");
150-
let session = altered_request.extensions().get::<Session>().expect("There should be a Session set inside the request");
168+
let req = Request::builder()
169+
.header(AUTHORIZATION, auth_header)
170+
.body(Body::empty())
171+
.unwrap();
172+
173+
let altered_request = for_request(req, &dummy_adapter, redis)
174+
.await
175+
.expect("Valid requests should succeed");
176+
let session = altered_request
177+
.extensions()
178+
.get::<Session>()
179+
.expect("There should be a Session set inside the request");
151180
let leader_id = IDS["leader"].to_hex_non_prefix_string();
152181
assert_eq!(leader_id, session.uid);
153182
assert!(session.ip.is_none());
154183
}
155-
}
184+
}

0 commit comments

Comments
 (0)