Skip to content

Commit c070c31

Browse files
committed
fix: apply formatting rules
1 parent 0c5dc13 commit c070c31

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

adapter/src/ethereum.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,19 @@ mod test {
489489
&signature,
490490
)
491491
.expect("Failed to verify signatures");
492+
493+
494+
let sig1 = "0x9fa5852041b9818021323aff8260624fd6998c52c95d9ad5036e0db6f2bf2b2d48a188ec1d638581ff56b0a2ecceca6d3880fc65030558bd8f68b154e7ebf80f1b";
495+
let msg = "1648231285e69677531ffe70719f67a07f3d4393b8425a5a1c84b0c72434c77b";
496+
497+
let verify2 = eth_adapter
498+
.verify(
499+
&ValidatorId::try_from("ce07CbB7e054514D590a0262C93070D838bFBA2e")
500+
.expect("Failed to parse id"),
501+
msg,
502+
&sig1,
503+
)
504+
.expect("Failed to verify signatures");
492505

493506
assert_eq!(verify, true, "invalid signature verification");
494507
}

primitives/src/util/tests/prep_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ lazy_static! {
3636
auth.insert("user".into(), "x8c9v1b2".into());
3737
auth.insert("publisher".into(), "testing".into());
3838
auth.insert("publisher2".into(), "testing2".into());
39-
auth.insert("creator".into(), "0x033ed90e0fec3f3ea1c9b005c724d704501e0196".into());
39+
auth.insert("creator".into(), "0x033Ed90e0FeC3F3ea1C9b005C724D704501e0196".into());
4040
auth.insert("tester".into(), "AUTH_awesomeTester".into());
4141

4242
auth

primitives/src/validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030
{
3131
let validator_id = String::deserialize(deserializer)?;
3232
if validator_id.is_empty() || validator_id.len() != 42 {
33-
return Err(serde::de::Error::custom("invalid validator id".to_string()));
33+
return Err(serde::de::Error::custom("invalid validator id length".to_string()));
3434
}
3535

3636
<[u8; 20] as FromHex>::from_hex(&validator_id[2..]).map_err(serde::de::Error::custom)
@@ -87,7 +87,7 @@ impl TryFrom<&str> for ValidatorId {
8787

8888
if hex_value.len() != 40 {
8989
return Err(DomainError::InvalidArgument(
90-
"Failed to deserialize validator id".to_string(),
90+
"invalid validator id length".to_string(),
9191
));
9292
}
9393

sentry/src/access.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,22 @@ async fn apply_rule(
181181
}
182182

183183
fn forbidden_referrer(session: &Session) -> bool {
184-
if let Some(hostname) = session
184+
match session
185185
.referrer_header
186186
.as_ref()
187187
.map(|rf| rf.split('/').nth(2))
188188
.flatten()
189189
{
190-
return hostname == "localhost"
191-
|| hostname == "127.0.0.1"
192-
|| hostname.starts_with("localhost:")
193-
|| hostname.starts_with("127.0.0.1:");
190+
Some(hostname) => hostname == "localhost" || hostname == "127.0.0.1" || hostname.starts_with("localhost:") || hostname.starts_with("127.0.0.1:"),
191+
None => false
194192
}
195-
196-
false
197193
}
198194

199195
fn forbidden_country(session: &Session) -> bool {
200-
if let Some(country) = session.country.as_ref() {
201-
return country == "XX";
196+
match session.country.as_ref() {
197+
Some(country) => country == "XX",
198+
None => false
202199
}
203-
false
204200
}
205201

206202
#[cfg(test)]

sentry/src/event_aggregator.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,37 +124,36 @@ impl EventAggregator {
124124
}
125125
};
126126

127-
let has_access = check_access(
127+
check_access(
128128
&app.redis,
129129
session,
130130
&app.config.ip_rate_limit,
131131
&record.channel,
132132
events,
133133
)
134-
.await;
135-
if let Err(e) = has_access {
136-
let err = match e {
134+
.await
135+
.map_err(|e| {
136+
match e {
137137
AccessError::OnlyCreatorCanCloseChannel | AccessError::ForbiddenReferrer => {
138138
ResponseError::Forbidden(e.to_string())
139139
}
140140
AccessError::RulesError(error) => ResponseError::TooManyRequests(error),
141141
AccessError::UnAuthenticated => ResponseError::Unauthorized,
142142
_ => ResponseError::BadRequest(e.to_string()),
143-
};
144-
return Err(err);
145-
}
143+
}
144+
})?;
146145

147146
events
148147
.iter()
149148
.for_each(|ev| event_reducer::reduce(&record.channel, &mut record.aggregate, ev));
150149

151150
// only time we don't have session is during
152151
// an unauthenticated close event
153-
if ANALYTICS_RECORDER.is_some() && session.is_some() {
152+
if let (true, Some(session)) = (ANALYTICS_RECORDER.is_some(), session) {
154153
tokio::spawn(analytics_recorder::record(
155154
redis.clone(),
156155
record.channel.clone(),
157-
session.expect("should have session").clone(),
156+
session.clone(),
158157
events.to_owned().to_vec(),
159158
app.logger.clone(),
160159
));

0 commit comments

Comments
 (0)