Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(vendor): extract inline test modules into separate files

Steven Enamakelc6feab73b60b
diff --git a/vendor/motosan-ai-oauth/src/exchange.rs b/vendor/motosan-ai-oauth/src/exchange.rs
index 4a4813fec1..a1c9222bba 100644
--- a/vendor/motosan-ai-oauth/src/exchange.rs
+++ b/vendor/motosan-ai-oauth/src/exchange.rs
@@ -109,124 +109,5 @@ pub async fn refresh_token(config: &OAuthConfig, refresh_token: &str) -> Result<
}
#[cfg(test)]
-mod tests {
- use super::*;
- use crate::TokenBodyFormat;
- use mockito::Matcher;
-
- #[tokio::test]
- async fn exchange_code_omits_state_for_random_strategy_form_body() {
- let mut server = mockito::Server::new_async().await;
- let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
-
- let mock = server
- .mock("POST", "/token")
- .match_header(
- "content-type",
- Matcher::Regex("application/x-www-form-urlencoded".into()),
- )
- .match_body(Matcher::Exact(
- "grant_type=authorization_code&code=AUTHCODE&redirect_uri=http%3A%2F%2F127.0.0.1%2Fcb&code_verifier=VERIFIER&client_id=test-client"
- .into(),
- ))
- .with_status(200)
- .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
- .create_async()
- .await;
-
- let cfg = crate::OAuthConfig {
- client_id: "test-client",
- client_secret: None,
- auth_url: "https://unused/",
- token_url,
- scopes: &[],
- redirect_port: None,
- callback_path: "/auth/callback",
- redirect_uri_host: "127.0.0.1",
- token_body: TokenBodyFormat::Form,
- extra_auth_params: &[],
- state_strategy: crate::StateStrategy::Random,
- };
- let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
- .await
- .expect("ok");
- assert_eq!(token.access_token, "AT");
- mock.assert_async().await;
- }
-
- #[tokio::test]
- async fn exchange_code_omits_state_for_random_strategy_json_body() {
- let mut server = mockito::Server::new_async().await;
- let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
-
- let mock = server
- .mock("POST", "/token")
- .match_header("content-type", Matcher::Regex("application/json".into()))
- // Matcher::JsonString compares parsed JSON, so key order in the
- // serialized HashMap does not matter.
- .match_body(Matcher::JsonString(
- r#"{"grant_type":"authorization_code","code":"AUTHCODE","redirect_uri":"http://127.0.0.1/cb","code_verifier":"VERIFIER","client_id":"test-client"}"#
- .into(),
- ))
- .with_status(200)
- .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
- .create_async()
- .await;
-
- let cfg = crate::OAuthConfig {
- client_id: "test-client",
- client_secret: None,
- auth_url: "https://unused/",
- token_url,
- scopes: &[],
- redirect_port: None,
- callback_path: "/auth/callback",
- redirect_uri_host: "127.0.0.1",
- token_body: TokenBodyFormat::Json,
- extra_auth_params: &[],
- state_strategy: crate::StateStrategy::Random,
- };
- let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
- .await
- .expect("ok");
- assert_eq!(token.access_token, "AT");
- mock.assert_async().await;
- }
-
- #[tokio::test]
- async fn exchange_code_sends_state_for_equals_verifier_strategy_json_body() {
- let mut server = mockito::Server::new_async().await;
- let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
-
- let mock = server
- .mock("POST", "/token")
- .match_header("content-type", Matcher::Regex("application/json".into()))
- .match_body(Matcher::JsonString(
- r#"{"grant_type":"authorization_code","code":"AUTHCODE","state":"STATE","redirect_uri":"http://127.0.0.1/cb","code_verifier":"VERIFIER","client_id":"test-client"}"#
- .into(),
- ))
- .with_status(200)
- .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
- .create_async()
- .await;
-
- let cfg = crate::OAuthConfig {
- client_id: "test-client",
- client_secret: None,
- auth_url: "https://unused/",
- token_url,
- scopes: &[],
- redirect_port: None,
- callback_path: "/auth/callback",
- redirect_uri_host: "127.0.0.1",
- token_body: TokenBodyFormat::Json,
- extra_auth_params: &[],
- state_strategy: crate::StateStrategy::EqualsVerifier,
- };
- let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
- .await
- .expect("ok");
- assert_eq!(token.access_token, "AT");
- mock.assert_async().await;
- }
-}
+#[path = "exchange_tests.rs"]
+mod tests;
diff --git a/vendor/motosan-ai-oauth/src/exchange_tests.rs b/vendor/motosan-ai-oauth/src/exchange_tests.rs
new file mode 100644
index 0000000000..63a4117e1a
--- /dev/null
+++ b/vendor/motosan-ai-oauth/src/exchange_tests.rs
@@ -0,0 +1,119 @@
+use super::*;
+use crate::TokenBodyFormat;
+use mockito::Matcher;
+
+#[tokio::test]
+async fn exchange_code_omits_state_for_random_strategy_form_body() {
+ let mut server = mockito::Server::new_async().await;
+ let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
+
+ let mock = server
+ .mock("POST", "/token")
+ .match_header(
+ "content-type",
+ Matcher::Regex("application/x-www-form-urlencoded".into()),
+ )
+ .match_body(Matcher::Exact(
+ "grant_type=authorization_code&code=AUTHCODE&redirect_uri=http%3A%2F%2F127.0.0.1%2Fcb&code_verifier=VERIFIER&client_id=test-client"
+ .into(),
+ ))
+ .with_status(200)
+ .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
+ .create_async()
+ .await;
+
+ let cfg = crate::OAuthConfig {
+ client_id: "test-client",
+ client_secret: None,
+ auth_url: "https://unused/",
+ token_url,
+ scopes: &[],
+ redirect_port: None,
+ callback_path: "/auth/callback",
+ redirect_uri_host: "127.0.0.1",
+ token_body: TokenBodyFormat::Form,
+ extra_auth_params: &[],
+ state_strategy: crate::StateStrategy::Random,
+ };
+ let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
+ .await
+ .expect("ok");
+ assert_eq!(token.access_token, "AT");
+ mock.assert_async().await;
+}
+
+#[tokio::test]
+async fn exchange_code_omits_state_for_random_strategy_json_body() {
+ let mut server = mockito::Server::new_async().await;
+ let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
+
+ let mock = server
+ .mock("POST", "/token")
+ .match_header("content-type", Matcher::Regex("application/json".into()))
+ // Matcher::JsonString compares parsed JSON, so key order in the
+ // serialized HashMap does not matter.
+ .match_body(Matcher::JsonString(
+ r#"{"grant_type":"authorization_code","code":"AUTHCODE","redirect_uri":"http://127.0.0.1/cb","code_verifier":"VERIFIER","client_id":"test-client"}"#
+ .into(),
+ ))
+ .with_status(200)
+ .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
+ .create_async()
+ .await;
+
+ let cfg = crate::OAuthConfig {
+ client_id: "test-client",
+ client_secret: None,
+ auth_url: "https://unused/",
+ token_url,
+ scopes: &[],
+ redirect_port: None,
+ callback_path: "/auth/callback",
+ redirect_uri_host: "127.0.0.1",
+ token_body: TokenBodyFormat::Json,
+ extra_auth_params: &[],
+ state_strategy: crate::StateStrategy::Random,
+ };
+ let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
+ .await
+ .expect("ok");
+ assert_eq!(token.access_token, "AT");
+ mock.assert_async().await;
+}
+
+#[tokio::test]
+async fn exchange_code_sends_state_for_equals_verifier_strategy_json_body() {
+ let mut server = mockito::Server::new_async().await;
+ let token_url: &'static str = Box::leak(format!("{}/token", server.url()).into_boxed_str());
+
+ let mock = server
+ .mock("POST", "/token")
+ .match_header("content-type", Matcher::Regex("application/json".into()))
+ .match_body(Matcher::JsonString(
+ r#"{"grant_type":"authorization_code","code":"AUTHCODE","state":"STATE","redirect_uri":"http://127.0.0.1/cb","code_verifier":"VERIFIER","client_id":"test-client"}"#
+ .into(),
+ ))
+ .with_status(200)
+ .with_body(r#"{"access_token":"AT","refresh_token":"RT","expires_in":3600}"#)
+ .create_async()
+ .await;
+
+ let cfg = crate::OAuthConfig {
+ client_id: "test-client",
+ client_secret: None,
+ auth_url: "https://unused/",
+ token_url,
+ scopes: &[],
+ redirect_port: None,
+ callback_path: "/auth/callback",
+ redirect_uri_host: "127.0.0.1",
+ token_body: TokenBodyFormat::Json,
+ extra_auth_params: &[],
+ state_strategy: crate::StateStrategy::EqualsVerifier,
+ };
+ let token = exchange_code(&cfg, "AUTHCODE", "STATE", "VERIFIER", "http://127.0.0.1/cb")
+ .await
+ .expect("ok");
+ assert_eq!(token.access_token, "AT");
+ mock.assert_async().await;
+}
diff --git a/vendor/motosan-ai-oauth/src/lib.rs b/vendor/motosan-ai-oauth/src/lib.rs
index f7c277ac2e..8751f4ddee 100644
--- a/vendor/motosan-ai-oauth/src/lib.rs
+++ b/vendor/motosan-ai-oauth/src/lib.rs
@@ -152,123 +152,5 @@ fn open_browser(url: &str) -> std::io::Result<()> {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn dummy_config() -> OAuthConfig {
- OAuthConfig {
- client_id: "test-client",
- client_secret: None,
- auth_url: "https://auth.example.com/oauth/authorize",
- token_url: "https://auth.example.com/oauth/token",
- scopes: &["openid", "profile"],
- redirect_port: None,
- callback_path: "/auth/callback",
- redirect_uri_host: "127.0.0.1",
- token_body: TokenBodyFormat::Form,
- extra_auth_params: &[],
- state_strategy: StateStrategy::Random,
- }
- }
-
- #[test]
- fn build_auth_url_contains_required_params() {
- let config = dummy_config();
- let url = build_auth_url(
- &config,
- "challenge123",
- "state456",
- "http://127.0.0.1:9999/auth/callback",
- );
- assert!(url.contains("client_id=test-client"));
- assert!(url.contains("response_type=code"));
- assert!(url.contains("code_challenge=challenge123"));
- assert!(url.contains("code_challenge_method=S256"));
- assert!(url.contains("state=state456"));
- assert!(url.contains("redirect_uri="));
- assert!(url.contains("scope="));
- }
-
- #[test]
- fn build_auth_url_includes_scopes_joined() {
- let config = dummy_config();
- let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
- assert!(url.contains("scope=openid+profile") || url.contains("scope=openid%20profile"));
- }
-
- #[test]
- fn build_auth_url_parses_as_valid_url() {
- let config = dummy_config();
- let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
- reqwest::Url::parse(&url).expect("auth URL must be valid");
- }
-
- #[test]
- fn build_auth_url_appends_extra_auth_params() {
- let config = OAuthConfig {
- extra_auth_params: &[("foo", "bar"), ("baz", "qux")],
- ..dummy_config()
- };
- let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
- assert!(url.contains("foo=bar"));
- assert!(url.contains("baz=qux"));
- }
-
- #[test]
- fn build_auth_url_no_longer_hardcodes_access_type() {
- // Empty extra_auth_params should produce no access_type query pair.
- let config = OAuthConfig {
- extra_auth_params: &[],
- ..dummy_config()
- };
- let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
- assert!(!url.contains("access_type="));
- }
-
- #[test]
- fn build_auth_url_uses_redirect_uri_host_in_uri() {
- // The redirect_uri is built by login(); we test the helper that constructs it.
- // The host substring comes from config.redirect_uri_host, not from the bind addr.
- let uri = build_redirect_uri("localhost", 53692, "/callback");
- assert_eq!(uri, "http://localhost:53692/callback");
-
- let uri = build_redirect_uri("127.0.0.1", 1455, "/auth/callback");
- assert_eq!(uri, "http://127.0.0.1:1455/auth/callback");
- }
-
- #[test]
- fn token_is_expired_when_issued_at_zero() {
- let token = Token {
- access_token: "a".into(),
- refresh_token: "r".into(),
- id_token: None,
- expires_in: 3600,
- issued_at: 0,
- };
- assert!(token.is_expired());
- }
-
- #[test]
- fn token_not_expired_when_just_issued() {
- let token = Token {
- access_token: "a".into(),
- refresh_token: "r".into(),
- id_token: None,
- expires_in: 3600,
- issued_at: unix_now(),
- };
- assert!(!token.is_expired());
- }
-
- #[test]
- fn token_within_buffer_is_considered_expired() {
- let token = Token {
- access_token: "a".into(),
- refresh_token: "r".into(),
- id_token: None,
- expires_in: 30, // expires in 30s, within the 60s buffer
- issued_at: unix_now(),
- };
- assert!(token.is_expired());
- }
-}
+#[path = "lib_tests.rs"]
+mod tests;
diff --git a/vendor/motosan-ai-oauth/src/lib_tests.rs b/vendor/motosan-ai-oauth/src/lib_tests.rs
new file mode 100644
index 0000000000..40af61dd29
--- /dev/null
+++ b/vendor/motosan-ai-oauth/src/lib_tests.rs
@@ -0,0 +1,118 @@
+use super::*;
+
+fn dummy_config() -> OAuthConfig {
+ OAuthConfig {
+ client_id: "test-client",
+ client_secret: None,
+ auth_url: "https://auth.example.com/oauth/authorize",
+ token_url: "https://auth.example.com/oauth/token",
+ scopes: &["openid", "profile"],
+ redirect_port: None,
+ callback_path: "/auth/callback",
+ redirect_uri_host: "127.0.0.1",
+ token_body: TokenBodyFormat::Form,
+ extra_auth_params: &[],
+ state_strategy: StateStrategy::Random,
+ }
+}
+
+#[test]
+fn build_auth_url_contains_required_params() {
+ let config = dummy_config();
+ let url = build_auth_url(
+ &config,
+ "challenge123",
+ "state456",
+ "http://127.0.0.1:9999/auth/callback",
+ );
+ assert!(url.contains("client_id=test-client"));
+ assert!(url.contains("response_type=code"));
+ assert!(url.contains("code_challenge=challenge123"));
+ assert!(url.contains("code_challenge_method=S256"));
+ assert!(url.contains("state=state456"));
+ assert!(url.contains("redirect_uri="));
+ assert!(url.contains("scope="));
+}
+
+#[test]
+fn build_auth_url_includes_scopes_joined() {
+ let config = dummy_config();
+ let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
+ assert!(url.contains("scope=openid+profile") || url.contains("scope=openid%20profile"));
+}
+
+#[test]
+fn build_auth_url_parses_as_valid_url() {
+ let config = dummy_config();
+ let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
+ reqwest::Url::parse(&url).expect("auth URL must be valid");
+}
+
+#[test]
+fn build_auth_url_appends_extra_auth_params() {
+ let config = OAuthConfig {
+ extra_auth_params: &[("foo", "bar"), ("baz", "qux")],
+ ..dummy_config()
+ };
+ let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
+ assert!(url.contains("foo=bar"));
+ assert!(url.contains("baz=qux"));
+}
+
+#[test]
+fn build_auth_url_no_longer_hardcodes_access_type() {
+ // Empty extra_auth_params should produce no access_type query pair.
+ let config = OAuthConfig {
+ extra_auth_params: &[],
+ ..dummy_config()
+ };
+ let url = build_auth_url(&config, "c", "s", "http://127.0.0.1:1234/auth/callback");
+ assert!(!url.contains("access_type="));
+}
+
+#[test]
+fn build_auth_url_uses_redirect_uri_host_in_uri() {
+ // The redirect_uri is built by login(); we test the helper that constructs it.
+ // The host substring comes from config.redirect_uri_host, not from the bind addr.
+ let uri = build_redirect_uri("localhost", 53692, "/callback");
+ assert_eq!(uri, "http://localhost:53692/callback");
+
+ let uri = build_redirect_uri("127.0.0.1", 1455, "/auth/callback");
+ assert_eq!(uri, "http://127.0.0.1:1455/auth/callback");
+}
+
+#[test]
+fn token_is_expired_when_issued_at_zero() {
+ let token = Token {
+ access_token: "a".into(),
+ refresh_token: "r".into(),
+ id_token: None,
+ expires_in: 3600,
+ issued_at: 0,
+ };
+ assert!(token.is_expired());
+}
+
+#[test]
+fn token_not_expired_when_just_issued() {
+ let token = Token {
+ access_token: "a".into(),
+ refresh_token: "r".into(),
+ id_token: None,
+ expires_in: 3600,
+ issued_at: unix_now(),
+ };
+ assert!(!token.is_expired());
+}
+
+#[test]
+fn token_within_buffer_is_considered_expired() {
+ let token = Token {
+ access_token: "a".into(),
+ refresh_token: "r".into(),
+ id_token: None,
+ expires_in: 30, // expires in 30s, within the 60s buffer
+ issued_at: unix_now(),
+ };
+ assert!(token.is_expired());
+}
diff --git a/vendor/motosan-ai-oauth/src/pkce.rs b/vendor/motosan-ai-oauth/src/pkce.rs
index b087415553..df7fc3469c 100644
--- a/vendor/motosan-ai-oauth/src/pkce.rs
+++ b/vendor/motosan-ai-oauth/src/pkce.rs
@@ -24,48 +24,5 @@ impl Pkce {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn verifier_is_base64url_no_pad() {
- let pkce = Pkce::generate();
- assert!(
- pkce.verifier
- .chars()
- .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'),
- "verifier contains non-base64url chars: {}",
- pkce.verifier
- );
- assert!(
- !pkce.verifier.contains('='),
- "verifier must not have padding"
- );
- assert_eq!(pkce.verifier.len(), 86);
- }
-
- #[test]
- fn challenge_matches_s256_of_verifier() {
- let pkce = Pkce::generate();
- let hash = Sha256::digest(pkce.verifier.as_bytes());
- let expected = URL_SAFE_NO_PAD.encode(hash);
- assert_eq!(pkce.challenge, expected);
- }
-
- #[test]
- fn challenge_is_base64url_no_pad() {
- let pkce = Pkce::generate();
- assert!(pkce
- .challenge
- .chars()
- .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'));
- assert!(!pkce.challenge.contains('='));
- }
-
- #[test]
- fn each_generate_is_unique() {
- let a = Pkce::generate();
- let b = Pkce::generate();
- assert_ne!(a.verifier, b.verifier);
- }
-}
+#[path = "pkce_tests.rs"]
+mod tests;
diff --git a/vendor/motosan-ai-oauth/src/pkce_tests.rs b/vendor/motosan-ai-oauth/src/pkce_tests.rs
new file mode 100644
index 0000000000..8ce3321949
--- /dev/null
+++ b/vendor/motosan-ai-oauth/src/pkce_tests.rs
@@ -0,0 +1,43 @@
+use super::*;
+
+#[test]
+fn verifier_is_base64url_no_pad() {
+ let pkce = Pkce::generate();
+ assert!(
+ pkce.verifier
+ .chars()
+ .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'),
+ "verifier contains non-base64url chars: {}",
+ pkce.verifier
+ );
+ assert!(
+ !pkce.verifier.contains('='),
+ "verifier must not have padding"
+ );
+ assert_eq!(pkce.verifier.len(), 86);
+}
+
+#[test]
+fn challenge_matches_s256_of_verifier() {
+ let pkce = Pkce::generate();
+ let hash = Sha256::digest(pkce.verifier.as_bytes());
+ let expected = URL_SAFE_NO_PAD.encode(hash);
+ assert_eq!(pkce.challenge, expected);
+}
+
+#[test]
+fn challenge_is_base64url_no_pad() {
+ let pkce = Pkce::generate();
+ assert!(pkce
+ .challenge
+ .chars()
+ .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_'));
+ assert!(!pkce.challenge.contains('='));
+}
+
+#[test]
+fn each_generate_is_unique() {
+ let a = Pkce::generate();
+ let b = Pkce::generate();
+ assert_ne!(a.verifier, b.verifier);
+}
diff --git a/vendor/motosan-ai-oauth/src/providers/codex.rs b/vendor/motosan-ai-oauth/src/providers/codex.rs
index 71add5a13d..00b6ee4804 100644
--- a/vendor/motosan-ai-oauth/src/providers/codex.rs
+++ b/vendor/motosan-ai-oauth/src/providers/codex.rs
@@ -17,30 +17,5 @@ pub fn codex() -> OAuthConfig {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn codex_config_has_correct_client_id() {
- let c = codex();
- assert_eq!(c.client_id, "app_EMoamEEZ73f0CkXaXp7hrann");
- }
-
- #[test]
- fn codex_config_has_no_client_secret() {
- let c = codex();
- assert!(c.client_secret.is_none());
- }
-
- #[test]
- fn codex_config_redirect_port_is_1455() {
- let c = codex();
- assert_eq!(c.redirect_port, Some(1455));
- }
-
- #[test]
- fn codex_config_auth_url_is_openai() {
- let c = codex();
- assert!(c.auth_url.contains("auth.openai.com"));
- }
-}
+#[path = "codex_tests.rs"]
+mod tests;
diff --git a/vendor/motosan-ai-oauth/src/providers/codex_tests.rs b/vendor/motosan-ai-oauth/src/providers/codex_tests.rs
new file mode 100644
index 0000000000..6889e29e15
--- /dev/null
+++ b/vendor/motosan-ai-oauth/src/providers/codex_tests.rs
@@ -0,0 +1,25 @@
+use super::*;
+
+#[test]
+fn codex_config_has_correct_client_id() {
+ let c = codex();
+ assert_eq!(c.client_id, "app_EMoamEEZ73f0CkXaXp7hrann");
+}
+
+#[test]
+fn codex_config_has_no_client_secret() {
+ let c = codex();
+ assert!(c.client_secret.is_none());
+}
+
+#[test]
+fn codex_config_redirect_port_is_1455() {
+ let c = codex();
+ assert_eq!(c.redirect_port, Some(1455));
+}
+
+#[test]
+fn codex_config_auth_url_is_openai() {
+ let c = codex();
+ assert!(c.auth_url.contains("auth.openai.com"));
+}
diff --git a/vendor/motosan-ai-oauth/src/server.rs b/vendor/motosan-ai-oauth/src/server.rs
index f3efcfed36..58c79aed2e 100644
--- a/vendor/motosan-ai-oauth/src/server.rs
+++ b/vendor/motosan-ai-oauth/src/server.rs
@@ -124,92 +124,5 @@ fn parse_callback(request: &str) -> Result<(String, String), Error> {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn get(path: &str) -> String {
- format!("GET {path} HTTP/1.1\r\nHost: localhost\r\n\r\n")
- }
-
- #[test]
- fn parses_normal_callback() {
- let (code, state) = parse_callback(&get("/auth/callback?code=abc123&state=xyz")).unwrap();
- assert_eq!(code, "abc123");
- assert_eq!(state, "xyz");
- }
-
- #[test]
- fn decodes_percent_encoded_params() {
- let (code, state) =
- parse_callback(&get("/auth/callback?code=ab%2Bcd&state=x%3Dy")).unwrap();
- assert_eq!(code, "ab+cd");
- assert_eq!(state, "x=y");
- }
-
- #[test]
- fn extra_params_are_ignored() {
- let (code, state) =
- parse_callback(&get("/auth/callback?code=c&state=s&session_state=ignored")).unwrap();
- assert_eq!(code, "c");
- assert_eq!(state, "s");
- }
-
- #[test]
- fn missing_code_returns_error() {
- let err = parse_callback(&get("/auth/callback?state=s")).unwrap_err();
- assert!(err.to_string().contains("missing code"));
- }
-
- #[test]
- fn missing_state_returns_error() {
- let err = parse_callback(&get("/auth/callback?code=c")).unwrap_err();
- assert!(err.to_string().contains("missing state"));
- }
-
- #[test]
- fn non_callback_path_is_not_callback() {
- assert!(!is_callback_request(&get("/favicon.ico"), "/auth/callback"));
- assert!(!is_callback_request(&get("/"), "/auth/callback"));
- }
-
- #[test]
- fn callback_path_with_code_is_callback() {
- assert!(is_callback_request(
- &get("/auth/callback?code=abc&state=xyz"),
- "/auth/callback"
- ));
- }
-
- #[test]
- fn anthropic_callback_path_is_callback() {
- assert!(is_callback_request(
- &get("/callback?code=abc&state=xyz"),
- "/callback"
- ));
- }
-
- #[test]
- fn auth_callback_path_does_not_match_anthropic_request() {
- // A request to /callback must not be accepted when callback_path is /auth/callback.
- assert!(!is_callback_request(
- &get("/callback?code=abc&state=xyz"),
- "/auth/callback"
- ));
- }
-
- #[tokio::test]
- async fn bind_dynamic_port_returns_nonzero_port() {
- let server = bind(None).await.expect("bind should succeed");
- assert!(server.port > 0, "dynamic port should be nonzero");
- }
-
- #[tokio::test]
- async fn bind_specific_port_returns_that_port() {
- let probe = TcpListener::bind("127.0.0.1:0").await.unwrap();
- let free_port = probe.local_addr().unwrap().port();
- drop(probe);
-
- let server = bind(Some(free_port)).await.expect("bind should succeed");
- assert_eq!(server.port, free_port);
- }
-}
+#[path = "server_tests.rs"]
+mod tests;
diff --git a/vendor/motosan-ai-oauth/src/server_tests.rs b/vendor/motosan-ai-oauth/src/server_tests.rs
new file mode 100644
index 0000000000..5994440a9a
--- /dev/null
+++ b/vendor/motosan-ai-oauth/src/server_tests.rs
@@ -0,0 +1,86 @@
+use super::*;
+
+fn get(path: &str) -> String {
+ format!("GET {path} HTTP/1.1\r\nHost: localhost\r\n\r\n")
+}
+
+#[test]
+fn parses_normal_callback() {
+ let (code, state) = parse_callback(&get("/auth/callback?code=abc123&state=xyz")).unwrap();
+ assert_eq!(code, "abc123");
+ assert_eq!(state, "xyz");
+}
+
+#[test]
+fn decodes_percent_encoded_params() {
+ let (code, state) = parse_callback(&get("/auth/callback?code=ab%2Bcd&state=x%3Dy")).unwrap();
+ assert_eq!(code, "ab+cd");
+ assert_eq!(state, "x=y");
+}
+
+#[test]
+fn extra_params_are_ignored() {
+ let (code, state) =
+ parse_callback(&get("/auth/callback?code=c&state=s&session_state=ignored")).unwrap();
+ assert_eq!(code, "c");
+ assert_eq!(state, "s");
+}
+
+#[test]
+fn missing_code_returns_error() {
+ let err = parse_callback(&get("/auth/callback?state=s")).unwrap_err();
+ assert!(err.to_string().contains("missing code"));
+}
+
+#[test]
+fn missing_state_returns_error() {
+ let err = parse_callback(&get("/auth/callback?code=c")).unwrap_err();
+ assert!(err.to_string().contains("missing state"));
+}
+
+#[test]
+fn non_callback_path_is_not_callback() {
+ assert!(!is_callback_request(&get("/favicon.ico"), "/auth/callback"));
+ assert!(!is_callback_request(&get("/"), "/auth/callback"));
+}
+
+#[test]
+fn callback_path_with_code_is_callback() {
+ assert!(is_callback_request(
+ &get("/auth/callback?code=abc&state=xyz"),
+ "/auth/callback"
+ ));
+}
+
+#[test]
+fn anthropic_callback_path_is_callback() {
+ assert!(is_callback_request(
+ &get("/callback?code=abc&state=xyz"),
+ "/callback"
+ ));
+}
+
+#[test]
+fn auth_callback_path_does_not_match_anthropic_request() {
+ // A request to /callback must not be accepted when callback_path is /auth/callback.
+ assert!(!is_callback_request(
+ &get("/callback?code=abc&state=xyz"),
+ "/auth/callback"
+ ));
+}
+
+#[tokio::test]
+async fn bind_dynamic_port_returns_nonzero_port() {
+ let server = bind(None).await.expect("bind should succeed");
+ assert!(server.port > 0, "dynamic port should be nonzero");
+}
+
+#[tokio::test]
+async fn bind_specific_port_returns_that_port() {
+ let probe = TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let free_port = probe.local_addr().unwrap().port();
+ drop(probe);
+
+ let server = bind(Some(free_port)).await.expect("bind should succeed");
+ assert_eq!(server.port, free_port);
+}