-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
145 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use self::fixtures::Fixture; | ||
use bytes::Bytes; | ||
use http_body_util::Empty; | ||
use komainu::scope::Scope; | ||
use serde::Serialize; | ||
use std::str::FromStr; | ||
|
||
mod fixtures; | ||
|
||
#[derive(Serialize)] | ||
struct SerdeResponse { | ||
body: Option<String>, | ||
#[serde(with = "http_serde::header_map")] | ||
headers: http::HeaderMap, | ||
#[serde(with = "http_serde::status_code")] | ||
status: http::StatusCode, | ||
} | ||
|
||
impl From<http::Response<()>> for SerdeResponse { | ||
#[inline] | ||
fn from(value: http::Response<()>) -> Self { | ||
let (parts, _body) = value.into_parts(); | ||
|
||
Self { | ||
body: None, | ||
headers: parts.headers, | ||
status: parts.status, | ||
} | ||
} | ||
} | ||
|
||
impl From<http::Response<Bytes>> for SerdeResponse { | ||
#[inline] | ||
fn from(value: http::Response<Bytes>) -> Self { | ||
let (parts, body) = value.into_parts(); | ||
let body = String::from_utf8(body.to_vec()).unwrap(); | ||
|
||
let mut response: Self = http::Response::from_parts(parts, ()).into(); | ||
response.body = Some(body); | ||
response | ||
} | ||
} | ||
|
||
#[futures_test::test] | ||
async fn success() { | ||
let fixture = Fixture::generate(); | ||
|
||
let uri = http::Uri::builder() | ||
.scheme("http") | ||
.authority("komainu.example") | ||
.path_and_query("/oauth/authorize?response_type=code&client_id=client_1") | ||
.build() | ||
.unwrap(); | ||
|
||
let req = http::Request::builder() | ||
.uri(uri) | ||
.body(Empty::<Bytes>::new()) | ||
.unwrap(); | ||
let req = komainu::Request::read_from(req).await.unwrap(); | ||
|
||
let acceptor = { | ||
let handle = fixture.code_grant.extract_raw(&req).await.unwrap(); | ||
handle | ||
.accept("user id".into(), &Scope::from_str("read").unwrap()) | ||
.await | ||
.unwrap() | ||
}; | ||
|
||
let deny = { | ||
let handle = fixture.code_grant.extract_raw(&req).await.unwrap(); | ||
handle.deny() | ||
}; | ||
|
||
insta::assert_json_snapshot!(SerdeResponse::from(acceptor.into_response())); | ||
insta::assert_json_snapshot!(SerdeResponse::from(deny)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: lib/komainu/tests/flows.rs | ||
expression: "SerdeResponse::from(deny)" | ||
--- | ||
{ | ||
"body": null, | ||
"headers": { | ||
"location": "http://client_1.example/?error=access_denied" | ||
}, | ||
"status": 302 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: lib/komainu/tests/flows.rs | ||
expression: "SerdeResponse::from(acceptor.into_response())" | ||
--- | ||
{ | ||
"body": null, | ||
"headers": { | ||
"location": "http://client_1.example/?code=sn7A6s3FVFsptwK6" | ||
}, | ||
"status": 302 | ||
} |