-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Auth] Cover the auth middleware with tests #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -178,11 +198,11 @@ pub async fn ensure_admin<B>( | |||
/// of the other "ensure_*" middlewares in this module to enforce the expected | |||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very happy that you started to use partial states 🚀
unknown_secret_key: StatusCode, | ||
} | ||
|
||
async fn run_tests( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL. But it doesn"t work with track_caller
indeed: rust-lang/rust#87417
[Auth] Cover the auth middleware with tests