diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/zotapi.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/tests/zotapi.rs b/tests/zotapi.rs index 38bdf8a..4bac884 100644 --- a/tests/zotapi.rs +++ b/tests/zotapi.rs @@ -19,9 +19,14 @@ extern crate mockito; use mockito::{mock, Matcher, Mock}; -fn default_mock(method: &str, url: &str) -> Mock { +fn mock_with_authorization(method: &str, url: &str) -> Mock { mock(method, url) - .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) + .match_header("Authorization", + Matcher::Exact(format!("Basic {}", base64::encode("testuser:test1234")))) +} + +fn default_mock(method: &str, url: &str) -> Mock { + mock_with_authorization(method, url) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") @@ -64,8 +69,7 @@ fn return_error_if_invalid_auth_provided() { #[test] fn create_new_post() { - let m = mock("POST", "/api/z/1.0/item/update") - .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) + let m = mock_with_authorization("POST", "/api/z/1.0/item/update") .match_body("body=This+is+a+test") .with_status(200) .with_header("content-type", "application/json") @@ -79,8 +83,7 @@ fn create_new_post() { #[test] fn create_new_post_with_title() { - let m = mock("POST", "/api/z/1.0/item/update") - .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) + let m = mock_with_authorization("POST", "/api/z/1.0/item/update") .match_body( Matcher::AllOf(vec![ Matcher::UrlEncoded("title".to_string(), "A+title".to_string()), @@ -99,8 +102,7 @@ fn create_new_post_with_title() { #[test] fn upload_item_with_media_file() { - let m = mock("POST", "/api/z/1.0/item/update") - .match_header("authorization", Matcher::Regex(r"Basic \w+=".into())) + let m = mock_with_authorization("POST", "/api/z/1.0/item/update") .match_header("content-type", Matcher::Regex("^multipart/form-data; boundary=.+$".into())) .match_body(Matcher::Regex( "--.+\r\n".to_owned() + @@ -130,9 +132,8 @@ fn upload_item_with_media_file() { #[test] fn upload_item_with_two_files() { - let m = mock("POST", "/api/z/1.0/item/update") - .match_header("authorization", Matcher::Regex(r"Basic \w+=".into())) - .match_header("content-type", Matcher::Regex("^multipart/form-data; boundary=.+$".into())) + let m = mock_with_authorization("POST", "/api/z/1.0/item/update") + .match_header("content-type", Matcher::Regex("multipart/form-data; boundary=.+".into())) .match_body(Matcher::Regex( "--.+\r\n".to_owned() + "Content-Disposition: form-data; name=\"body\"\r\n" + @@ -208,9 +209,8 @@ fn fetch_privacy_groups() { #[test] fn fetch_members_of_group_by_group_id() { - let m = mock("GET", "/api/z/1.0/group_members") + let m = mock_with_authorization("GET", "/api/z/1.0/group_members") .match_query(Matcher::UrlEncoded("group_id".to_string(), "42".to_string())) - .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") @@ -222,9 +222,8 @@ fn fetch_members_of_group_by_group_id() { #[test] fn fetch_members_of_group_by_group_name() { - let m = mock("GET", "/api/z/1.0/group_members") + let m = mock_with_authorization("GET", "/api/z/1.0/group_members") .match_query(Matcher::UrlEncoded("group_name".into(), "Friends+of+pain".into())) - .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") |