Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
workspaces: backend
- run: cargo fmt --all --check
- run: cargo clippy --locked --all-targets --all-features -- -D warnings
# Out of `--all-targets` (`test = false`): it runs only against a
# configured server, in the OIDC job.
- run: cargo clippy --locked --all-features --test semantic_conformance -- -D warnings
- name: Tests without development login (production defaults)
run: cargo test --locked
- name: DuckLake catalog database
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/oidc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ jobs:
sleep 2
done
exit 1
# #144: the production API against this very server, before Playwright
# (both edit the fixture's memberships, never at once). Its own loopback
# address: OIDC admission is per client, the browser keeps its budget.
- name: API conformance with real OIDC identities, A/B oracle and revocation
working-directory: backend
env:
DUCKDB_LIB_DIR: /tmp/oidc-duckdb
DUCKDB_INCLUDE_DIR: /tmp/oidc-duckdb
LD_LIBRARY_PATH: /tmp/oidc-duckdb
DATABASE_URL: postgres://bi:bi@127.0.0.1:18072/bi
BI_TEST_OIDC_ISSUER: http://127.0.0.1:18071/realms/bi-test
BI_CONFORMANCE_BASE_URL: http://127.0.0.1:18070
BI_CONFORMANCE_PROJECT_DIR: ${{ github.workspace }}/frontend/e2e/semantic/project
BI_CONFORMANCE_CLIENT_ADDR: 127.0.0.2
run: cargo test --locked -j 4 -p bi-server --no-default-features --features postgres-tests --test semantic_conformance -- --test-threads=1
- name: Corporate login, semantic Explorar A/B, logout, keyboard and axe
run: npm run test:e2e -- e2e/oidc.spec.ts e2e/explore.spec.ts
working-directory: frontend
Expand Down
7 changes: 7 additions & 0 deletions backend/crates/bi-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ libc = "0.2"

[lints]
workspace = true

# Conformance of the production API (#144): it requires a configured server
# and fails without one, so it runs only by name (`--test
# semantic_conformance`), the same command locally and in the OIDC job.
[[test]]
name = "semantic_conformance"
test = false
57 changes: 8 additions & 49 deletions backend/crates/bi-server/src/oidc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ proptest! {
}
}

// The real form's login, shared with the conformance target (#144). Declared
// here, outside `real`: a path inside an inline module resolves through a
// `tests/real/` directory that does not exist, which only Windows tolerates.
#[cfg(feature = "postgres-tests")]
#[path = "../../tests/common/keycloak.rs"]
mod keycloak;

#[cfg(feature = "postgres-tests")]
mod real {
use super::*;
Expand All @@ -182,55 +189,7 @@ mod real {
authorize_as(url, "oidc-user").await
}

/// The login of `username` (password `oidc-test-only`) at the real form.
async fn authorize_as(url: &str, username: &str) -> String {
let http = http_client().unwrap();
let response = http.get(url).send().await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let cookies = response
.headers()
.get_all(header::SET_COOKIE)
.iter()
.map(|value| {
value
.to_str()
.unwrap()
.split(';')
.next()
.unwrap()
.to_owned()
})
.collect::<Vec<_>>()
.join("; ");
let html = response.text().await.unwrap();
let form = html
.split("id=\"kc-form-login\"")
.nth(1)
.expect("real Keycloak login form");
let action = form
.split("action=\"")
.nth(1)
.unwrap()
.split('"')
.next()
.unwrap()
.replace("&amp;", "&");
let response = http
.post(action)
.header(header::COOKIE, cookies)
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(format!(
"username={username}&password=oidc-test-only&credentialId="
))
.send()
.await
.unwrap();
assert_eq!(response.status(), StatusCode::FOUND);
response.headers()[header::LOCATION]
.to_str()
.unwrap()
.to_owned()
}
use super::keycloak::authorize_as;

async fn tokens(
config: &OidcConfig,
Expand Down
64 changes: 64 additions & 0 deletions backend/crates/bi-server/tests/common/keycloak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! The real login form of the OIDC fixture (`docker/oidc`), shared by the
//! router tests (`src/oidc/tests.rs`) and the conformance target
//! (`tests/semantic_conformance.rs`): no provider endpoint is replaced.

use std::time::Duration;

use reqwest::StatusCode;
use reqwest::header;

/// The login of `username` (password `oidc-test-only`) at the real form the
/// authorization `url` opens: the provider's redirect back to the
/// application, with its code and state.
pub async fn authorize_as(url: &str, username: &str) -> String {
let http = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.timeout(Duration::from_secs(5))
.build()
.unwrap();
let response = http.get(url).send().await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let cookies = response
.headers()
.get_all(header::SET_COOKIE)
.iter()
.map(|value| {
value
.to_str()
.unwrap()
.split(';')
.next()
.unwrap()
.to_owned()
})
.collect::<Vec<_>>()
.join("; ");
let html = response.text().await.unwrap();
let form = html
.split("id=\"kc-form-login\"")
.nth(1)
.expect("real Keycloak login form");
let action = form
.split("action=\"")
.nth(1)
.unwrap()
.split('"')
.next()
.unwrap()
.replace("&amp;", "&");
let response = http
.post(action)
.header(header::COOKIE, cookies)
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
.body(format!(
"username={username}&password=oidc-test-only&credentialId="
))
.send()
.await
.unwrap();
assert_eq!(response.status(), StatusCode::FOUND);
response.headers()[header::LOCATION]
.to_str()
.unwrap()
.to_owned()
}
Loading
Loading