From 30358bd15f2af475d3fb125717778a1d5e7ca11e Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:05:10 -0400 Subject: [PATCH 01/13] Implement CannotViewPlugins error and its test --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 wp_networking/tests/test_plugins_err.rs diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 155502995..2a277d321 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -45,6 +45,8 @@ pub enum WPRestErrorCode { CannotEdit, #[serde(rename = "rest_cannot_edit_roles")] CannotEditRoles, + #[serde(rename = "rest_cannot_view_plugins")] + CannotViewPlugins, #[serde(rename = "rest_forbidden_context")] ForbiddenContext, #[serde(rename = "rest_forbidden_orderby")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index b2f9847b8..3a1b5129d 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -131,6 +131,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::CannotCreateUser => 403, WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, + WPRestErrorCode::CannotViewPlugins => 403, WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, WPRestErrorCode::ForbiddenWho => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs new file mode 100644 index 000000000..563b36c6f --- /dev/null +++ b/wp_networking/tests/test_plugins_err.rs @@ -0,0 +1,18 @@ +use wp_api::{WPContext, WPRestErrorCode}; + +use crate::test_helpers::{ + api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, +}; + +pub mod test_helpers; + +#[tokio::test] +async fn list_plugins_err_cannot_view_plugins() { + api_as_subscriber() + .list_plugins_request(WPContext::Edit, &None) + .execute() + .await + .unwrap() + .parse(wp_api::parse_retrieve_plugin_response_with_edit_context) + .assert_wp_error(WPRestErrorCode::CannotViewPlugins); +} From 5a8e41dcf070dcbc0082aac4b0f6fca25532f142 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:15:42 -0400 Subject: [PATCH 02/13] Implement CannotInstallPlugin error and its test --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 2a277d321..42d3d2d00 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -45,6 +45,8 @@ pub enum WPRestErrorCode { CannotEdit, #[serde(rename = "rest_cannot_edit_roles")] CannotEditRoles, + #[serde(rename = "rest_cannot_install_plugin")] + CannotInstallPlugin, #[serde(rename = "rest_cannot_view_plugins")] CannotViewPlugins, #[serde(rename = "rest_forbidden_context")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 3a1b5129d..533abe742 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -131,6 +131,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::CannotCreateUser => 403, WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, + WPRestErrorCode::CannotInstallPlugin => 403, WPRestErrorCode::CannotViewPlugins => 403, WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index 563b36c6f..7fe83d5a1 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -1,7 +1,8 @@ -use wp_api::{WPContext, WPRestErrorCode}; +use wp_api::{PluginCreateParams, PluginStatus, WPContext, WPRestErrorCode}; use crate::test_helpers::{ api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, + WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, }; pub mod test_helpers; @@ -16,3 +17,17 @@ async fn list_plugins_err_cannot_view_plugins() { .parse(wp_api::parse_retrieve_plugin_response_with_edit_context) .assert_wp_error(WPRestErrorCode::CannotViewPlugins); } + +#[tokio::test] +async fn create_plugin_err_cannot_install_plugin() { + api_as_subscriber() + .create_plugin_request(&PluginCreateParams { + slug: WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS.into(), + status: PluginStatus::Active, + }) + .execute() + .await + .unwrap() + .parse(wp_api::parse_create_plugin_response) + .assert_wp_error(WPRestErrorCode::CannotInstallPlugin); +} From e4ba547e78b167c6c06ccb447fe1bc8df168f720 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:23:22 -0400 Subject: [PATCH 03/13] Implement PluginNotFound error and its test --- wp_api/src/api_error.rs | 2 ++ wp_api/src/lib.rs | 2 +- wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 20 ++++++++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 42d3d2d00..b785a73cb 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -57,6 +57,8 @@ pub enum WPRestErrorCode { ForbiddenWho, #[serde(rename = "rest_invalid_param")] InvalidParam, + #[serde(rename = "rest_plugin_not_found")] + PluginNotFound, #[serde(rename = "rest_not_logged_in")] Unauthorized, #[serde(rename = "rest_user_cannot_delete")] diff --git a/wp_api/src/lib.rs b/wp_api/src/lib.rs index 69cbb068d..b95b4da34 100644 --- a/wp_api/src/lib.rs +++ b/wp_api/src/lib.rs @@ -267,7 +267,7 @@ impl WPApiHelper { pub fn update_plugin_request( &self, plugin: &PluginSlug, - params: PluginUpdateParams, + params: &PluginUpdateParams, ) -> WPNetworkRequest { WPNetworkRequest { method: RequestMethod::POST, diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 533abe742..0481ffb25 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -136,6 +136,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, WPRestErrorCode::ForbiddenWho => 403, + WPRestErrorCode::PluginNotFound => 404, WPRestErrorCode::InvalidParam => 400, WPRestErrorCode::TrashNotSupported => 501, WPRestErrorCode::Unauthorized => 401, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index 7fe83d5a1..299ca7e22 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -1,7 +1,7 @@ -use wp_api::{PluginCreateParams, PluginStatus, WPContext, WPRestErrorCode}; +use wp_api::{PluginCreateParams, PluginStatus, PluginUpdateParams, WPContext, WPRestErrorCode}; use crate::test_helpers::{ - api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, + api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, }; @@ -31,3 +31,19 @@ async fn create_plugin_err_cannot_install_plugin() { .parse(wp_api::parse_create_plugin_response) .assert_wp_error(WPRestErrorCode::CannotInstallPlugin); } + +#[tokio::test] +async fn update_plugin_err_plugin_not_found() { + api() + .update_plugin_request( + &"foo".into(), + &PluginUpdateParams { + status: PluginStatus::Active, + }, + ) + .execute() + .await + .unwrap() + .parse(wp_api::parse_update_plugin_response) + .assert_wp_error(WPRestErrorCode::PluginNotFound); +} From 2b48a53bedd8022d8e8d5b11ab63a47dff3c305a Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:27:23 -0400 Subject: [PATCH 04/13] Implement CannotManagePlugins error and its test --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index b785a73cb..4ef9f57bf 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -47,6 +47,8 @@ pub enum WPRestErrorCode { CannotEditRoles, #[serde(rename = "rest_cannot_install_plugin")] CannotInstallPlugin, + #[serde(rename = "rest_cannot_manage_plugins")] + CannotManagePlugins, #[serde(rename = "rest_cannot_view_plugins")] CannotViewPlugins, #[serde(rename = "rest_forbidden_context")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 0481ffb25..cf167991a 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -132,6 +132,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, WPRestErrorCode::CannotInstallPlugin => 403, + WPRestErrorCode::CannotManagePlugins => 403, WPRestErrorCode::CannotViewPlugins => 403, WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index 299ca7e22..bd70162b4 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -2,7 +2,7 @@ use wp_api::{PluginCreateParams, PluginStatus, PluginUpdateParams, WPContext, WP use crate::test_helpers::{ api, api_as_subscriber, AssertWpError, WPNetworkRequestExecutor, WPNetworkResponseParser, - WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, + HELLO_DOLLY_PLUGIN_SLUG, WP_ORG_PLUGIN_SLUG_CLASSIC_WIDGETS, }; pub mod test_helpers; @@ -47,3 +47,19 @@ async fn update_plugin_err_plugin_not_found() { .parse(wp_api::parse_update_plugin_response) .assert_wp_error(WPRestErrorCode::PluginNotFound); } + +#[tokio::test] +async fn update_plugin_err_cannot_manage_plugins() { + api_as_subscriber() + .update_plugin_request( + &HELLO_DOLLY_PLUGIN_SLUG.into(), + &PluginUpdateParams { + status: PluginStatus::Active, + }, + ) + .execute() + .await + .unwrap() + .parse(wp_api::parse_update_plugin_response) + .assert_wp_error(WPRestErrorCode::CannotManagePlugins); +} From 39a13007bc9833d1adfa7f01a99def2f1434ca85 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:33:48 -0400 Subject: [PATCH 05/13] Implement CannotDeleteActivePlugin error and its test --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 4ef9f57bf..e528121cf 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -41,6 +41,8 @@ pub struct UnrecognizedWPRestError { pub enum WPRestErrorCode { #[serde(rename = "rest_cannot_create_user")] CannotCreateUser, + #[serde(rename = "rest_cannot_delete_active_plugin")] + CannotDeleteActivePlugin, #[serde(rename = "rest_cannot_edit")] CannotEdit, #[serde(rename = "rest_cannot_edit_roles")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index cf167991a..6ba850787 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -129,6 +129,7 @@ pub fn read_test_credentials_from_file() -> TestCredentials { fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> u16 { match error_code { WPRestErrorCode::CannotCreateUser => 403, + WPRestErrorCode::CannotDeleteActivePlugin => 400, WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, WPRestErrorCode::CannotInstallPlugin => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index bd70162b4..f1aa2c352 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -63,3 +63,14 @@ async fn update_plugin_err_cannot_manage_plugins() { .parse(wp_api::parse_update_plugin_response) .assert_wp_error(WPRestErrorCode::CannotManagePlugins); } + +#[tokio::test] +async fn delete_plugin_err_cannot_delete_active_plugin() { + api() + .delete_plugin_request(&HELLO_DOLLY_PLUGIN_SLUG.into()) + .execute() + .await + .unwrap() + .parse(wp_api::parse_delete_plugin_response) + .assert_wp_error(WPRestErrorCode::CannotDeleteActivePlugin); +} From 340021b2d808c826fba6cd2b7d5b939360727ad8 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:35:34 -0400 Subject: [PATCH 06/13] Adds CannotManageNetworkPlugins error --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index e528121cf..4e12aec76 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -49,6 +49,8 @@ pub enum WPRestErrorCode { CannotEditRoles, #[serde(rename = "rest_cannot_install_plugin")] CannotInstallPlugin, + #[serde(rename = "rest_cannot_manage_network_plugins")] + CannotManageNetworkPlugins, #[serde(rename = "rest_cannot_manage_plugins")] CannotManagePlugins, #[serde(rename = "rest_cannot_view_plugins")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 6ba850787..2e80c1117 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -133,6 +133,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, WPRestErrorCode::CannotInstallPlugin => 403, + WPRestErrorCode::CannotManageNetworkPlugins => 403, WPRestErrorCode::CannotManagePlugins => 403, WPRestErrorCode::CannotViewPlugins => 403, WPRestErrorCode::ForbiddenContext => 403, From 5db765721f7e0af1193c916e29d5b3b816e8fd8a Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:46:49 -0400 Subject: [PATCH 07/13] Adds CannotActivatePlugin error --- wp_api/src/api_error.rs | 15 +++++++-- wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 44 ++++++++++++------------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 4e12aec76..fb38167db 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -49,8 +49,6 @@ pub enum WPRestErrorCode { CannotEditRoles, #[serde(rename = "rest_cannot_install_plugin")] CannotInstallPlugin, - #[serde(rename = "rest_cannot_manage_network_plugins")] - CannotManageNetworkPlugins, #[serde(rename = "rest_cannot_manage_plugins")] CannotManagePlugins, #[serde(rename = "rest_cannot_view_plugins")] @@ -81,17 +79,30 @@ pub enum WPRestErrorCode { UserInvalidRole, #[serde(rename = "rest_user_invalid_slug")] UserInvalidSlug, + // --- // Tested, but we believe these errors are imppossible to get unless the requests are manually modified + // --- #[serde(rename = "rest_user_exists")] UserExists, #[serde(rename = "rest_user_invalid_argument")] UserInvalidArgument, #[serde(rename = "rest_trash_not_supported")] TrashNotSupported, + // --- // Untested, because we believe these errors require multisite + // --- + #[serde(rename = "rest_cannot_manage_network_plugins")] + CannotManageNetworkPlugins, #[serde(rename = "rest_user_create")] UserCreate, + // --- // Untested, because we believe these errors are impossible to get + // --- + // Happens while activating a plugin without the `activate_plugin` permission. + // However, in a default setup a prior check of `activate_plugins` will fail + // resulting in `CannotManagePlugins` error instead. + #[serde(rename = "rest_cannot_activate_plugin")] + CannotActivatePlugin, #[serde(rename = "rest_user_invalid_username")] UserInvalidUsername, #[serde(rename = "rest_user_invalid_password")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 2e80c1117..2247570cc 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -128,6 +128,7 @@ pub fn read_test_credentials_from_file() -> TestCredentials { fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> u16 { match error_code { + WPRestErrorCode::CannotActivatePlugin => 403, WPRestErrorCode::CannotCreateUser => 403, WPRestErrorCode::CannotDeleteActivePlugin => 400, WPRestErrorCode::CannotEdit => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index f1aa2c352..327cf06c4 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -7,17 +7,6 @@ use crate::test_helpers::{ pub mod test_helpers; -#[tokio::test] -async fn list_plugins_err_cannot_view_plugins() { - api_as_subscriber() - .list_plugins_request(WPContext::Edit, &None) - .execute() - .await - .unwrap() - .parse(wp_api::parse_retrieve_plugin_response_with_edit_context) - .assert_wp_error(WPRestErrorCode::CannotViewPlugins); -} - #[tokio::test] async fn create_plugin_err_cannot_install_plugin() { api_as_subscriber() @@ -32,6 +21,28 @@ async fn create_plugin_err_cannot_install_plugin() { .assert_wp_error(WPRestErrorCode::CannotInstallPlugin); } +#[tokio::test] +async fn delete_plugin_err_cannot_delete_active_plugin() { + api() + .delete_plugin_request(&HELLO_DOLLY_PLUGIN_SLUG.into()) + .execute() + .await + .unwrap() + .parse(wp_api::parse_delete_plugin_response) + .assert_wp_error(WPRestErrorCode::CannotDeleteActivePlugin); +} + +#[tokio::test] +async fn list_plugins_err_cannot_view_plugins() { + api_as_subscriber() + .list_plugins_request(WPContext::Edit, &None) + .execute() + .await + .unwrap() + .parse(wp_api::parse_retrieve_plugin_response_with_edit_context) + .assert_wp_error(WPRestErrorCode::CannotViewPlugins); +} + #[tokio::test] async fn update_plugin_err_plugin_not_found() { api() @@ -63,14 +74,3 @@ async fn update_plugin_err_cannot_manage_plugins() { .parse(wp_api::parse_update_plugin_response) .assert_wp_error(WPRestErrorCode::CannotManagePlugins); } - -#[tokio::test] -async fn delete_plugin_err_cannot_delete_active_plugin() { - api() - .delete_plugin_request(&HELLO_DOLLY_PLUGIN_SLUG.into()) - .execute() - .await - .unwrap() - .parse(wp_api::parse_delete_plugin_response) - .assert_wp_error(WPRestErrorCode::CannotDeleteActivePlugin); -} From 374663102820072f60b782804f16801f98bc914d Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:51:29 -0400 Subject: [PATCH 08/13] Adds CannotDeactivatePlugin error --- wp_api/src/api_error.rs | 11 ++++++++--- wp_networking/tests/test_helpers.rs | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index fb38167db..8ebbc4bd7 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -98,11 +98,16 @@ pub enum WPRestErrorCode { // --- // Untested, because we believe these errors are impossible to get // --- - // Happens while activating a plugin without the `activate_plugin` permission. - // However, in a default setup a prior check of `activate_plugins` will fail - // resulting in `CannotManagePlugins` error instead. + /// Happens while activating a plugin without the `activate_plugin` permission. + /// However, in a default setup a prior check of `activate_plugins` will fail + /// resulting in `CannotManagePlugins` error instead. #[serde(rename = "rest_cannot_activate_plugin")] CannotActivatePlugin, + /// Happens while deactivating a plugin without the `deactivate_plugin` permission. + /// However, in a default setup a prior check of `activate_plugins` will fail + /// resulting in `CannotManagePlugins` error instead. + #[serde(rename = "rest_cannot_deactivate_plugin")] + CannotDeactivatePlugin, #[serde(rename = "rest_user_invalid_username")] UserInvalidUsername, #[serde(rename = "rest_user_invalid_password")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 2247570cc..2d5893756 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -130,6 +130,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> match error_code { WPRestErrorCode::CannotActivatePlugin => 403, WPRestErrorCode::CannotCreateUser => 403, + WPRestErrorCode::CannotDeactivatePlugin => 403, WPRestErrorCode::CannotDeleteActivePlugin => 400, WPRestErrorCode::CannotEdit => 403, WPRestErrorCode::CannotEditRoles => 403, From 09622cddef72ae883fd8b9cf3054a8320716db9a Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:54:01 -0400 Subject: [PATCH 09/13] Implement CannotViewPlugin error and its test --- wp_api/src/api_error.rs | 2 ++ wp_networking/tests/test_helpers.rs | 1 + wp_networking/tests/test_plugins_err.rs | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 8ebbc4bd7..5aba647b1 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -51,6 +51,8 @@ pub enum WPRestErrorCode { CannotInstallPlugin, #[serde(rename = "rest_cannot_manage_plugins")] CannotManagePlugins, + #[serde(rename = "rest_cannot_view_plugin")] + CannotViewPlugin, #[serde(rename = "rest_cannot_view_plugins")] CannotViewPlugins, #[serde(rename = "rest_forbidden_context")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 2d5893756..9ce0d3376 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -137,6 +137,7 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::CannotInstallPlugin => 403, WPRestErrorCode::CannotManageNetworkPlugins => 403, WPRestErrorCode::CannotManagePlugins => 403, + WPRestErrorCode::CannotViewPlugin => 403, WPRestErrorCode::CannotViewPlugins => 403, WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, diff --git a/wp_networking/tests/test_plugins_err.rs b/wp_networking/tests/test_plugins_err.rs index 327cf06c4..6d6a6a31b 100644 --- a/wp_networking/tests/test_plugins_err.rs +++ b/wp_networking/tests/test_plugins_err.rs @@ -43,6 +43,17 @@ async fn list_plugins_err_cannot_view_plugins() { .assert_wp_error(WPRestErrorCode::CannotViewPlugins); } +#[tokio::test] +async fn retrieve_plugin_err_cannot_view_plugin() { + api_as_subscriber() + .retrieve_plugin_request(WPContext::Edit, &HELLO_DOLLY_PLUGIN_SLUG.into()) + .execute() + .await + .unwrap() + .parse(wp_api::parse_retrieve_plugin_response_with_edit_context) + .assert_wp_error(WPRestErrorCode::CannotViewPlugin); +} + #[tokio::test] async fn update_plugin_err_plugin_not_found() { api() From 02ba7a1a7810b48d3462de84e4d9e52887cf0d73 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 11:58:01 -0400 Subject: [PATCH 10/13] Adds UnableToConnectToFilesystem & UnableToDetermineInstalledPlugin errors --- wp_api/src/api_error.rs | 7 +++++++ wp_networking/tests/test_helpers.rs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 5aba647b1..efb74c881 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -91,6 +91,13 @@ pub enum WPRestErrorCode { #[serde(rename = "rest_trash_not_supported")] TrashNotSupported, // --- + // Untested, because we don't have the necessary setup for it + // --- + #[serde(rename = "unable_to_connect_to_filesystem")] + UnableToConnectToFilesystem, + #[serde(rename = "unable_to_determine_installed_plugin")] + UnableToDetermineInstalledPlugin, + // --- // Untested, because we believe these errors require multisite // --- #[serde(rename = "rest_cannot_manage_network_plugins")] diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 9ce0d3376..da4e47ca7 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -145,6 +145,8 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::PluginNotFound => 404, WPRestErrorCode::InvalidParam => 400, WPRestErrorCode::TrashNotSupported => 501, + WPRestErrorCode::UnableToConnectToFilesystem => 500, + WPRestErrorCode::UnableToDetermineInstalledPlugin => 500, WPRestErrorCode::Unauthorized => 401, WPRestErrorCode::UserCannotDelete => 403, WPRestErrorCode::UserCannotView => 403, From 234658ec17d0fcac33d7ff210ecffad2dd5ef1e2 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 12:09:51 -0400 Subject: [PATCH 11/13] Adds FsUnavailable & NetworkOnlyPlugin errors --- wp_api/src/api_error.rs | 4 ++++ wp_networking/tests/test_helpers.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index efb74c881..121136df4 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -93,6 +93,8 @@ pub enum WPRestErrorCode { // --- // Untested, because we don't have the necessary setup for it // --- + #[serde(rename = "fs_unavailable")] + FsUnavailable, #[serde(rename = "unable_to_connect_to_filesystem")] UnableToConnectToFilesystem, #[serde(rename = "unable_to_determine_installed_plugin")] @@ -102,6 +104,8 @@ pub enum WPRestErrorCode { // --- #[serde(rename = "rest_cannot_manage_network_plugins")] CannotManageNetworkPlugins, + #[serde(rename = "rest_network_only_plugin")] + NetworkOnlyPlugin, #[serde(rename = "rest_user_create")] UserCreate, // --- diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index da4e47ca7..1373ac4d9 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -142,6 +142,8 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, WPRestErrorCode::ForbiddenWho => 403, + WPRestErrorCode::FsUnavailable => 500, + WPRestErrorCode::NetworkOnlyPlugin => 400, WPRestErrorCode::PluginNotFound => 404, WPRestErrorCode::InvalidParam => 400, WPRestErrorCode::TrashNotSupported => 501, From b8f85d1815f8d2fe2d3e851a78aedcf1bd1c88bf Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 12:23:45 -0400 Subject: [PATCH 12/13] Adds WPInternalErrorCode --- wp_api/src/api_error.rs | 52 ++++++++++++++++++++++++----- wp_networking/tests/test_helpers.rs | 3 -- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/wp_api/src/api_error.rs b/wp_api/src/api_error.rs index 121136df4..7acfa259b 100644 --- a/wp_api/src/api_error.rs +++ b/wp_api/src/api_error.rs @@ -91,15 +91,6 @@ pub enum WPRestErrorCode { #[serde(rename = "rest_trash_not_supported")] TrashNotSupported, // --- - // Untested, because we don't have the necessary setup for it - // --- - #[serde(rename = "fs_unavailable")] - FsUnavailable, - #[serde(rename = "unable_to_connect_to_filesystem")] - UnableToConnectToFilesystem, - #[serde(rename = "unable_to_determine_installed_plugin")] - UnableToDetermineInstalledPlugin, - // --- // Untested, because we believe these errors require multisite // --- #[serde(rename = "rest_cannot_manage_network_plugins")] @@ -126,3 +117,46 @@ pub enum WPRestErrorCode { #[serde(rename = "rest_user_invalid_password")] UserInvalidPassword, } + +// All internal errors _should_ be wrapped as a `WPRestErrorCode` by the server. However, there +// is a good chance that some internal errors do make it into the response, so these error types +// are provided. +// +// Currently, we don't parse the response for these error types, but we could consider adding it +// as a fallback. For the moment, clients can manually try parsing an `Unrecognized` error +// into this type. +#[derive(Debug, Deserialize, PartialEq, Eq, uniffi::Error)] +pub enum WPInternalErrorCode { + #[serde(rename = "fs_error")] + FsError, + #[serde(rename = "fs_no_plugins_dir")] + FsNoPluginsDir, + #[serde(rename = "fs_unavailable")] + FsUnavailable, + #[serde(rename = "could_not_remove_plugin")] + CouldNotRemovePlugin, + #[serde(rename = "could_not_resume_plugin")] + CouldNotResumePlugin, + #[serde(rename = "no_plugin_header")] + NoPluginHeader, + #[serde(rename = "plugin_missing_dependencies")] + PluginMissingDependencies, + #[serde(rename = "plugin_not_found")] + PluginNotFound, + #[serde(rename = "plugin_invalid")] + PluginInvalid, + #[serde(rename = "plugin_php_incompatible")] + PluginPhpIncompatible, + #[serde(rename = "plugin_wp_incompatible")] + PluginWpIncompatible, + #[serde(rename = "plugin_wp_php_incompatible")] + PluginWpPhpIncompatible, + #[serde(rename = "plugins_invalid")] + PluginsInvalid, + #[serde(rename = "unable_to_connect_to_filesystem")] + UnableToConnectToFilesystem, + #[serde(rename = "unable_to_determine_installed_plugin")] + UnableToDetermineInstalledPlugin, + #[serde(rename = "unexpected_output")] + UnexpectedOutput, +} diff --git a/wp_networking/tests/test_helpers.rs b/wp_networking/tests/test_helpers.rs index 1373ac4d9..ea5bd5aed 100644 --- a/wp_networking/tests/test_helpers.rs +++ b/wp_networking/tests/test_helpers.rs @@ -142,13 +142,10 @@ fn expected_status_code_for_wp_rest_error_code(error_code: &WPRestErrorCode) -> WPRestErrorCode::ForbiddenContext => 403, WPRestErrorCode::ForbiddenOrderBy => 403, WPRestErrorCode::ForbiddenWho => 403, - WPRestErrorCode::FsUnavailable => 500, WPRestErrorCode::NetworkOnlyPlugin => 400, WPRestErrorCode::PluginNotFound => 404, WPRestErrorCode::InvalidParam => 400, WPRestErrorCode::TrashNotSupported => 501, - WPRestErrorCode::UnableToConnectToFilesystem => 500, - WPRestErrorCode::UnableToDetermineInstalledPlugin => 500, WPRestErrorCode::Unauthorized => 401, WPRestErrorCode::UserCannotDelete => 403, WPRestErrorCode::UserCannotView => 403, From 411647d62f68405530c23dc3ed9e629ee8915e3b Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Tue, 21 May 2024 13:22:08 -0400 Subject: [PATCH 13/13] Fix missing & in PluginUpdateParams in test_plugins_mut --- wp_networking/tests/test_plugins_mut.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp_networking/tests/test_plugins_mut.rs b/wp_networking/tests/test_plugins_mut.rs index cc4b571e6..690f2f3a2 100644 --- a/wp_networking/tests/test_plugins_mut.rs +++ b/wp_networking/tests/test_plugins_mut.rs @@ -38,7 +38,7 @@ async fn update_plugin() { let updated_plugin = api() .update_plugin_request( &HELLO_DOLLY_PLUGIN_SLUG.into(), - PluginUpdateParams { status }, + &PluginUpdateParams { status }, ) .execute() .await