diff --git a/Cargo.lock b/Cargo.lock index 2664abe7..42745f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aho-corasick" version = "1.1.3" @@ -26,6 +32,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -137,6 +158,22 @@ dependencies = [ "nom", ] +[[package]] +name = "async-compression" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c90a406b4495d129f00461241616194cb8a032c8d1c53c657f0961d5f8e0498" +dependencies = [ + "brotli", + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", + "zstd", + "zstd-safe", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -207,7 +244,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.4", "object", "rustc-demangle", ] @@ -248,6 +285,27 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "brotli" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -303,6 +361,10 @@ name = "cc" version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +dependencies = [ + "jobserver", + "libc", +] [[package]] name = "cfg-if" @@ -406,6 +468,15 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "deranged" version = "0.3.11" @@ -516,6 +587,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "flate2" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.0", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1132,6 +1213,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -1242,6 +1332,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" version = "1.0.1" @@ -1680,6 +1779,7 @@ version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ + "async-compression", "base64", "bytes", "encoding_rs", @@ -3431,3 +3531,31 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zstd" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.11+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75652c55c0b6f3e6f12eb786fe1bc960396bf05a1eb3bf1f3691c3610ac2e6d4" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/wp_api/src/login.rs b/wp_api/src/login.rs index 56dcba55..93a24731 100644 --- a/wp_api/src/login.rs +++ b/wp_api/src/login.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use wp_serde_helper::deserialize_i64_or_string; pub use login_client::WpLoginClient; -pub use url_discovery::{UrlDiscoveryState, UrlDiscoverySuccess}; +pub use url_discovery::{UrlDiscoveryError, UrlDiscoveryState, UrlDiscoverySuccess}; use crate::ParsedUrl; use crate::WpUuid; diff --git a/wp_api/src/login/url_discovery.rs b/wp_api/src/login/url_discovery.rs index a14d84d7..da931256 100644 --- a/wp_api/src/login/url_discovery.rs +++ b/wp_api/src/login/url_discovery.rs @@ -9,6 +9,35 @@ use super::WpApiDetails; const API_ROOT_LINK_HEADER: &str = "https://api.w.org/"; +#[uniffi::export] +fn new_api_discovery(site_url: String) -> NewUrlDiscoveryResult { + todo!() +} + +#[derive(Debug, uniffi::Record)] +pub struct NewUrlDiscoveryResult { + pub user_input_attempt: NewUrlDiscoveryAttemptResult, + pub other_successful_attempts: Vec, + pub other_failed_attempts: Vec, +} + +#[derive(Debug, uniffi::Record)] +pub struct NewUrlDiscoveryAttemptResult { + pub is_network_error: bool, + pub is_successful: bool, + pub is_the_site_url_same_as_the_user_input: bool, + pub is_failed_to_parse_site_url: bool, + pub is_failed_to_parsed_api_root: bool, + pub is_failed_to_parsed_api_details: bool, + pub has_found_api_root_url: bool, + pub input_url: String, + pub parsed_site_url: Option>, + pub api_root_url: Option>, + pub api_details: Option>, + // TODO: Not sure about the type for this + pub errors: u32, +} + pub fn construct_attempts(input_site_url: String) -> Vec { let mut attempts = vec![input_site_url.clone()]; if !input_site_url.starts_with("http") { diff --git a/wp_api_integration_tests/Cargo.toml b/wp_api_integration_tests/Cargo.toml index d5b02c59..8984f3fc 100644 --- a/wp_api_integration_tests/Cargo.toml +++ b/wp_api_integration_tests/Cargo.toml @@ -13,7 +13,7 @@ async-trait = { workspace = true } clap = { workspace = true, features = ["derive"] } futures = { workspace = true } http = { workspace = true } -reqwest = { workspace = true, features = [ "multipart", "json", "stream" ] } +reqwest = { workspace = true, features = [ "multipart", "json", "stream", "gzip", "brotli", "zstd", "deflate" ] } serde = { workspace = true, features = [ "derive" ] } serde_json = { workspace = true } tokio = { workspace = true, features = [ "full" ] } diff --git a/wp_api_integration_tests/tests/test_login_err.rs b/wp_api_integration_tests/tests/test_login_err.rs new file mode 100644 index 00000000..5880e939 --- /dev/null +++ b/wp_api_integration_tests/tests/test_login_err.rs @@ -0,0 +1,18 @@ +use rstest::rstest; +use serial_test::parallel; +use std::sync::Arc; +use wp_api::login::{UrlDiscoveryError, WpLoginClient}; +use wp_api_integration_tests::AsyncWpNetworking; + +#[rstest] +#[case("http://optional-https.wpmt.co")] // Fails because it's `http` +#[tokio::test] +#[parallel] +async fn test_login_flow_err_url_discovery_failed(#[case] site_url: &str) { + let client = WpLoginClient::new(Arc::new(AsyncWpNetworking::default())); + let err = client + .api_discovery(site_url.to_string()) + .await + .unwrap_err(); + assert!(matches!(err, UrlDiscoveryError::UrlDiscoveryFailed { .. })); +} diff --git a/wp_api_integration_tests/tests/test_login_immut.rs b/wp_api_integration_tests/tests/test_login_immut.rs index 303c8556..dcdc248e 100644 --- a/wp_api_integration_tests/tests/test_login_immut.rs +++ b/wp_api_integration_tests/tests/test_login_immut.rs @@ -7,6 +7,7 @@ use wp_api_integration_tests::{AssertResponse, AsyncWpNetworking}; const LOCALHOST_AUTH_URL: &str = "http://localhost/wp-admin/authorize-application.php"; const AUTOMATTIC_WIDGETS_AUTH_URL: &str = "https://automatticwidgets.wpcomstaging.com/wp-admin/authorize-application.php"; +const VANILLA_WP_SITE_URL: &str = "https://vanilla.wpmt.co/wp-admin/authorize-application.php"; #[rstest] #[case("http://localhost", LOCALHOST_AUTH_URL)] @@ -35,6 +36,20 @@ const AUTOMATTIC_WIDGETS_AUTH_URL: &str = AUTOMATTIC_WIDGETS_AUTH_URL )] #[case("automatticwidgets.wpcomstaging.com/ ", AUTOMATTIC_WIDGETS_AUTH_URL)] +#[case("vanilla.wpmt.co", VANILLA_WP_SITE_URL)] +#[case("http://vanilla.wpmt.co", VANILLA_WP_SITE_URL)] +#[case( + "https://optional-https.wpmt.co", + "https://optional-https.wpmt.co/wp-admin/authorize-application.php" +)] +#[case( + "https://わぷー.wpmt.co", + "https://xn--39j4bws.wpmt.co/wp-admin/authorize-application.php" +)] +#[case( + "https://jetpack.wpmt.co", + "https://jetpack.wpmt.co/wp-admin/authorize-application.php" +)] #[tokio::test] #[parallel] async fn test_login_flow(#[case] site_url: &str, #[case] expected_auth_url: &str) {