Add tests for JWKS, Discovery and userinfo endpoints

Signed-off-by: Olivier 'reivilibre <olivier@librepush.net>
This commit is contained in:
Olivier 'reivilibre' 2024-07-07 10:23:31 +01:00
parent 13e6cd5361
commit 6f13cb6145
4 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,11 @@
---
source: src/tests/test_oidc_auth_flow.rs
expression: "(headers, json)"
---
- access-control-allow-origin: "*"
access-control-expose-headers: "*"
content-length: "92"
content-type: application/json
- name: robert
preferred_username: robert
sub: 00000000-0000-0000-0000-000000000000

View File

@ -0,0 +1,9 @@
---
source: src/tests/test_oidc_auth_flow.rs
expression: "(headers, text)"
---
- access-control-allow-origin: "*"
access-control-expose-headers: "*"
content-length: "505"
content-type: application/json
- "{\"issuer\":\"http://idcoop.example.com\",\"authorization_endpoint\":\"http://idcoop.example.com/oidc/auth\",\"token_endpoint\":\"http://idcoop.example.com/oidc/token\",\"userinfo_endpoint\":\"http://idcoop.example.com/oidc/userinfo\",\"jwks_uri\":\"http://idcoop.example.com/oidc/jwks\",\"scopes_supported\":[\"openid\"],\"response_types_supported\":[\"code\"],\"response_modes_supported\":[\"query\"],\"grant_types_supported\":[\"authorization_code\"],\"subject_types_supported\":[\"public\"],\"id_token_signing_alg_values_supported\":[\"RS256\"]}"

View File

@ -0,0 +1,9 @@
---
source: src/tests/test_oidc_auth_flow.rs
expression: "(headers, text)"
---
- access-control-allow-origin: "*"
access-control-expose-headers: "*"
content-length: "425"
content-type: application/json
- "{\"keys\":[{\"kty\":\"RSA\",\"n\":\"w7umnDmvt2ntktJZaeaDLF4wTHeUCXkCQnGOUPTQCExdlPVQcAIjH9sJmk2dWllhRkm_81nn-x8dXqjYbCvTGC_kHSYodiPiqTLQ1pu4YcvRbQh1XPYtc_T67l29KJtow1i7gZD3QqiWUwufDm2SpoC-Dh-RdUL-SUf2V9tToy6JVzyaNbKJy7_ZpYLn74VJpwte6J0kqhSwQJ4VHnY233Zy0oZKdMWvBtJ1uy7OyHWscqPDOUtjPmsyciyPO3qo4389MiFtAJvPdJkWvNYTtg_mDXFQNsCBPTBCP4nuPNGMS0NFRwo1-A3FYq-HHhMcrGJHS_FSvlNeIDTuu5ODVQ\",\"e\":\"AQAB\",\"use\":\"sig\",\"kid\":\"thekey\",\"alg\":\"RS256\"}]}"

View File

@ -9,7 +9,7 @@ use insta::assert_yaml_snapshot;
use maplit::btreemap; use maplit::btreemap;
use sqlx::types::Uuid; use sqlx::types::Uuid;
use crate::{passwords::create_password_hash, store::CreateUser, tests::basic_system}; use crate::{passwords::create_password_hash, tests::basic_system};
async fn dump_resp_text( async fn dump_resp_text(
req_name: &str, req_name: &str,
@ -152,4 +152,38 @@ async fn test_full_flow() {
assert_eq!(status, 200); assert_eq!(status, 200);
let json: BTreeMap<String, serde_json::Value> = serde_json::from_str(&text).unwrap(); let json: BTreeMap<String, serde_json::Value> = serde_json::from_str(&text).unwrap();
assert_yaml_snapshot!("6/token", (headers, json)); assert_yaml_snapshot!("6/token", (headers, json));
// 7. /userinfo request
let resp = client
.get("/oidc/userinfo")
.header(
"Authorization",
"Bearer HL4qRFKUlBqkrPTvAQ6z-xpYf2uo9sbO68miVnnz7KE",
)
.send()
.await;
let (status, headers, text) = dump_resp_text("7. /userinfo", resp).await;
assert_eq!(status, 200);
let json: BTreeMap<String, serde_json::Value> = serde_json::from_str(&text).unwrap();
assert_yaml_snapshot!("7/userinfo", (headers, json));
}
#[tokio::test]
async fn test_jwks_endpoint() {
let sys = basic_system().await;
let client = TestClient::new(sys.web);
let resp = client.get("/oidc/jwks").send().await;
let (status, headers, text) = dump_resp_text("/jwks", resp).await;
assert_eq!(status, 200);
assert_yaml_snapshot!((headers, text));
}
#[tokio::test]
async fn test_discovery_endpoint() {
let sys = basic_system().await;
let client = TestClient::new(sys.web);
let resp = client.get("/.well-known/openid-configuration").send().await;
let (status, headers, text) = dump_resp_text("discovery", resp).await;
assert_eq!(status, 200);
assert_yaml_snapshot!((headers, text));
} }