[Auth] Cover the auth middleware with tests#25
Conversation
AhmedSoliman
left a comment
There was a problem hiding this comment.
Thanks for covering those with tests 💯
| impl FromRef<Arc<AppState>> for AuthenticationState { | ||
| fn from_ref(input: &Arc<AppState>) -> Self { | ||
| Self { | ||
| authenticator: input.authenticator.clone(), | ||
| config: input.context.service_config(), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I thought FromRef was implemented for all T: Clone already, no? I wonder why this wasn't the case for AuthenticationState.
Also, did you try to #[derive(FromRef, Clone)]?
There was a problem hiding this comment.
FromRef<T> for T is implemented for all Ts where T: Clone but here I'm defining how to get an AuthenticationState (custom struct) from an AppState, there's no way the compiler can infer this on its own or even with a derive macro, right?
I think the derive macro might work only if I'm getting a state member from the state struct, but here it's a completely custom new struct.
| /// AuthenticationStatus for a certain route. | ||
| pub async fn authenticate<B>( | ||
| State(state): State<Arc<AppState>>, | ||
| State(state): State<AuthenticationState>, |
There was a problem hiding this comment.
Very happy that you started to use partial states 🚀
| unknown_secret_key: StatusCode, | ||
| } | ||
|
|
||
| async fn run_tests( |
There was a problem hiding this comment.
Should we put #[track_caller] here to get helpful messages when assertions fail? Not super sure if this works with async functions though.
There was a problem hiding this comment.
TIL. But it doesn't work with track_caller indeed: rust-lang/rust#87417
[Auth] Cover the auth middleware with tests