Skip to content
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

Improve test_auth error message when contains() fails #6657

Merged
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
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
);
}
}
Loading