Skip to content

Commit

Permalink
added test for non-asci error
Browse files Browse the repository at this point in the history
  • Loading branch information
shopifyski committed Mar 8, 2024
1 parent f716a28 commit 843c9f7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libsql-server/src/auth/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn parse_grpc_auth_header(
return metadata
.get(GRPC_AUTH_HEADER)
.ok_or(AuthError::AuthHeaderNotFound)
.and_then(|h| h.to_str().map_err(|_| AuthError::AuthHeaderNonAscii)) // this never happens, guaranteed at type level
.and_then(|h| h.to_str().map_err(|_| AuthError::AuthHeaderNonAscii))
.and_then(|t| UserAuthContext::from_auth_str(t))
.map_err(|e| {
tonic::Status::new(
Expand Down Expand Up @@ -103,6 +103,17 @@ mod tests {
);
}

#[test]
fn parse_grpc_auth_header_error_non_ascii() {
let mut map = tonic::metadata::MetadataMap::new();
map.insert("x-authorization", "bearer I❤NY".parse().unwrap());
let result = parse_grpc_auth_header(&map);
assert_eq!(
result.unwrap_err().message(),
"Failed parse grpc auth: Non-ASCII auth header"
)
}

#[test]
fn parse_grpc_auth_header_error_malformed_auth_str() {
let mut map = tonic::metadata::MetadataMap::new();
Expand Down

0 comments on commit 843c9f7

Please sign in to comment.