d718c5a372
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
use crate::common::{get_request_to, req_path};
|
|
use actix_web::{http::StatusCode, test};
|
|
use sqlpage::webserver::http::main_handler;
|
|
|
|
#[actix_web::test]
|
|
async fn test_basic_auth_not_provided() {
|
|
let resp_result = req_path("/tests/errors/basic_auth.sql").await;
|
|
let resp = resp_result.unwrap();
|
|
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);
|
|
assert_eq!(
|
|
resp.headers().get("www-authenticate").unwrap(),
|
|
"Basic realm=\"Authentication required\", charset=\"UTF-8\""
|
|
);
|
|
let body = test::read_body(resp).await;
|
|
let body_str = String::from_utf8(body.to_vec()).unwrap();
|
|
assert!(
|
|
body_str.contains("Unauthorized"),
|
|
"{body_str}\nexpected to contain Unauthorized"
|
|
);
|
|
assert!(
|
|
!body_str.contains("Success!"),
|
|
"{body_str}\nexpected not to contain Success!"
|
|
);
|
|
}
|
|
|
|
#[actix_web::test]
|
|
async fn test_basic_auth_with_credentials() {
|
|
let req = get_request_to("/tests/errors/basic_auth.sql")
|
|
.await
|
|
.unwrap() // log in with credentials "user:password"
|
|
.append_header(("Authorization", "Basic dXNlcjpwYXNzd29yZA=="))
|
|
.to_srv_request();
|
|
let resp = main_handler(req)
|
|
.await
|
|
.expect("req with credentials should succeed");
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
let body = test::read_body(resp).await;
|
|
let body_str = String::from_utf8(body.to_vec()).unwrap();
|
|
assert!(
|
|
body_str.contains("Success!"),
|
|
"{body_str}\nexpected to contain Success"
|
|
);
|
|
}
|