Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions crates/auth-rs/src/http/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,22 @@ mod tests {
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);

// Nor is a Cookie header that is not text (a byte outside visible
// ASCII): it is skipped, not an error.
let (app, _) = with_session(SessionKind::ApiKey);
let unreadable = axum::http::HeaderValue::from_bytes(b"test_session=\xff").unwrap();
let resp = app
.oneshot(
HttpRequest::builder()
.uri("/protected")
.header("cookie", unreadable)
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);
}

// A key in a header wins over a cookie the browser happens to hold.
Expand Down
11 changes: 7 additions & 4 deletions crates/auth-rs/src/ldap_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ async fn authenticate(request: DirectoryLogin<'_>) -> Result<DirectoryUser, Dire
let _ = ldap.unbind().await;
if entries.len() > 1 {
let matches = entries.len();
tracing::warn!(
matches,
"LDAP user filter matched more than one entry; refusing the login"
);
// The message is a const so the call fits one line: tracing's
// `log` fallback (on through axum) repeats it in a branch that
// never runs while a subscriber is set, and on a line of its own
// it is a line no test reaches.
const MESSAGE: &str =
"LDAP user filter matched more than one entry; refusing the login";
tracing::warn!(matches, "{MESSAGE}");
}
return Err(DirectoryError::InvalidCredentials);
};
Expand Down
8 changes: 3 additions & 5 deletions crates/auth-rs/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,9 @@ pub async fn ldap_login<R: AccessRule>(

let grant = R::grant_for(&config.access, username, &user.member_of).ok_or_else(|| {
let groups = user.member_of.len();
tracing::warn!(
username,
groups,
"LDAP login refused: no access rule names this user or their groups"
);
// A const so the call fits one line (see ldap_directory.rs).
const MESSAGE: &str = "LDAP login refused: no access rule names this user or their groups";
tracing::warn!(username, groups, "{MESSAGE}");
LoginError::NotAuthorized
})?;

Expand Down