File tree Expand file tree Collapse file tree 5 files changed +30
-22
lines changed Expand file tree Collapse file tree 5 files changed +30
-22
lines changed Original file line number Diff line number Diff line change @@ -489,6 +489,19 @@ mod test {
489
489
& signature ,
490
490
)
491
491
. 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" ) ;
492
505
493
506
assert_eq ! ( verify, true , "invalid signature verification" ) ;
494
507
}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ lazy_static! {
36
36
auth. insert( "user" . into( ) , "x8c9v1b2" . into( ) ) ;
37
37
auth. insert( "publisher" . into( ) , "testing" . into( ) ) ;
38
38
auth. insert( "publisher2" . into( ) , "testing2" . into( ) ) ;
39
- auth. insert( "creator" . into( ) , "0x033ed90e0fec3f3ea1c9b005c724d704501e0196 " . into( ) ) ;
39
+ auth. insert( "creator" . into( ) , "0x033Ed90e0FeC3F3ea1C9b005C724D704501e0196 " . into( ) ) ;
40
40
auth. insert( "tester" . into( ) , "AUTH_awesomeTester" . into( ) ) ;
41
41
42
42
auth
Original file line number Diff line number Diff line change 30
30
{
31
31
let validator_id = String :: deserialize ( deserializer) ?;
32
32
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 ( ) ) ) ;
34
34
}
35
35
36
36
<[ u8 ; 20 ] as FromHex >:: from_hex ( & validator_id[ 2 ..] ) . map_err ( serde:: de:: Error :: custom)
@@ -87,7 +87,7 @@ impl TryFrom<&str> for ValidatorId {
87
87
88
88
if hex_value. len ( ) != 40 {
89
89
return Err ( DomainError :: InvalidArgument (
90
- "Failed to deserialize validator id" . to_string ( ) ,
90
+ "invalid validator id length " . to_string ( ) ,
91
91
) ) ;
92
92
}
93
93
Original file line number Diff line number Diff line change @@ -181,26 +181,22 @@ async fn apply_rule(
181
181
}
182
182
183
183
fn forbidden_referrer ( session : & Session ) -> bool {
184
- if let Some ( hostname ) = session
184
+ match session
185
185
. referrer_header
186
186
. as_ref ( )
187
187
. map ( |rf| rf. split ( '/' ) . nth ( 2 ) )
188
188
. flatten ( )
189
189
{
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
194
192
}
195
-
196
- false
197
193
}
198
194
199
195
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
202
199
}
203
- false
204
200
}
205
201
206
202
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -124,37 +124,36 @@ impl EventAggregator {
124
124
}
125
125
} ;
126
126
127
- let has_access = check_access (
127
+ check_access (
128
128
& app. redis ,
129
129
session,
130
130
& app. config . ip_rate_limit ,
131
131
& record. channel ,
132
132
events,
133
133
)
134
- . await ;
135
- if let Err ( e ) = has_access {
136
- let err = match e {
134
+ . await
135
+ . map_err ( |e| {
136
+ match e {
137
137
AccessError :: OnlyCreatorCanCloseChannel | AccessError :: ForbiddenReferrer => {
138
138
ResponseError :: Forbidden ( e. to_string ( ) )
139
139
}
140
140
AccessError :: RulesError ( error) => ResponseError :: TooManyRequests ( error) ,
141
141
AccessError :: UnAuthenticated => ResponseError :: Unauthorized ,
142
142
_ => ResponseError :: BadRequest ( e. to_string ( ) ) ,
143
- } ;
144
- return Err ( err) ;
145
- }
143
+ }
144
+ } ) ?;
146
145
147
146
events
148
147
. iter ( )
149
148
. for_each ( |ev| event_reducer:: reduce ( & record. channel , & mut record. aggregate , ev) ) ;
150
149
151
150
// only time we don't have session is during
152
151
// an unauthenticated close event
153
- if ANALYTICS_RECORDER . is_some ( ) && session . is_some ( ) {
152
+ if let ( true , Some ( session ) ) = ( ANALYTICS_RECORDER . is_some ( ) , session ) {
154
153
tokio:: spawn ( analytics_recorder:: record (
155
154
redis. clone ( ) ,
156
155
record. channel . clone ( ) ,
157
- session. expect ( "should have session" ) . clone ( ) ,
156
+ session. clone ( ) ,
158
157
events. to_owned ( ) . to_vec ( ) ,
159
158
app. logger . clone ( ) ,
160
159
) ) ;
You can’t perform that action at this time.
0 commit comments