mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
This isn't a solution for #3484, as that seems to be an issue with privileges on the user's side. However, in the process of figuring that out, I realized we never explicitly test password-less auth.
This commit is contained in:
parent
dc32f99c0f
commit
2f5ba71c1e
2 changed files with 33 additions and 0 deletions
|
@ -1,8 +1,12 @@
|
|||
use anyhow::Context;
|
||||
use futures::TryStreamExt;
|
||||
use sqlx::mysql::{MySql, MySqlConnection, MySqlPool, MySqlPoolOptions, MySqlRow};
|
||||
use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo};
|
||||
use sqlx_core::connection::ConnectOptions;
|
||||
use sqlx_mysql::MySqlConnectOptions;
|
||||
use sqlx_test::{new, setup_if_needed};
|
||||
use std::env;
|
||||
use url::Url;
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_connects() -> anyhow::Result<()> {
|
||||
|
@ -14,6 +18,27 @@ async fn it_connects() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_connects_without_password() -> anyhow::Result<()> {
|
||||
setup_if_needed();
|
||||
|
||||
let mut url = Url::parse(&env::var("DATABASE_URL").context("expected DATABASE_URL")?)
|
||||
.context("error parsing DATABASE_URL")?;
|
||||
|
||||
url.set_username("no_password").unwrap();
|
||||
url.set_password(None).unwrap();
|
||||
|
||||
let mut conn = MySqlConnectOptions::from_url(&url)?.connect().await?;
|
||||
|
||||
let vars = sqlx::raw_sql("SHOW VARIABLES").fetch_all(&mut conn).await?;
|
||||
|
||||
assert!(!vars.is_empty());
|
||||
|
||||
conn.close().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_maths() -> anyhow::Result<()> {
|
||||
let mut conn = new::<MySql>().await?;
|
||||
|
|
|
@ -22,3 +22,11 @@ CREATE TABLE products (
|
|||
name TEXT,
|
||||
price NUMERIC CHECK (price > 0)
|
||||
);
|
||||
|
||||
-- Create a user without a password to test passwordless auth.
|
||||
CREATE USER 'no_password'@'%';
|
||||
|
||||
-- The minimum privilege apparently needed to connect to a specific database.
|
||||
-- Granting no privileges, or just `GRANT USAGE`, gives an "access denied" error.
|
||||
-- https://github.com/launchbadge/sqlx/issues/3484#issuecomment-2350901546
|
||||
GRANT SELECT ON sqlx.* TO 'no_password'@'%';
|
||||
|
|
Loading…
Reference in a new issue