Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

OAuth 2.0 sessions list and get admin APIs #3031

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
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
55 changes: 55 additions & 0 deletions crates/handlers/src/admin/v1/oauth2_sessions/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,58 @@ pub async fn handler(
&base,
)))
}

#[cfg(test)]
mod tests {
use hyper::{Request, StatusCode};
use sqlx::PgPool;

use crate::test_utils::{setup, RequestBuilderExt, ResponseExt, TestState};

#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_oauth2_simple_session_list(pool: PgPool) {
setup();
let mut state = TestState::from_pool(pool).await.unwrap();
let token = state.token_with_scope("urn:mas:admin").await;

// We already have a session because of the token above
let request = Request::get("/api/admin/v1/oauth2-sessions")
.bearer(&token)
.empty();
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
insta::assert_json_snapshot!(body, @r###"
{
"meta": {
"count": 1
},
"data": [
{
"type": "oauth2-session",
"id": "01FSHN9AG0MKGTBNZ16RDR3PVY",
"attributes": {
"created_at": "2022-01-16T14:40:00Z",
"finished_at": null,
"user_id": null,
"user_session_id": null,
"client_id": "01FSHN9AG0FAQ50MT1E9FFRPZR",
"scope": "urn:mas:admin",
"user_agent": null,
"last_active_at": null,
"last_active_ip": null
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/01FSHN9AG0MKGTBNZ16RDR3PVY"
}
}
],
"links": {
"self": "/api/admin/v1/oauth2-sessions?page[first]=10",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess too late to ask this now, but what's the idea behind this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the JSON API spec adds self links wherever it can, so that you get canonical URLs of even nested stuff

"first": "/api/admin/v1/oauth2-sessions?page[first]=10",
"last": "/api/admin/v1/oauth2-sessions?page[last]=10"
}
}
"###);
}
}
Loading