Skip to content

Commit

Permalink
Improve test_auth error message when contains() fails (apache#6657)
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi authored and adbmal committed Nov 2, 2024
1 parent 6ed68d4 commit b7be99b
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions arrow-flight/examples/flight_sql_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,30 +1006,36 @@ mod tests {
async fn test_auth() {
test_all_clients(|mut client| async move {
// no handshake
assert!(client
.prepare("select 1;".to_string(), None)
.await
.unwrap_err()
.to_string()
.contains("No authorization header"));
assert_contains(
client
.prepare("select 1;".to_string(), None)
.await
.unwrap_err()
.to_string(),
"No authorization header",
);

// Invalid credentials
assert!(client
.handshake("admin", "password2")
.await
.unwrap_err()
.to_string()
.contains("Invalid credentials"));
assert_contains(
client
.handshake("admin", "password2")
.await
.unwrap_err()
.to_string(),
"Invalid credentials",
);

// Invalid Tokens
client.handshake("admin", "password").await.unwrap();
client.set_token("wrong token".to_string());
assert!(client
.prepare("select 1;".to_string(), None)
.await
.unwrap_err()
.to_string()
.contains("invalid token"));
assert_contains(
client
.prepare("select 1;".to_string(), None)
.await
.unwrap_err()
.to_string(),
"invalid token",
);

client.clear_token();

Expand All @@ -1039,4 +1045,15 @@ mod tests {
})
.await
}

fn assert_contains(actual: impl AsRef<str>, searched_for: impl AsRef<str>) {
let actual = actual.as_ref();
let searched_for = searched_for.as_ref();
assert!(
actual.contains(searched_for),
"Expected '{}' to contain '{}'",
actual,
searched_for
);
}
}

0 comments on commit b7be99b

Please sign in to comment.