Skip to content

Commit 01d5413

Browse files
committed
test(oauth): fix submit html page test
1 parent 7f171e1 commit 01d5413

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/api/v1/oauth.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn oauth_auto_submit_form(cb: String, session_id: String) -> String {
133133

134134
#[cfg(test)]
135135
mod oauth_tests {
136-
use crate::test::{self, get};
136+
use crate::test::{self, create_session, get, SESSION_ID};
137137
use axum::http::{Request, StatusCode};
138138
use hyper::Method;
139139
use tower::ServiceExt;
@@ -179,22 +179,27 @@ mod oauth_tests {
179179
let tmp = tempfile::tempdir().unwrap();
180180
let ctx = test::seed(tmp.path());
181181
let app = super::router(ctx.to_owned());
182+
183+
// create a session to use
184+
create_session(ctx).await;
182185

183186
// Request to get the html page
184-
let form_body = "session_id=testSessionId&callback_url=https://radicle.xyz".to_string();
187+
let form_body = format!("session_id={SESSION_ID}&callback_url=https://radicle.xyz");
185188
let req = Request::builder()
186189
.method(Method::POST)
187190
.uri("/oauth")
188191
.header("Content-Type", "application/x-www-form-urlencoded")
189192
.body(form_body)
190193
.unwrap();
191194
let response = app.oneshot(req).await.unwrap();
192-
//let response = post(&app, , Some(Body::from(form_body)), None).await;
193195
let status = response.status();
194-
let redir_url = response.headers()["Location"].to_str().unwrap();
195-
//let html: String = String::from_utf8(html_bytes.to_vec()).unwrap();
196-
197-
assert_eq!(status, StatusCode::TEMPORARY_REDIRECT);
198-
assert_eq!(redir_url, "https://radicle.xyz?session_id=testSessionId");
196+
assert_eq!(status, StatusCode::OK);
197+
let html_bytes = axum::body::to_bytes(response.into_body(), usize::MAX)
198+
.await
199+
.unwrap();
200+
let html: String = String::from_utf8(html_bytes.to_vec()).unwrap();
201+
println!("{}", html);
202+
assert!(html.contains(r#"<body onload="document.frm.submit()">"#));
203+
assert!(html.contains(r#"<form name="frm" action="https://radicle.xyz" method="POST" style="display:none;">"#));
199204
}
200205
}

0 commit comments

Comments
 (0)