已合并
add native tests for request_next verify module #1820
SnakyHY创建于 3月11日
add native tests for request_next verify module #1820
已合并
共 9 个文件变更+1822-0
| @@ -0,0 +1,200 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{Action, TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_core::file::FileSpec; | ||
| 16 | +use request_client::verify::{file_spec::FileSpecVerifier, method::MethodVerifier, ConfigVerifier}; | ||
| 17 | + | ||
| 18 | +fn create_download_config() -> TaskConfig { | ||
| 19 | + TaskConfigBuilder::new(Version::API10) | ||
| 20 | + .url("https://example.com/test".to_string()) | ||
| 21 | + .action(Action::Download) | ||
| 22 | + .build() | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +fn create_upload_config_with_files(file_count: usize) -> TaskConfig { | ||
| 26 | + let files: Vec<FileSpec> = (0..file_count) | ||
| 27 | + .map(|i| FileSpec { | ||
| 28 | + name: format!("file_{}", i), | ||
| 29 | + path: format!("/tmp/file_{}", i), | ||
| 30 | + file_name: format!("file_{}", i), | ||
| 31 | + mime_type: "application/octet-stream".to_string(), | ||
| 32 | + is_user_file: false, | ||
| 33 | + fd: None, | ||
| 34 | + }) | ||
| 35 | + .collect(); | ||
| 36 | + TaskConfigBuilder::new(Version::API10) | ||
| 37 | + .url("https://example.com/upload".to_string()) | ||
| 38 | + .action(Action::Upload) | ||
| 39 | + .files(files) | ||
| 40 | + .build() | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// @tc.name: ut_file_spec_verifier_download_success | ||
| 44 | +// @tc.desc: Test FileSpecVerifier with download action | ||
| 45 | +// @tc.precon: NA | ||
| 46 | +// @tc.step: 1. Create FileSpecVerifier | ||
| 47 | +// 2. Create TaskConfig with download action | ||
| 48 | +// 3. Verify config passes validation | ||
| 49 | +// @tc.expect: Verification passes for download action | ||
| 50 | +// @tc.type: FUNC | ||
| 51 | +// @tc.require: issueNumber | ||
| 52 | + | ||
| 53 | +fn ut_file_spec_verifier_download_success() { | ||
| 54 | + let verifier = FileSpecVerifier {}; | ||
| 55 | + let config = create_download_config(); | ||
| 56 | + assert!(verifier.verify(&config).is_ok()); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// @tc.name: ut_file_spec_verifier_upload_with_files | ||
| 60 | +// @tc.desc: Test FileSpecVerifier with upload action and files | ||
| 61 | +// @tc.precon: NA | ||
| 62 | +// @tc.step: 1. Create FileSpecVerifier | ||
| 63 | +// 2. Create TaskConfig with upload action and 1 file | ||
| 64 | +// 3. Verify config passes validation | ||
| 65 | +// @tc.expect: Verification passes for upload with files | ||
| 66 | +// @tc.type: FUNC | ||
| 67 | +// @tc.require: issueNumber | ||
| 68 | + | ||
| 69 | +fn ut_file_spec_verifier_upload_with_files() { | ||
| 70 | + let verifier = FileSpecVerifier {}; | ||
| 71 | + let config = create_upload_config_with_files(1); | ||
| 72 | + assert!(verifier.verify(&config).is_ok()); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +// @tc.name: ut_file_spec_verifier_upload_without_files | ||
| 76 | +// @tc.desc: Test FileSpecVerifier with upload action but no files | ||
| 77 | +// @tc.precon: NA | ||
| 78 | +// @tc.step: 1. Create FileSpecVerifier | ||
| 79 | +// 2. Create TaskConfig with upload action but no files | ||
| 80 | +// 3. Verify config fails validation | ||
| 81 | +// @tc.expect: Verification fails with error code 401 | ||
| 82 | +// @tc.type: FUNC | ||
| 83 | +// @tc.require: issueNumber | ||
| 84 | + | ||
| 85 | +fn ut_file_spec_verifier_upload_without_files() { | ||
| 86 | + let verifier = FileSpecVerifier {}; | ||
| 87 | + let config = TaskConfigBuilder::new(Version::API10) | ||
| 88 | + .url("https://example.com/upload".to_string()) | ||
| 89 | + .action(Action::Upload) | ||
| 90 | + .build(); | ||
| 91 | + let result = verifier.verify(&config); | ||
| 92 | + assert!(result.is_err()); | ||
| 93 | + assert_eq!(result.unwrap_err(), 401); | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +// @tc.name: ut_method_verifier_download_get | ||
| 97 | +// @tc.desc: Test MethodVerifier with download action and GET method | ||
| 98 | +// @tc.precon: NA | ||
| 99 | +// @tc.step: 1. Create MethodVerifier | ||
| 100 | +// 2. Create TaskConfig with download action and GET method | ||
| 101 | +// 3. Verify config passes validation | ||
| 102 | +// @tc.expect: Verification passes for download with GET | ||
| 103 | +// @tc.type: FUNC | ||
| 104 | +// @tc.require: issueNumber | ||
| 105 | + | ||
| 106 | +fn ut_method_verifier_download_get() { | ||
| 107 | + let verifier = MethodVerifier {}; | ||
| 108 | + let mut config = create_download_config(); | ||
| 109 | + config.method = "GET".to_string(); | ||
| 110 | + assert!(verifier.verify(&config).is_ok()); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +// @tc.name: ut_method_verifier_download_post | ||
| 114 | +// @tc.desc: Test MethodVerifier with download action and POST method | ||
| 115 | +// @tc.precon: NA | ||
| 116 | +// @tc.step: 1. Create MethodVerifier | ||
| 117 | +// 2. Create TaskConfig with download action and POST method | ||
| 118 | +// 3. Verify config passes validation | ||
| 119 | +// @tc.expect: Verification passes for download with POST | ||
| 120 | +// @tc.type: FUNC | ||
| 121 | +// @tc.require: issueNumber | ||
| 122 | + | ||
| 123 | +fn ut_method_verifier_download_post() { | ||
| 124 | + let verifier = MethodVerifier {}; | ||
| 125 | + let mut config = create_download_config(); | ||
| 126 | + config.method = "POST".to_string(); | ||
| 127 | + assert!(verifier.verify(&config).is_ok()); | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +// @tc.name: ut_method_verifier_download_invalid_method | ||
| 131 | +// @tc.desc: Test MethodVerifier with download action and invalid method | ||
| 132 | +// @tc.precon: NA | ||
| 133 | +// @tc.step: 1. Create MethodVerifier | ||
| 134 | +// 2. Create TaskConfig with download action and PUT method | ||
| 135 | +// 3. Verify config fails validation | ||
| 136 | +// @tc.expect: Verification fails with error code 401 | ||
| 137 | +// @tc.type: FUNC | ||
| 138 | +// @tc.require: issueNumber | ||
| 139 | + | ||
| 140 | +fn ut_method_verifier_download_invalid_method() { | ||
| 141 | + let verifier = MethodVerifier {}; | ||
| 142 | + let mut config = create_download_config(); | ||
| 143 | + config.method = "PUT".to_string(); | ||
| 144 | + let result = verifier.verify(&config); | ||
| 145 | + assert!(result.is_err()); | ||
| 146 | + assert_eq!(result.unwrap_err(), 401); | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +// @tc.name: ut_method_verifier_upload_put | ||
| 150 | +// @tc.desc: Test MethodVerifier with upload action and PUT method | ||
| 151 | +// @tc.precon: NA | ||
| 152 | +// @tc.step: 1. Create MethodVerifier | ||
| 153 | +// 2. Create TaskConfig with upload action and PUT method | ||
| 154 | +// 3. Verify config passes validation | ||
| 155 | +// @tc.expect: Verification passes for upload with PUT | ||
| 156 | +// @tc.type: FUNC | ||
| 157 | +// @tc.require: issueNumber | ||
| 158 | + | ||
| 159 | +fn ut_method_verifier_upload_put() { | ||
| 160 | + let verifier = MethodVerifier {}; | ||
| 161 | + let mut config = create_upload_config_with_files(1); | ||
| 162 | + config.method = "PUT".to_string(); | ||
| 163 | + assert!(verifier.verify(&config).is_ok()); | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +// @tc.name: ut_method_verifier_upload_post | ||
| 167 | +// @tc.desc: Test MethodVerifier with upload action and POST method | ||
| 168 | +// @tc.precon: NA | ||
| 169 | +// @tc.step: 1. Create MethodVerifier | ||
| 170 | +// 2. Create TaskConfig with upload action and POST method | ||
| 171 | +// 3. Verify config passes validation | ||
| 172 | +// @tc.expect: Verification passes for upload with POST | ||
| 173 | +// @tc.type: FUNC | ||
| 174 | +// @tc.require: issueNumber | ||
| 175 | + | ||
| 176 | +fn ut_method_verifier_upload_post() { | ||
| 177 | + let verifier = MethodVerifier {}; | ||
| 178 | + let mut config = create_upload_config_with_files(1); | ||
| 179 | + config.method = "POST".to_string(); | ||
| 180 | + assert!(verifier.verify(&config).is_ok()); | ||
| 181 | +} | ||
| 182 | + | ||
| 183 | +// @tc.name: ut_method_verifier_upload_invalid_method | ||
| 184 | +// @tc.desc: Test MethodVerifier with upload action and invalid method | ||
| 185 | +// @tc.precon: NA | ||
| 186 | +// @tc.step: 1. Create MethodVerifier | ||
| 187 | +// 2. Create TaskConfig with upload action and GET method | ||
| 188 | +// 3. Verify config fails validation | ||
| 189 | +// @tc.expect: Verification fails with error code 401 | ||
| 190 | +// @tc.type: FUNC | ||
| 191 | +// @tc.require: issueNumber | ||
| 192 | + | ||
| 193 | +fn ut_method_verifier_upload_invalid_method() { | ||
| 194 | + let verifier = MethodVerifier {}; | ||
| 195 | + let mut config = create_upload_config_with_files(1); | ||
| 196 | + config.method = "GET".to_string(); | ||
| 197 | + let result = verifier.verify(&config); | ||
| 198 | + assert!(result.is_err()); | ||
| 199 | + assert_eq!(result.unwrap_err(), 401); | ||
| 200 | +} | ||
| @@ -0,0 +1,217 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{Action, FormItem, TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::{form_item::FormItemVerifier, token::TokenVerifier, data::DataVerifier, ConfigVerifier}; | ||
| 16 | + | ||
| 17 | +// ==================== FormItemVerifier Tests ==================== | ||
| 18 | + | ||
| 19 | +fn create_config_with_form_items(version: Version, action: Action, form_items: Vec<FormItem>) -> TaskConfig { | ||
| 20 | + TaskConfigBuilder::new(version) | ||
| 21 | + .url("https://example.com/test".to_string()) | ||
| 22 | + .action(action) | ||
| 23 | + .data(form_items) | ||
| 24 | + .build() | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +// @tc.name: ut_form_item_verifier_api9_upload_with_items | ||
| 28 | +// @tc.desc: Test FormItemVerifier with API9 upload and form items | ||
| 29 | +// @tc.precon: NA | ||
| 30 | +// @tc.step: 1. Create FormItemVerifier | ||
| 31 | +// 2. Create TaskConfig with API9 upload action and form items | ||
| 32 | +// 3. Verify config passes validation | ||
| 33 | +// @tc.expect: Verification passes for API9 upload with form items | ||
| 34 | +// @tc.type: FUNC | ||
| 35 | +// @tc.require: issueNumber | ||
| 36 | + | ||
| 37 | +fn ut_form_item_verifier_api9_upload_with_items() { | ||
| 38 | + let verifier = FormItemVerifier {}; | ||
| 39 | + let form_items = vec![FormItem { name: "field1".to_string(), value: "value1".to_string() }]; | ||
| 40 | + let config = create_config_with_form_items(Version::API9, Action::Upload, form_items); | ||
| 41 | + assert!(verifier.verify(&config).is_ok()); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// @tc.name: ut_form_item_verifier_api9_upload_empty_items | ||
| 45 | +// @tc.desc: Test FormItemVerifier with API9 upload and empty form items | ||
| 46 | +// @tc.precon: NA | ||
| 47 | +// @tc.step: 1. Create FormItemVerifier | ||
| 48 | +// 2. Create TaskConfig with API9 upload action and empty form items | ||
| 49 | +// 3. Verify config fails validation | ||
| 50 | +// @tc.expect: Verification fails with error code 401 | ||
| 51 | +// @tc.type: FUNC | ||
| 52 | +// @tc.require: issueNumber | ||
| 53 | + | ||
| 54 | +fn ut_form_item_verifier_api9_upload_empty_items() { | ||
| 55 | + let verifier = FormItemVerifier {}; | ||
| 56 | + let config = create_config_with_form_items(Version::API9, Action::Upload, vec![]); | ||
| 57 | + let result = verifier.verify(&config); | ||
| 58 | + assert!(result.is_err()); | ||
| 59 | + assert_eq!(result.unwrap_err(), 401); | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +// @tc.name: ut_form_item_verifier_api10_upload_with_items | ||
| 63 | +// @tc.desc: Test FormItemVerifier with API10 upload and form items | ||
| 64 | +// @tc.precon: NA | ||
| 65 | +// @tc.step: 1. Create FormItemVerifier | ||
| 66 | +// 2. Create TaskConfig with API10 upload action and form items | ||
| 67 | +// 3. Verify config passes validation | ||
| 68 | +// @tc.expect: Verification passes for API10 upload with form items | ||
| 69 | +// @tc.type: FUNC | ||
| 70 | +// @tc.require: issueNumber | ||
| 71 | + | ||
| 72 | +fn ut_form_item_verifier_api10_upload_with_items() { | ||
| 73 | + let verifier = FormItemVerifier {}; | ||
| 74 | + let form_items = vec![FormItem { name: "field1".to_string(), value: "value1".to_string() }]; | ||
| 75 | + let config = create_config_with_form_items(Version::API10, Action::Upload, form_items); | ||
| 76 | + assert!(verifier.verify(&config).is_ok()); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +// ==================== TokenVerifier Tests ==================== | ||
| 80 | + | ||
| 81 | +fn create_config_with_token(version: Version, token: &str) -> TaskConfig { | ||
| 82 | + let mut config = TaskConfigBuilder::new(version) | ||
| 83 | + .url("https://example.com/test".to_string()) | ||
| 84 | + .build(); | ||
| 85 | + config.token = token.to_string(); | ||
| 86 | + config | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +// @tc.name: ut_token_verifier_api9_any_token | ||
| 90 | +// @tc.desc: Test TokenVerifier with API9 version ignores token validation | ||
| 91 | +// @tc.precon: NA | ||
| 92 | +// @tc.step: 1. Create TokenVerifier | ||
| 93 | +// 2. Create TaskConfig with API9 version and short token | ||
| 94 | +// 3. Verify config passes validation | ||
| 95 | +// @tc.expect: Verification passes for API9 with any token | ||
| 96 | +// @tc.type: FUNC | ||
| 97 | +// @tc.require: issueNumber | ||
| 98 | + | ||
| 99 | +fn ut_token_verifier_api9_any_token() { | ||
| 100 | + let verifier = TokenVerifier {}; | ||
| 101 | + let config = create_config_with_token(Version::API9, "short"); | ||
| 102 | + assert!(verifier.verify(&config).is_ok()); | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +// @tc.name: ut_token_verifier_api10_valid_token | ||
| 106 | +// @tc.desc: Test TokenVerifier with API10 and valid token | ||
| 107 | +// @tc.precon: NA | ||
| 108 | +// @tc.step: 1. Create TokenVerifier | ||
| 109 | +// 2. Create TaskConfig with API10 version and valid token | ||
| 110 | +// 3. Verify config passes validation | ||
| 111 | +// @tc.expect: Verification passes for API10 with valid token | ||
| 112 | +// @tc.type: FUNC | ||
| 113 | +// @tc.require: issueNumber | ||
| 114 | + | ||
| 115 | +fn ut_token_verifier_api10_valid_token() { | ||
| 116 | + let verifier = TokenVerifier {}; | ||
| 117 | + let config = create_config_with_token(Version::API10, "valid_token_12345"); | ||
| 118 | + assert!(verifier.verify(&config).is_ok()); | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +// @tc.name: ut_token_verifier_api10_below_min_length | ||
| 122 | +// @tc.desc: Test TokenVerifier with API10 and token below minimum length | ||
| 123 | +// @tc.precon: NA | ||
| 124 | +// @tc.step: 1. Create TokenVerifier | ||
| 125 | +// 2. Create TaskConfig with API10 version and token below minimum length (7 chars) | ||
| 126 | +// 3. Verify config fails validation | ||
| 127 | +// @tc.expect: Verification fails with error code 401 | ||
| 128 | +// @tc.type: FUNC | ||
| 129 | +// @tc.require: issueNumber | ||
| 130 | + | ||
| 131 | +fn ut_token_verifier_api10_below_min_length() { | ||
| 132 | + let verifier = TokenVerifier {}; | ||
| 133 | + let config = create_config_with_token(Version::API10, "1234567"); | ||
| 134 | + let result = verifier.verify(&config); | ||
| 135 | + assert!(result.is_err()); | ||
| 136 | + assert_eq!(result.unwrap_err(), 401); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +// @tc.name: ut_token_verifier_api10_exceed_max_length | ||
| 140 | +// @tc.desc: Test TokenVerifier with API10 and token exceeding maximum length | ||
| 141 | +// @tc.precon: NA | ||
| 142 | +// @tc.step: 1. Create TokenVerifier | ||
| 143 | +// 2. Create TaskConfig with API10 version and token exceeding maximum length (2049 chars) | ||
| 144 | +// 3. Verify config fails validation | ||
| 145 | +// @tc.expect: Verification fails with error code 401 | ||
| 146 | +// @tc.type: FUNC | ||
| 147 | +// @tc.require: issueNumber | ||
| 148 | + | ||
| 149 | +fn ut_token_verifier_api10_exceed_max_length() { | ||
| 150 | + let verifier = TokenVerifier {}; | ||
| 151 | + let long_token = "a".repeat(2049); | ||
| 152 | + let config = create_config_with_token(Version::API10, &long_token); | ||
| 153 | + let result = verifier.verify(&config); | ||
| 154 | + assert!(result.is_err()); | ||
| 155 | + assert_eq!(result.unwrap_err(), 401); | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +// ==================== DataVerifier Tests ==================== | ||
| 159 | + | ||
| 160 | +fn create_config_with_data(version: Version, action: Action, data: &str) -> TaskConfig { | ||
| 161 | + let mut config = TaskConfigBuilder::new(version) | ||
| 162 | + .url("https://example.com/test".to_string()) | ||
| 163 | + .action(action) | ||
| 164 | + .build(); | ||
| 165 | + config.data = data.to_string(); | ||
| 166 | + config | ||
| 167 | +} | ||
| 168 | + | ||
| 169 | +// @tc.name: ut_data_verifier_api10_download_with_data | ||
| 170 | +// @tc.desc: Test DataVerifier with API10 download and data | ||
| 171 | +// @tc.precon: NA | ||
| 172 | +// @tc.step: 1. Create DataVerifier | ||
| 173 | +// 2. Create TaskConfig with API10 download action and data | ||
| 174 | +// 3. Verify config passes validation | ||
| 175 | +// @tc.expect: Verification passes for API10 download with data | ||
| 176 | +// @tc.type: FUNC | ||
| 177 | +// @tc.require: issueNumber | ||
| 178 | + | ||
| 179 | +fn ut_data_verifier_api10_download_with_data() { | ||
| 180 | + let verifier = DataVerifier {}; | ||
| 181 | + let config = create_config_with_data(Version::API10, Action::Download, "some data"); | ||
| 182 | + assert!(verifier.verify(&config).is_ok()); | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +// @tc.name: ut_data_verifier_api10_upload_with_data | ||
| 186 | +// @tc.desc: Test DataVerifier with API10 upload and data | ||
| 187 | +// @tc.precon: NA | ||
| 188 | +// @tc.step: 1. Create DataVerifier | ||
| 189 | +// 2. Create TaskConfig with API10 upload action and data | ||
| 190 | +// 3. Verify config fails validation | ||
| 191 | +// @tc.expect: Verification fails with error code 401 | ||
| 192 | +// @tc.type: FUNC | ||
| 193 | +// @tc.require: issueNumber | ||
| 194 | + | ||
| 195 | +fn ut_data_verifier_api10_upload_with_data() { | ||
| 196 | + let verifier = DataVerifier {}; | ||
| 197 | + let config = create_config_with_data(Version::API10, Action::Upload, "some data"); | ||
| 198 | + let result = verifier.verify(&config); | ||
| 199 | + assert!(result.is_err()); | ||
| 200 | + assert_eq!(result.unwrap_err(), 401); | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +// @tc.name: ut_data_verifier_api9_upload_with_data | ||
| 204 | +// @tc.desc: Test DataVerifier with API9 upload and data | ||
| 205 | +// @tc.precon: NA | ||
| 206 | +// @tc.step: 1. Create DataVerifier | ||
| 207 | +// 2. Create TaskConfig with API9 upload action and data | ||
| 208 | +// 3. Verify config passes validation | ||
| 209 | +// @tc.expect: Verification passes for API9 upload with data | ||
| 210 | +// @tc.type: FUNC | ||
| 211 | +// @tc.require: issueNumber | ||
| 212 | + | ||
| 213 | +fn ut_data_verifier_api9_upload_with_data() { | ||
| 214 | + let verifier = DataVerifier {}; | ||
| 215 | + let config = create_config_with_data(Version::API9, Action::Upload, "some data"); | ||
| 216 | + assert!(verifier.verify(&config).is_ok()); | ||
| 217 | +} | ||
| @@ -0,0 +1,182 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{Action, TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::method::MethodVerifier; | ||
| 16 | +use request_client::verify::ConfigVerifier; | ||
| 17 | + | ||
| 18 | +fn create_config_with_method(action: Action, method: &str) -> TaskConfig { | ||
| 19 | + TaskConfigBuilder::new(Version::API10) | ||
| 20 | + .url("https://example.com/test".to_string()) | ||
| 21 | + .action(action) | ||
| 22 | + .method(method.to_string()) | ||
| 23 | + .build() | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +// @tc.name: ut_method_verifier_download_get | ||
| 27 | +// @tc.desc: Test MethodVerifier with download action and GET method | ||
| 28 | +// @tc.precon: NA | ||
| 29 | +// @tc.step: 1. Create MethodVerifier | ||
| 30 | +// 2. Create TaskConfig with download action and GET method | ||
| 31 | +// 3. Verify config passes validation | ||
| 32 | +// @tc.expect: Verification passes for download with GET | ||
| 33 | +// @tc.type: FUNC | ||
| 34 | +// @tc.require: issueNumber | ||
| 35 | + | ||
| 36 | +fn ut_method_verifier_download_get() { | ||
| 37 | + let verifier = MethodVerifier {}; | ||
| 38 | + let config = create_config_with_method(Action::Download, "GET"); | ||
| 39 | + let result = verifier.verify(&config); | ||
| 40 | + assert!(result.is_ok()); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// @tc.name: ut_method_verifier_download_post | ||
| 44 | +// @tc.desc: Test MethodVerifier with download action and POST method | ||
| 45 | +// @tc.precon: NA | ||
| 46 | +// @tc.step: 1. Create MethodVerifier | ||
| 47 | +// 2. Create TaskConfig with download action and POST method | ||
| 48 | +// 3. Verify config passes validation | ||
| 49 | +// @tc.expect: Verification passes for download with POST | ||
| 50 | +// @tc.type: FUNC | ||
| 51 | +// @tc.require: issueNumber | ||
| 52 | + | ||
| 53 | +fn ut_method_verifier_download_post() { | ||
| 54 | + let verifier = MethodVerifier {}; | ||
| 55 | + let config = create_config_with_method(Action::Download, "POST"); | ||
| 56 | + let result = verifier.verify(&config); | ||
| 57 | + assert!(result.is_ok()); | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +// @tc.name: ut_method_verifier_download_invalid_method | ||
| 61 | +// @tc.desc: Test MethodVerifier with download action and invalid method | ||
| 62 | +// @tc.precon: NA | ||
| 63 | +// @tc.step: 1. Create MethodVerifier | ||
| 64 | +// 2. Create TaskConfig with download action and PUT method | ||
| 65 | +// 3. Verify config fails validation | ||
| 66 | +// @tc.expect: Verification fails with error code 401 | ||
| 67 | +// @tc.type: FUNC | ||
| 68 | +// @tc.require: issueNumber | ||
| 69 | + | ||
| 70 | +fn ut_method_verifier_download_invalid_method() { | ||
| 71 | + let verifier = MethodVerifier {}; | ||
| 72 | + let config = create_config_with_method(Action::Download, "PUT"); | ||
| 73 | + let result = verifier.verify(&config); | ||
| 74 | + assert!(result.is_err()); | ||
| 75 | + assert_eq!(result.unwrap_err(), 401); | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +// @tc.name: ut_method_verifier_download_delete_method | ||
| 79 | +// @tc.desc: Test MethodVerifier with download action and DELETE method | ||
| 80 | +// @tc.precon: NA | ||
| 81 | +// @tc.step: 1. Create MethodVerifier | ||
| 82 | +// 2. Create TaskConfig with download action and DELETE method | ||
| 83 | +// 3. Verify config fails validation | ||
| 84 | +// @tc.expect: Verification fails with error code 401 | ||
| 85 | +// @tc.type: FUNC | ||
| 86 | +// @tc.require: issueNumber | ||
| 87 | + | ||
| 88 | +fn ut_method_verifier_download_delete_method() { | ||
| 89 | + let verifier = MethodVerifier {}; | ||
| 90 | + let config = create_config_with_method(Action::Download, "DELETE"); | ||
| 91 | + let result = verifier.verify(&config); | ||
| 92 | + assert!(result.is_err()); | ||
| 93 | + assert_eq!(result.unwrap_err(), 401); | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +// @tc.name: ut_method_verifier_upload_put | ||
| 97 | +// @tc.desc: Test MethodVerifier with upload action and PUT method | ||
| 98 | +// @tc.precon: NA | ||
| 99 | +// @tc.step: 1. Create MethodVerifier | ||
| 100 | +// 2. Create TaskConfig with upload action and PUT method | ||
| 101 | +// 3. Verify config passes validation | ||
| 102 | +// @tc.expect: Verification passes for upload with PUT | ||
| 103 | +// @tc.type: FUNC | ||
| 104 | +// @tc.require: issueNumber | ||
| 105 | + | ||
| 106 | +fn ut_method_verifier_upload_put() { | ||
| 107 | + let verifier = MethodVerifier {}; | ||
| 108 | + let config = create_config_with_method(Action::Upload, "PUT"); | ||
| 109 | + let result = verifier.verify(&config); | ||
| 110 | + assert!(result.is_ok()); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +// @tc.name: ut_method_verifier_upload_post | ||
| 114 | +// @tc.desc: Test MethodVerifier with upload action and POST method | ||
| 115 | +// @tc.precon: NA | ||
| 116 | +// @tc.step: 1. Create MethodVerifier | ||
| 117 | +// 2. Create TaskConfig with upload action and POST method | ||
| 118 | +// 3. Verify config passes validation | ||
| 119 | +// @tc.expect: Verification passes for upload with POST | ||
| 120 | +// @tc.type: FUNC | ||
| 121 | +// @tc.require: issueNumber | ||
| 122 | + | ||
| 123 | +fn ut_method_verifier_upload_post() { | ||
| 124 | + let verifier = MethodVerifier {}; | ||
| 125 | + let config = create_config_with_method(Action::Upload, "POST"); | ||
| 126 | + let result = verifier.verify(&config); | ||
| 127 | + assert!(result.is_ok()); | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +// @tc.name: ut_method_verifier_upload_invalid_method | ||
| 131 | +// @tc.desc: Test MethodVerifier with upload action and invalid method | ||
| 132 | +// @tc.precon: NA | ||
| 133 | +// @tc.step: 1. Create MethodVerifier | ||
| 134 | +// 2. Create TaskConfig with upload action and GET method | ||
| 135 | +// 3. Verify config fails validation | ||
| 136 | +// @tc.expect: Verification fails with error code 401 | ||
| 137 | +// @tc.type: FUNC | ||
| 138 | +// @tc.require: issueNumber | ||
| 139 | + | ||
| 140 | +fn ut_method_verifier_upload_invalid_method() { | ||
| 141 | + let verifier = MethodVerifier {}; | ||
| 142 | + let config = create_config_with_method(Action::Upload, "GET"); | ||
| 143 | + let result = verifier.verify(&config); | ||
| 144 | + assert!(result.is_err()); | ||
| 145 | + assert_eq!(result.unwrap_err(), 401); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +// @tc.name: ut_method_verifier_upload_delete_method | ||
| 149 | +// @tc.desc: Test MethodVerifier with upload action and DELETE method | ||
| 150 | +// @tc.precon: NA | ||
| 151 | +// @tc.step: 1. Create MethodVerifier | ||
| 152 | +// 2. Create TaskConfig with upload action and DELETE method | ||
| 153 | +// 3. Verify config fails validation | ||
| 154 | +// @tc.expect: Verification fails with error code 401 | ||
| 155 | +// @tc.type: FUNC | ||
| 156 | +// @tc.require: issueNumber | ||
| 157 | + | ||
| 158 | +fn ut_method_verifier_upload_delete_method() { | ||
| 159 | + let verifier = MethodVerifier {}; | ||
| 160 | + let config = create_config_with_method(Action::Upload, "DELETE"); | ||
| 161 | + let result = verifier.verify(&config); | ||
| 162 | + assert!(result.is_err()); | ||
| 163 | + assert_eq!(result.unwrap_err(), 401); | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +// @tc.name: ut_method_verifier_lowercase_method | ||
| 167 | +// @tc.desc: Test MethodVerifier with lowercase method | ||
| 168 | +// @tc.precon: NA | ||
| 169 | +// @tc.step: 1. Create MethodVerifier | ||
| 170 | +// 2. Create TaskConfig with download action and lowercase 'get' | ||
| 171 | +// 3. Verify config fails validation | ||
| 172 | +// @tc.expect: Verification fails with error code 401 | ||
| 173 | +// @tc.type: FUNC | ||
| 174 | +// @tc.require: issueNumber | ||
| 175 | + | ||
| 176 | +fn ut_method_verifier_lowercase_method() { | ||
| 177 | + let verifier = MethodVerifier {}; | ||
| 178 | + let config = create_config_with_method(Action::Download, "get"); | ||
| 179 | + let result = verifier.verify(&config); | ||
| 180 | + assert!(result.is_err()); | ||
| 181 | + assert_eq!(result.unwrap_err(), 401); | ||
| 182 | +} | ||
| @@ -0,0 +1,191 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{MinSpeed, TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::{min_speed::MinSpeedVerifier, index::IndexVerifier, ConfigVerifier}; | ||
| 16 | +use request_core::config::Action; | ||
| 17 | +use request_core::file::FileSpec; | ||
| 18 | + | ||
| 19 | +// ==================== MinSpeedVerifier Tests ==================== | ||
| 20 | + | ||
| 21 | +fn create_config_with_min_speed(speed: i64, duration: i64) -> TaskConfig { | ||
| 22 | + TaskConfigBuilder::new(Version::API10) | ||
| 23 | + .url("https://example.com/test".to_string()) | ||
| 24 | + .min_speed(MinSpeed { speed, duration }) | ||
| 25 | + .build() | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// @tc.name: ut_min_speed_verifier_valid_zero | ||
| 29 | +// @tc.desc: Test MinSpeedVerifier with zero values | ||
| 30 | +// @tc.precon: NA | ||
| 31 | +// @tc.step: 1. Create MinSpeedVerifier | ||
| 32 | +// 2. Create TaskConfig with min_speed speed=0 and duration=0 | ||
| 33 | +// 3. Verify config passes validation | ||
| 34 | +// @tc.expect: Verification passes for zero min_speed values | ||
| 35 | +// @tc.type: FUNC | ||
| 36 | +// @tc.require: issueNumber | ||
| 37 | + | ||
| 38 | +fn ut_min_speed_verifier_valid_zero() { | ||
| 39 | + let verifier = MinSpeedVerifier {}; | ||
| 40 | + let config = create_config_with_min_speed(0, 0); | ||
| 41 | + assert!(verifier.verify(&config).is_ok()); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// @tc.name: ut_min_speed_verifier_valid_positive | ||
| 45 | +// @tc.desc: Test MinSpeedVerifier with positive values | ||
| 46 | +// @tc.precon: NA | ||
| 47 | +// @tc.step: 1. Create MinSpeedVerifier | ||
| 48 | +// 2. Create TaskConfig with min_speed speed=1024 and duration=60 | ||
| 49 | +// 3. Verify config passes validation | ||
| 50 | +// @tc.expect: Verification passes for positive min_speed values | ||
| 51 | +// @tc.type: FUNC | ||
| 52 | +// @tc.require: issueNumber | ||
| 53 | + | ||
| 54 | +fn ut_min_speed_verifier_valid_positive() { | ||
| 55 | + let verifier = MinSpeedVerifier {}; | ||
| 56 | + let config = create_config_with_min_speed(1024, 60); | ||
| 57 | + assert!(verifier.verify(&config).is_ok()); | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +// @tc.name: ut_min_speed_verifier_negative_speed | ||
| 61 | +// @tc.desc: Test MinSpeedVerifier with negative speed | ||
| 62 | +// @tc.precon: NA | ||
| 63 | +// @tc.step: 1. Create MinSpeedVerifier | ||
| 64 | +// 2. Create TaskConfig with min_speed speed=-1 and duration=60 | ||
| 65 | +// 3. Verify config fails validation | ||
| 66 | +// @tc.expect: Verification fails with error code 401 | ||
| 67 | +// @tc.type: FUNC | ||
| 68 | +// @tc.require: issueNumber | ||
| 69 | + | ||
| 70 | +fn ut_min_speed_verifier_negative_speed() { | ||
| 71 | + let verifier = MinSpeedVerifier {}; | ||
| 72 | + let config = create_config_with_min_speed(-1, 60); | ||
| 73 | + let result = verifier.verify(&config); | ||
| 74 | + assert!(result.is_err()); | ||
| 75 | + assert_eq!(result.unwrap_err(), 401); | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +// @tc.name: ut_min_speed_verifier_negative_duration | ||
| 79 | +// @tc.desc: Test MinSpeedVerifier with negative duration | ||
| 80 | +// @tc.precon: NA | ||
| 81 | +// @tc.step: 1. Create MinSpeedVerifier | ||
| 82 | +// 2. Create TaskConfig with min_speed speed=1024 and duration=-1 | ||
| 83 | +// 3. Verify config fails validation | ||
| 84 | +// @tc.expect: Verification fails with error code 401 | ||
| 85 | +// @tc.type: FUNC | ||
| 86 | +// @tc.require: issueNumber | ||
| 87 | + | ||
| 88 | +fn ut_min_speed_verifier_negative_duration() { | ||
| 89 | + let verifier = MinSpeedVerifier {}; | ||
| 90 | + let config = create_config_with_min_speed(1024, -1); | ||
| 91 | + let result = verifier.verify(&config); | ||
| 92 | + assert!(result.is_err()); | ||
| 93 | + assert_eq!(result.unwrap_err(), 401); | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +// ==================== IndexVerifier Tests ==================== | ||
| 97 | + | ||
| 98 | +fn create_download_config_with_index(index: i32) -> TaskConfig { | ||
| 99 | + TaskConfigBuilder::new(Version::API10) | ||
| 100 | + .url("https://example.com/test".to_string()) | ||
| 101 | + .action(Action::Download) | ||
| 102 | + .index(index) | ||
| 103 | + .build() | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +fn create_upload_config_with_index(index: i32, file_count: usize) -> TaskConfig { | ||
| 107 | + let files: Vec<FileSpec> = (0..file_count) | ||
| 108 | + .map(|i| FileSpec { | ||
| 109 | + name: format!("file_{}", i), | ||
| 110 | + path: format!("/tmp/file_{}", i), | ||
| 111 | + file_name: format!("file_{}", i), | ||
| 112 | + mime_type: "application/octet-stream".to_string(), | ||
| 113 | + is_user_file: false, | ||
| 114 | + fd: None, | ||
| 115 | + }) | ||
| 116 | + .collect(); | ||
| 117 | + TaskConfigBuilder::new(Version::API10) | ||
| 118 | + .url("https://example.com/upload".to_string()) | ||
| 119 | + .action(Action::Upload) | ||
| 120 | + .index(index) | ||
| 121 | + .files(files) | ||
| 122 | + .build() | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +// @tc.name: ut_index_verifier_download_zero_index | ||
| 126 | +// @tc.desc: Test IndexVerifier with download action and index=0 | ||
| 127 | +// @tc.precon: NA | ||
| 128 | +// @tc.step: 1. Create IndexVerifier | ||
| 129 | +// 2. Create TaskConfig with download action and index=0 | ||
| 130 | +// 3. Verify config passes validation | ||
| 131 | +// @tc.expect: Verification passes for download with index=0 | ||
| 132 | +// @tc.type: FUNC | ||
| 133 | +// @tc.require: issueNumber | ||
| 134 | + | ||
| 135 | +fn ut_index_verifier_download_zero_index() { | ||
| 136 | + let verifier = IndexVerifier {}; | ||
| 137 | + let config = create_download_config_with_index(0); | ||
| 138 | + assert!(verifier.verify(&config).is_ok()); | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +// @tc.name: ut_index_verifier_download_non_zero_index | ||
| 142 | +// @tc.desc: Test IndexVerifier with download action and non-zero index | ||
| 143 | +// @tc.precon: NA | ||
| 144 | +// @tc.step: 1. Create IndexVerifier | ||
| 145 | +// 2. Create TaskConfig with download action and index=1 | ||
| 146 | +// 3. Verify config fails validation | ||
| 147 | +// @tc.expect: Verification fails with error code 401 | ||
| 148 | +// @tc.type: FUNC | ||
| 149 | +// @tc.require: issueNumber | ||
| 150 | + | ||
| 151 | +fn ut_index_verifier_download_non_zero_index() { | ||
| 152 | + let verifier = IndexVerifier {}; | ||
| 153 | + let config = create_download_config_with_index(1); | ||
| 154 | + let result = verifier.verify(&config); | ||
| 155 | + assert!(result.is_err()); | ||
| 156 | + assert_eq!(result.unwrap_err(), 401); | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +// @tc.name: ut_index_verifier_upload_valid_index | ||
| 160 | +// @tc.desc: Test IndexVerifier with upload action and valid index | ||
| 161 | +// @tc.precon: NA | ||
| 162 | +// @tc.step: 1. Create IndexVerifier | ||
| 163 | +// 2. Create TaskConfig with upload action, index=2 and 5 files | ||
| 164 | +// 3. Verify config passes validation | ||
| 165 | +// @tc.expect: Verification passes for upload with valid index | ||
| 166 | +// @tc.type: FUNC | ||
| 167 | +// @tc.require: issueNumber | ||
| 168 | + | ||
| 169 | +fn ut_index_verifier_upload_valid_index() { | ||
| 170 | + let verifier = IndexVerifier {}; | ||
| 171 | + let config = create_upload_config_with_index(2, 5); | ||
| 172 | + assert!(verifier.verify(&config).is_ok()); | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +// @tc.name: ut_index_verifier_upload_index_exceeds_file_count | ||
| 176 | +// @tc.desc: Test IndexVerifier with upload action and index exceeds file count | ||
| 177 | +// @tc.precon: NA | ||
| 178 | +// @tc.step: 1. Create IndexVerifier | ||
| 179 | +// 2. Create TaskConfig with upload action, index=4 and 3 files | ||
| 180 | +// 3. Verify config fails validation | ||
| 181 | +// @tc.expect: Verification fails with error code 401 | ||
| 182 | +// @tc.type: FUNC | ||
| 183 | +// @tc.require: issueNumber | ||
| 184 | + | ||
| 185 | +fn ut_index_verifier_upload_index_exceeds_file_count() { | ||
| 186 | + let verifier = IndexVerifier {}; | ||
| 187 | + let config = create_upload_config_with_index(4, 3); | ||
| 188 | + let result = verifier.verify(&config); | ||
| 189 | + assert!(result.is_err()); | ||
| 190 | + assert_eq!(result.unwrap_err(), 401); | ||
| 191 | +} | ||
| @@ -0,0 +1,212 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{Action, TaskConfig, TaskConfigBuilder, Timeout, Version}; | ||
| 15 | +use request_core::file::FileSpec; | ||
| 16 | +use request_client::verify::{TaskConfigVerifier, ConfigVerifier}; | ||
| 17 | + | ||
| 18 | +fn create_valid_download_config() -> TaskConfig { | ||
| 19 | + TaskConfigBuilder::new(Version::API10) | ||
| 20 | + .url("https://example.com/test".to_string()) | ||
| 21 | + .action(Action::Download) | ||
| 22 | + .timeout(Timeout { connection_timeout: 60, total_timeout: 3600 }) | ||
| 23 | + .build() | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +fn create_valid_upload_config() -> TaskConfig { | ||
| 27 | + let files = vec![FileSpec { | ||
| 28 | + name: "file".to_string(), | ||
| 29 | + path: "/tmp/file".to_string(), | ||
| 30 | + file_name: "file.txt".to_string(), | ||
| 31 | + mime_type: "text/plain".to_string(), | ||
| 32 | + is_user_file: false, | ||
| 33 | + fd: None, | ||
| 34 | + }]; | ||
| 35 | + TaskConfigBuilder::new(Version::API10) | ||
| 36 | + .url("https://example.com/upload".to_string()) | ||
| 37 | + .action(Action::Upload) | ||
| 38 | + .method("PUT".to_string()) | ||
| 39 | + .files(files) | ||
| 40 | + .timeout(Timeout { connection_timeout: 60, total_timeout: 3600 }) | ||
| 41 | + .build() | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// @tc.name: ut_task_config_verifier_get_instance | ||
| 45 | +// @tc.desc: Test TaskConfigVerifier singleton instance | ||
| 46 | +// @tc.precon: NA | ||
| 47 | +// @tc.step: 1. Get TaskConfigVerifier instance twice | ||
| 48 | +// 2. Verify both instances are the same pointer | ||
| 49 | +// @tc.expect: Both instances point to the same singleton | ||
| 50 | +// @tc.type: FUNC | ||
| 51 | +// @tc.require: issueNumber | ||
| 52 | + | ||
| 53 | +fn ut_task_config_verifier_get_instance() { | ||
| 54 | + let instance1 = TaskConfigVerifier::get_instance(); | ||
| 55 | + let instance2 = TaskConfigVerifier::get_instance(); | ||
| 56 | + assert!(std::ptr::eq(instance1, instance2)); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// @tc.name: ut_task_config_verifier_valid_download_config | ||
| 60 | +// @tc.desc: Test TaskConfigVerifier with valid download config | ||
| 61 | +// @tc.precon: NA | ||
| 62 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 63 | +// 2. Create valid download config | ||
| 64 | +// 3. Verify config passes validation | ||
| 65 | +// @tc.expect: Verification passes for valid download config | ||
| 66 | +// @tc.type: FUNC | ||
| 67 | +// @tc.require: issueNumber | ||
| 68 | + | ||
| 69 | +fn ut_task_config_verifier_valid_download_config() { | ||
| 70 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 71 | + let config = create_valid_download_config(); | ||
| 72 | + assert!(verifier.verify(&config).is_ok()); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +// @tc.name: ut_task_config_verifier_valid_upload_config | ||
| 76 | +// @tc.desc: Test TaskConfigVerifier with valid upload config | ||
| 77 | +// @tc.precon: NA | ||
| 78 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 79 | +// 2. Create valid upload config with files | ||
| 80 | +// 3. Verify config passes validation | ||
| 81 | +// @tc.expect: Verification passes for valid upload config | ||
| 82 | +// @tc.type: FUNC | ||
| 83 | +// @tc.require: issueNumber | ||
| 84 | + | ||
| 85 | +fn ut_task_config_verifier_valid_upload_config() { | ||
| 86 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 87 | + let config = create_valid_upload_config(); | ||
| 88 | + assert!(verifier.verify(&config).is_ok()); | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +// @tc.name: ut_task_config_verifier_invalid_url | ||
| 92 | +// @tc.desc: Test TaskConfigVerifier with invalid URL | ||
| 93 | +// @tc.precon: NA | ||
| 94 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 95 | +// 2. Create config with invalid URL | ||
| 96 | +// 3. Verify config fails validation | ||
| 97 | +// @tc.expect: Verification fails with error code 401 | ||
| 98 | +// @tc.type: FUNC | ||
| 99 | +// @tc.require: issueNumber | ||
| 100 | + | ||
| 101 | +fn ut_task_config_verifier_invalid_url() { | ||
| 102 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 103 | + let mut config = create_valid_download_config(); | ||
| 104 | + config.url = "invalid_url".to_string(); | ||
| 105 | + let result = verifier.verify(&config); | ||
| 106 | + assert!(result.is_err()); | ||
| 107 | + assert_eq!(result.unwrap_err(), 401); | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +// @tc.name: ut_task_config_verifier_invalid_method_download | ||
| 111 | +// @tc.desc: Test TaskConfigVerifier with invalid method for download | ||
| 112 | +// @tc.precon: NA | ||
| 113 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 114 | +// 2. Create download config with PUT method | ||
| 115 | +// 3. Verify config fails validation | ||
| 116 | +// @tc.expect: Verification fails with error code 401 | ||
| 117 | +// @tc.type: FUNC | ||
| 118 | +// @tc.require: issueNumber | ||
| 119 | + | ||
| 120 | +fn ut_task_config_verifier_invalid_method_download() { | ||
| 121 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 122 | + let mut config = create_valid_download_config(); | ||
| 123 | + config.method = "PUT".to_string(); | ||
| 124 | + let result = verifier.verify(&config); | ||
| 125 | + assert!(result.is_err()); | ||
| 126 | + assert_eq!(result.unwrap_err(), 401); | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +// @tc.name: ut_task_config_verifier_upload_without_files | ||
| 130 | +// @tc.desc: Test TaskConfigVerifier with upload but no files | ||
| 131 | +// @tc.precon: NA | ||
| 132 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 133 | +// 2. Create upload config without files | ||
| 134 | +// 3. Verify config fails validation | ||
| 135 | +// @tc.expect: Verification fails with error code 401 | ||
| 136 | +// @tc.type: FUNC | ||
| 137 | +// @tc.require: issueNumber | ||
| 138 | + | ||
| 139 | +fn ut_task_config_verifier_upload_without_files() { | ||
| 140 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 141 | + let mut config = TaskConfigBuilder::new(Version::API10) | ||
| 142 | + .url("https://example.com/upload".to_string()) | ||
| 143 | + .action(Action::Upload) | ||
| 144 | + .method("PUT".to_string()) | ||
| 145 | + .timeout(Timeout { connection_timeout: 60, total_timeout: 3600 }) | ||
| 146 | + .build(); | ||
| 147 | + config.file_specs = vec![]; | ||
| 148 | + let result = verifier.verify(&config); | ||
| 149 | + assert!(result.is_err()); | ||
| 150 | + assert_eq!(result.unwrap_err(), 401); | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +// @tc.name: ut_task_config_verifier_invalid_timeout | ||
| 154 | +// @tc.desc: Test TaskConfigVerifier with invalid timeout | ||
| 155 | +// @tc.precon: NA | ||
| 156 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 157 | +// 2. Create config with zero connection timeout | ||
| 158 | +// 3. Verify config fails validation | ||
| 159 | +// @tc.expect: Verification fails with error code 401 | ||
| 160 | +// @tc.type: FUNC | ||
| 161 | +// @tc.require: issueNumber | ||
| 162 | + | ||
| 163 | +fn ut_task_config_verifier_invalid_timeout() { | ||
| 164 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 165 | + let config = TaskConfigBuilder::new(Version::API10) | ||
| 166 | + .url("https://example.com/test".to_string()) | ||
| 167 | + .action(Action::Download) | ||
| 168 | + .timeout(Timeout { connection_timeout: 0, total_timeout: 3600 }) | ||
| 169 | + .build(); | ||
| 170 | + let result = verifier.verify(&config); | ||
| 171 | + assert!(result.is_err()); | ||
| 172 | + assert_eq!(result.unwrap_err(), 401); | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +// @tc.name: ut_task_config_verifier_long_title | ||
| 176 | +// @tc.desc: Test TaskConfigVerifier with title exceeding max length | ||
| 177 | +// @tc.precon: NA | ||
| 178 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 179 | +// 2. Create config with title exceeding max length (257 chars) | ||
| 180 | +// 3. Verify config fails validation | ||
| 181 | +// @tc.expect: Verification fails with error code 401 | ||
| 182 | +// @tc.type: FUNC | ||
| 183 | +// @tc.require: issueNumber | ||
| 184 | + | ||
| 185 | +fn ut_task_config_verifier_long_title() { | ||
| 186 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 187 | + let mut config = create_valid_download_config(); | ||
| 188 | + config.title = "a".repeat(257); | ||
| 189 | + let result = verifier.verify(&config); | ||
| 190 | + assert!(result.is_err()); | ||
| 191 | + assert_eq!(result.unwrap_err(), 401); | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +// @tc.name: ut_task_config_verifier_api9_config | ||
| 195 | +// @tc.desc: Test TaskConfigVerifier with API9 config | ||
| 196 | +// @tc.precon: NA | ||
| 197 | +// @tc.step: 1. Get TaskConfigVerifier instance | ||
| 198 | +// 2. Create config with API9 version | ||
| 199 | +// 3. Verify config passes validation | ||
| 200 | +// @tc.expect: Verification passes for API9 config | ||
| 201 | +// @tc.type: FUNC | ||
| 202 | +// @tc.require: issueNumber | ||
| 203 | + | ||
| 204 | +fn ut_task_config_verifier_api9_config() { | ||
| 205 | + let verifier = TaskConfigVerifier::get_instance(); | ||
| 206 | + let config = TaskConfigBuilder::new(Version::API9) | ||
| 207 | + .url("https://example.com/test".to_string()) | ||
| 208 | + .action(Action::Download) | ||
| 209 | + .timeout(Timeout { connection_timeout: 60, total_timeout: 3600 }) | ||
| 210 | + .build(); | ||
| 211 | + assert!(verifier.verify(&config).is_ok()); | ||
| 212 | +} | ||
| @@ -0,0 +1,244 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{Notification, TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::{notification::NotificationVerifier, ConfigVerifier}; | ||
| 16 | + | ||
| 17 | +fn create_config_with_notification(version: Version, notification: Notification) -> TaskConfig { | ||
| 18 | + let mut config = TaskConfigBuilder::new(version) | ||
| 19 | + .url("https://example.com/test".to_string()) | ||
| 20 | + .build(); | ||
| 21 | + config.notification = notification; | ||
| 22 | + config | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +// @tc.name: ut_notification_verifier_api9_with_notification | ||
| 26 | +// @tc.desc: Test NotificationVerifier with API9 version ignores notification validation | ||
| 27 | +// @tc.precon: NA | ||
| 28 | +// @tc.step: 1. Create NotificationVerifier | ||
| 29 | +// 2. Create TaskConfig with API9 version and notification with long title | ||
| 30 | +// 3. Verify config passes validation | ||
| 31 | +// @tc.expect: Verification passes for API9 with any notification | ||
| 32 | +// @tc.type: FUNC | ||
| 33 | +// @tc.require: issueNumber | ||
| 34 | + | ||
| 35 | +fn ut_notification_verifier_api9_with_notification() { | ||
| 36 | + let verifier = NotificationVerifier {}; | ||
| 37 | + let notification = Notification { | ||
| 38 | + title: Some("a".repeat(2000)), | ||
| 39 | + text: None, | ||
| 40 | + disable: None, | ||
| 41 | + visibility: Some(0), | ||
| 42 | + want_agent: None, | ||
| 43 | + }; | ||
| 44 | + let config = create_config_with_notification(Version::API9, notification); | ||
| 45 | + assert!(verifier.verify(&config).is_ok()); | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +// @tc.name: ut_notification_verifier_api10_empty_notification | ||
| 49 | +// @tc.desc: Test NotificationVerifier with API10 and empty notification | ||
| 50 | +// @tc.precon: NA | ||
| 51 | +// @tc.step: 1. Create NotificationVerifier | ||
| 52 | +// 2. Create TaskConfig with API10 version and empty notification | ||
| 53 | +// 3. Verify config passes validation | ||
| 54 | +// @tc.expect: Verification passes for API10 with empty notification | ||
| 55 | +// @tc.type: FUNC | ||
| 56 | +// @tc.require: issueNumber | ||
| 57 | + | ||
| 58 | +fn ut_notification_verifier_api10_empty_notification() { | ||
| 59 | + let verifier = NotificationVerifier {}; | ||
| 60 | + let notification = Notification { | ||
| 61 | + title: None, | ||
| 62 | + text: None, | ||
| 63 | + disable: None, | ||
| 64 | + visibility: None, | ||
| 65 | + want_agent: None, | ||
| 66 | + }; | ||
| 67 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 68 | + assert!(verifier.verify(&config).is_ok()); | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +// @tc.name: ut_notification_verifier_api10_valid_title | ||
| 72 | +// @tc.desc: Test NotificationVerifier with API10 and valid title | ||
| 73 | +// @tc.precon: NA | ||
| 74 | +// @tc.step: 1. Create NotificationVerifier | ||
| 75 | +// 2. Create TaskConfig with API10 version and notification with valid title | ||
| 76 | +// 3. Verify config passes validation | ||
| 77 | +// @tc.expect: Verification passes for API10 with valid title | ||
| 78 | +// @tc.type: FUNC | ||
| 79 | +// @tc.require: issueNumber | ||
| 80 | + | ||
| 81 | +fn ut_notification_verifier_api10_valid_title() { | ||
| 82 | + let verifier = NotificationVerifier {}; | ||
| 83 | + let notification = Notification { | ||
| 84 | + title: Some("Download Notification".to_string()), | ||
| 85 | + text: None, | ||
| 86 | + disable: None, | ||
| 87 | + visibility: None, | ||
| 88 | + want_agent: None, | ||
| 89 | + }; | ||
| 90 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 91 | + assert!(verifier.verify(&config).is_ok()); | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +// @tc.name: ut_notification_verifier_api10_title_exceed_max | ||
| 95 | +// @tc.desc: Test NotificationVerifier with API10 and title exceeding max length | ||
| 96 | +// @tc.precon: NA | ||
| 97 | +// @tc.step: 1. Create NotificationVerifier | ||
| 98 | +// 2. Create TaskConfig with API10 version and notification with title exceeding max length | ||
| 99 | +// 3. Verify config fails validation | ||
| 100 | +// @tc.expect: Verification fails with error code 401 | ||
| 101 | +// @tc.type: FUNC | ||
| 102 | +// @tc.require: issueNumber | ||
| 103 | + | ||
| 104 | +fn ut_notification_verifier_api10_title_exceed_max() { | ||
| 105 | + let verifier = NotificationVerifier {}; | ||
| 106 | + let notification = Notification { | ||
| 107 | + title: Some("a".repeat(1025)), | ||
| 108 | + text: None, | ||
| 109 | + disable: None, | ||
| 110 | + visibility: None, | ||
| 111 | + want_agent: None, | ||
| 112 | + }; | ||
| 113 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 114 | + let result = verifier.verify(&config); | ||
| 115 | + assert!(result.is_err()); | ||
| 116 | + assert_eq!(result.unwrap_err(), 401); | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +// @tc.name: ut_notification_verifier_api10_text_exceed_max | ||
| 120 | +// @tc.desc: Test NotificationVerifier with API10 and text exceeding max length | ||
| 121 | +// @tc.precon: NA | ||
| 122 | +// @tc.step: 1. Create NotificationVerifier | ||
| 123 | +// 2. Create TaskConfig with API10 version and notification with text exceeding max length | ||
| 124 | +// 3. Verify config fails validation | ||
| 125 | +// @tc.expect: Verification fails with error code 401 | ||
| 126 | +// @tc.type: FUNC | ||
| 127 | +// @tc.require: issueNumber | ||
| 128 | + | ||
| 129 | +fn ut_notification_verifier_api10_text_exceed_max() { | ||
| 130 | + let verifier = NotificationVerifier {}; | ||
| 131 | + let notification = Notification { | ||
| 132 | + title: None, | ||
| 133 | + text: Some("a".repeat(3073)), | ||
| 134 | + disable: None, | ||
| 135 | + visibility: None, | ||
| 136 | + want_agent: None, | ||
| 137 | + }; | ||
| 138 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 139 | + let result = verifier.verify(&config); | ||
| 140 | + assert!(result.is_err()); | ||
| 141 | + assert_eq!(result.unwrap_err(), 401); | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +// @tc.name: ut_notification_verifier_api10_empty_want_agent | ||
| 145 | +// @tc.desc: Test NotificationVerifier with API10 and empty want_agent | ||
| 146 | +// @tc.precon: NA | ||
| 147 | +// @tc.step: 1. Create NotificationVerifier | ||
| 148 | +// 2. Create TaskConfig with API10 version and notification with empty want_agent | ||
| 149 | +// 3. Verify config fails validation | ||
| 150 | +// @tc.expect: Verification fails with error code 401 | ||
| 151 | +// @tc.type: FUNC | ||
| 152 | +// @tc.require: issueNumber | ||
| 153 | + | ||
| 154 | +fn ut_notification_verifier_api10_empty_want_agent() { | ||
| 155 | + let verifier = NotificationVerifier {}; | ||
| 156 | + let notification = Notification { | ||
| 157 | + title: None, | ||
| 158 | + text: None, | ||
| 159 | + disable: None, | ||
| 160 | + visibility: None, | ||
| 161 | + want_agent: Some("".to_string()), | ||
| 162 | + }; | ||
| 163 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 164 | + let result = verifier.verify(&config); | ||
| 165 | + assert!(result.is_err()); | ||
| 166 | + assert_eq!(result.unwrap_err(), 401); | ||
| 167 | +} | ||
| 168 | + | ||
| 169 | +// @tc.name: ut_notification_verifier_api10_visibility_zero | ||
| 170 | +// @tc.desc: Test NotificationVerifier with API10 and visibility=0 | ||
| 171 | +// @tc.precon: NA | ||
| 172 | +// @tc.step: 1. Create NotificationVerifier | ||
| 173 | +// 2. Create TaskConfig with API10 version and notification with visibility=0 | ||
| 174 | +// 3. Verify config fails validation | ||
| 175 | +// @tc.expect: Verification fails with error code 401 | ||
| 176 | +// @tc.type: FUNC | ||
| 177 | +// @tc.require: issueNumber | ||
| 178 | + | ||
| 179 | +fn ut_notification_verifier_api10_visibility_zero() { | ||
| 180 | + let verifier = NotificationVerifier {}; | ||
| 181 | + let notification = Notification { | ||
| 182 | + title: None, | ||
| 183 | + text: None, | ||
| 184 | + disable: None, | ||
| 185 | + visibility: Some(0), | ||
| 186 | + want_agent: None, | ||
| 187 | + }; | ||
| 188 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 189 | + let result = verifier.verify(&config); | ||
| 190 | + assert!(result.is_err()); | ||
| 191 | + assert_eq!(result.unwrap_err(), 401); | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +// @tc.name: ut_notification_verifier_api10_visibility_valid | ||
| 195 | +// @tc.desc: Test NotificationVerifier with API10 and valid visibility values | ||
| 196 | +// @tc.precon: NA | ||
| 197 | +// @tc.step: 1. Create NotificationVerifier | ||
| 198 | +// 2. Create TaskConfig with API10 version and notification with visibility 1, 2, 3 | ||
| 199 | +// 3. Verify config passes validation for each | ||
| 200 | +// @tc.expect: Verification passes for valid visibility values | ||
| 201 | +// @tc.type: FUNC | ||
| 202 | +// @tc.require: issueNumber | ||
| 203 | + | ||
| 204 | +fn ut_notification_verifier_api10_visibility_valid() { | ||
| 205 | + let verifier = NotificationVerifier {}; | ||
| 206 | + for vis in [1, 2, 3] { | ||
| 207 | + let notification = Notification { | ||
| 208 | + title: None, | ||
| 209 | + text: None, | ||
| 210 | + disable: None, | ||
| 211 | + visibility: Some(vis), | ||
| 212 | + want_agent: None, | ||
| 213 | + }; | ||
| 214 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 215 | + assert!(verifier.verify(&config).is_ok()); | ||
| 216 | + } | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +// @tc.name: ut_notification_verifier_api10_visibility_invalid | ||
| 220 | +// @tc.desc: Test NotificationVerifier with API10 and invalid visibility values | ||
| 221 | +// @tc.precon: NA | ||
| 222 | +// @tc.step: 1. Create NotificationVerifier | ||
| 223 | +// 2. Create TaskConfig with API10 version and notification with visibility 4, 5, 7 | ||
| 224 | +// 3. Verify config fails validation for each | ||
| 225 | +// @tc.expect: Verification fails with error code 401 | ||
| 226 | +// @tc.type: FUNC | ||
| 227 | +// @tc.require: issueNumber | ||
| 228 | + | ||
| 229 | +fn ut_notification_verifier_api10_visibility_invalid() { | ||
| 230 | + let verifier = NotificationVerifier {}; | ||
| 231 | + for vis in [4, 5, 7] { | ||
| 232 | + let notification = Notification { | ||
| 233 | + title: None, | ||
| 234 | + text: None, | ||
| 235 | + disable: None, | ||
| 236 | + visibility: Some(vis), | ||
| 237 | + want_agent: None, | ||
| 238 | + }; | ||
| 239 | + let config = create_config_with_notification(Version::API10, notification); | ||
| 240 | + let result = verifier.verify(&config); | ||
| 241 | + assert!(result.is_err()); | ||
| 242 | + assert_eq!(result.unwrap_err(), 401); | ||
| 243 | + } | ||
| 244 | +} | ||
| @@ -0,0 +1,244 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::{proxy::ProxyVerifier, timeout::TimeoutVerifier, ConfigVerifier}; | ||
| 16 | + | ||
| 17 | +// ==================== ProxyVerifier Tests ==================== | ||
| 18 | + | ||
| 19 | +fn create_config_with_proxy(version: Version, proxy: &str) -> TaskConfig { | ||
| 20 | + let mut config = TaskConfigBuilder::new(version) | ||
| 21 | + .url("https://example.com/test".to_string()) | ||
| 22 | + .build(); | ||
| 23 | + config.proxy = proxy.to_string(); | ||
| 24 | + config | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +// @tc.name: ut_proxy_verifier_api9_any_proxy | ||
| 28 | +// @tc.desc: Test ProxyVerifier with API9 version ignores proxy validation | ||
| 29 | +// @tc.precon: NA | ||
| 30 | +// @tc.step: 1. Create ProxyVerifier | ||
| 31 | +// 2. Create TaskConfig with API9 version and invalid proxy | ||
| 32 | +// 3. Verify config passes validation | ||
| 33 | +// @tc.expect: Verification passes for API9 with any proxy | ||
| 34 | +// @tc.type: FUNC | ||
| 35 | +// @tc.require: issueNumber | ||
| 36 | + | ||
| 37 | +fn ut_proxy_verifier_api9_any_proxy() { | ||
| 38 | + let verifier = ProxyVerifier {}; | ||
| 39 | + let config = create_config_with_proxy(Version::API9, "invalid_proxy"); | ||
| 40 | + assert!(verifier.verify(&config).is_ok()); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// @tc.name: ut_proxy_verifier_empty_proxy | ||
| 44 | +// @tc.desc: Test ProxyVerifier with empty proxy | ||
| 45 | +// @tc.precon: NA | ||
| 46 | +// @tc.step: 1. Create ProxyVerifier | ||
| 47 | +// 2. Create TaskConfig with API10 version and empty proxy | ||
| 48 | +// 3. Verify config passes validation | ||
| 49 | +// @tc.expect: Verification passes for empty proxy | ||
| 50 | +// @tc.type: FUNC | ||
| 51 | +// @tc.require: issueNumber | ||
| 52 | + | ||
| 53 | +fn ut_proxy_verifier_empty_proxy() { | ||
| 54 | + let verifier = ProxyVerifier {}; | ||
| 55 | + let config = create_config_with_proxy(Version::API10, ""); | ||
| 56 | + assert!(verifier.verify(&config).is_ok()); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// @tc.name: ut_proxy_verifier_valid_proxy | ||
| 60 | +// @tc.desc: Test ProxyVerifier with valid proxy | ||
| 61 | +// @tc.precon: NA | ||
| 62 | +// @tc.step: 1. Create ProxyVerifier | ||
| 63 | +// 2. Create TaskConfig with API10 version and valid proxy | ||
| 64 | +// 3. Verify config passes validation | ||
| 65 | +// @tc.expect: Verification passes for valid proxy | ||
| 66 | +// @tc.type: FUNC | ||
| 67 | +// @tc.require: issueNumber | ||
| 68 | + | ||
| 69 | +fn ut_proxy_verifier_valid_proxy() { | ||
| 70 | + let verifier = ProxyVerifier {}; | ||
| 71 | + let config = create_config_with_proxy(Version::API10, "http://127.0.0.1:8080"); | ||
| 72 | + assert!(verifier.verify(&config).is_ok()); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +// @tc.name: ut_proxy_verifier_missing_http_prefix | ||
| 76 | +// @tc.desc: Test ProxyVerifier with missing http:// prefix | ||
| 77 | +// @tc.precon: NA | ||
| 78 | +// @tc.step: 1. Create ProxyVerifier | ||
| 79 | +// 2. Create TaskConfig with API10 version and proxy without http:// prefix | ||
| 80 | +// 3. Verify config fails validation | ||
| 81 | +// @tc.expect: Verification fails with error code 401 | ||
| 82 | +// @tc.type: FUNC | ||
| 83 | +// @tc.require: issueNumber | ||
| 84 | + | ||
| 85 | +fn ut_proxy_verifier_missing_http_prefix() { | ||
| 86 | + let verifier = ProxyVerifier {}; | ||
| 87 | + let config = create_config_with_proxy(Version::API10, "127.0.0.1:8080"); | ||
| 88 | + let result = verifier.verify(&config); | ||
| 89 | + assert!(result.is_err()); | ||
| 90 | + assert_eq!(result.unwrap_err(), 401); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +// @tc.name: ut_proxy_verifier_missing_port | ||
| 94 | +// @tc.desc: Test ProxyVerifier with missing port | ||
| 95 | +// @tc.precon: NA | ||
| 96 | +// @tc.step: 1. Create ProxyVerifier | ||
| 97 | +// 2. Create TaskConfig with API10 version and proxy without port | ||
| 98 | +// 3. Verify config fails validation | ||
| 99 | +// @tc.expect: Verification fails with error code 401 | ||
| 100 | +// @tc.type: FUNC | ||
| 101 | +// @tc.require: issueNumber | ||
| 102 | + | ||
| 103 | +fn ut_proxy_verifier_missing_port() { | ||
| 104 | + let verifier = ProxyVerifier {}; | ||
| 105 | + let config = create_config_with_proxy(Version::API10, "http://127.0.0.1"); | ||
| 106 | + let result = verifier.verify(&config); | ||
| 107 | + assert!(result.is_err()); | ||
| 108 | + assert_eq!(result.unwrap_err(), 401); | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +// @tc.name: ut_proxy_verifier_non_numeric_port | ||
| 112 | +// @tc.desc: Test ProxyVerifier with non-numeric port | ||
| 113 | +// @tc.precon: NA | ||
| 114 | +// @tc.step: 1. Create ProxyVerifier | ||
| 115 | +// 2. Create TaskConfig with API10 version and proxy with non-numeric port | ||
| 116 | +// 3. Verify config fails validation | ||
| 117 | +// @tc.expect: Verification fails with error code 401 | ||
| 118 | +// @tc.type: FUNC | ||
| 119 | +// @tc.require: issueNumber | ||
| 120 | + | ||
| 121 | +fn ut_proxy_verifier_non_numeric_port() { | ||
| 122 | + let verifier = ProxyVerifier {}; | ||
| 123 | + let config = create_config_with_proxy(Version::API10, "http://127.0.0.1:abc"); | ||
| 124 | + let result = verifier.verify(&config); | ||
| 125 | + assert!(result.is_err()); | ||
| 126 | + assert_eq!(result.unwrap_err(), 401); | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +// @tc.name: ut_proxy_verifier_max_length | ||
| 130 | +// @tc.desc: Test ProxyVerifier with proxy exceeding max length | ||
| 131 | +// @tc.precon: NA | ||
| 132 | +// @tc.step: 1. Create ProxyVerifier | ||
| 133 | +// 2. Create TaskConfig with API10 version and proxy exceeding max length | ||
| 134 | +// 3. Verify config fails validation | ||
| 135 | +// @tc.expect: Verification fails with error code 401 | ||
| 136 | +// @tc.type: FUNC | ||
| 137 | +// @tc.require: issueNumber | ||
| 138 | + | ||
| 139 | +fn ut_proxy_verifier_max_length() { | ||
| 140 | + let verifier = ProxyVerifier {}; | ||
| 141 | + let long_proxy = format!("http://{}", "a".repeat(600)); | ||
| 142 | + let config = create_config_with_proxy(Version::API10, &long_proxy); | ||
| 143 | + let result = verifier.verify(&config); | ||
| 144 | + assert!(result.is_err()); | ||
| 145 | + assert_eq!(result.unwrap_err(), 401); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +// ==================== TimeoutVerifier Tests ==================== | ||
| 149 | + | ||
| 150 | +fn create_config_with_timeout(connection_timeout: u64, total_timeout: u64) -> TaskConfig { | ||
| 151 | + TaskConfigBuilder::new(Version::API10) | ||
| 152 | + .url("https://example.com/test".to_string()) | ||
| 153 | + .timeout(request_core::config::Timeout { | ||
| 154 | + connection_timeout, | ||
| 155 | + total_timeout, | ||
| 156 | + }) | ||
| 157 | + .build() | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +// @tc.name: ut_timeout_verifier_valid_timeout | ||
| 161 | +// @tc.desc: Test TimeoutVerifier with valid timeout values | ||
| 162 | +// @tc.precon: NA | ||
| 163 | +// @tc.step: 1. Create TimeoutVerifier | ||
| 164 | +// 2. Create TaskConfig with valid timeout values | ||
| 165 | +// 3. Verify config passes validation | ||
| 166 | +// @tc.expect: Verification passes for valid timeout values | ||
| 167 | +// @tc.type: FUNC | ||
| 168 | +// @tc.require: issueNumber | ||
| 169 | + | ||
| 170 | +fn ut_timeout_verifier_valid_timeout() { | ||
| 171 | + let verifier = TimeoutVerifier {}; | ||
| 172 | + let config = create_config_with_timeout(60, 3600); | ||
| 173 | + assert!(verifier.verify(&config).is_ok()); | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +// @tc.name: ut_timeout_verifier_zero_connection_timeout | ||
| 177 | +// @tc.desc: Test TimeoutVerifier with zero connection timeout | ||
| 178 | +// @tc.precon: NA | ||
| 179 | +// @tc.step: 1. Create TimeoutVerifier | ||
| 180 | +// 2. Create TaskConfig with zero connection timeout | ||
| 181 | +// 3. Verify config fails validation | ||
| 182 | +// @tc.expect: Verification fails with error code 401 | ||
| 183 | +// @tc.type: FUNC | ||
| 184 | +// @tc.require: issueNumber | ||
| 185 | + | ||
| 186 | +fn ut_timeout_verifier_zero_connection_timeout() { | ||
| 187 | + let verifier = TimeoutVerifier {}; | ||
| 188 | + let config = create_config_with_timeout(0, 3600); | ||
| 189 | + let result = verifier.verify(&config); | ||
| 190 | + assert!(result.is_err()); | ||
| 191 | + assert_eq!(result.unwrap_err(), 401); | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +// @tc.name: ut_timeout_verifier_zero_total_timeout | ||
| 195 | +// @tc.desc: Test TimeoutVerifier with zero total timeout | ||
| 196 | +// @tc.precon: NA | ||
| 197 | +// @tc.step: 1. Create TimeoutVerifier | ||
| 198 | +// 2. Create TaskConfig with zero total timeout | ||
| 199 | +// 3. Verify config fails validation | ||
| 200 | +// @tc.expect: Verification fails with error code 401 | ||
| 201 | +// @tc.type: FUNC | ||
| 202 | +// @tc.require: issueNumber | ||
| 203 | + | ||
| 204 | +fn ut_timeout_verifier_zero_total_timeout() { | ||
| 205 | + let verifier = TimeoutVerifier {}; | ||
| 206 | + let config = create_config_with_timeout(1, 0); | ||
| 207 | + let result = verifier.verify(&config); | ||
| 208 | + assert!(result.is_err()); | ||
| 209 | + assert_eq!(result.unwrap_err(), 401); | ||
| 210 | +} | ||
| 211 | + | ||
| 212 | +// @tc.name: ut_timeout_verifier_max_total_timeout | ||
| 213 | +// @tc.desc: Test TimeoutVerifier with maximum total timeout | ||
| 214 | +// @tc.precon: NA | ||
| 215 | +// @tc.step: 1. Create TimeoutVerifier | ||
| 216 | +// 2. Create TaskConfig with maximum total timeout (604800) | ||
| 217 | +// 3. Verify config passes validation | ||
| 218 | +// @tc.expect: Verification passes for maximum total timeout | ||
| 219 | +// @tc.type: FUNC | ||
| 220 | +// @tc.require: issueNumber | ||
| 221 | + | ||
| 222 | +fn ut_timeout_verifier_max_total_timeout() { | ||
| 223 | + let verifier = TimeoutVerifier {}; | ||
| 224 | + let config = create_config_with_timeout(1, 604800); | ||
| 225 | + assert!(verifier.verify(&config).is_ok()); | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +// @tc.name: ut_timeout_verifier_exceed_max_total_timeout | ||
| 229 | +// @tc.desc: Test TimeoutVerifier with total timeout exceeding max | ||
| 230 | +// @tc.precon: NA | ||
| 231 | +// @tc.step: 1. Create TimeoutVerifier | ||
| 232 | +// 2. Create TaskConfig with total timeout exceeding max (604801) | ||
| 233 | +// 3. Verify config fails validation | ||
| 234 | +// @tc.expect: Verification fails with error code 401 | ||
| 235 | +// @tc.type: FUNC | ||
| 236 | +// @tc.require: issueNumber | ||
| 237 | + | ||
| 238 | +fn ut_timeout_verifier_exceed_max_total_timeout() { | ||
| 239 | + let verifier = TimeoutVerifier {}; | ||
| 240 | + let config = create_config_with_timeout(1, 604801); | ||
| 241 | + let result = verifier.verify(&config); | ||
| 242 | + assert!(result.is_err()); | ||
| 243 | + assert_eq!(result.unwrap_err(), 401); | ||
| 244 | +} | ||
| @@ -0,0 +1,171 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::{title::TitleVerifier, description::DescriptionVerifier, ConfigVerifier}; | ||
| 16 | + | ||
| 17 | +// ==================== TitleVerifier Tests ==================== | ||
| 18 | + | ||
| 19 | +fn create_config_with_title(version: Version, title: &str) -> TaskConfig { | ||
| 20 | + TaskConfigBuilder::new(version) | ||
| 21 | + .url("https://example.com/test".to_string()) | ||
| 22 | + .title(title.to_string()) | ||
| 23 | + .build() | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +// @tc.name: ut_title_verifier_api9_long_title | ||
| 27 | +// @tc.desc: Test TitleVerifier with API9 version ignores title length | ||
| 28 | +// @tc.precon: NA | ||
| 29 | +// @tc.step: 1. Create TitleVerifier | ||
| 30 | +// 2. Create TaskConfig with API9 version and long title (300 chars) | ||
| 31 | +// 3. Verify config passes validation | ||
| 32 | +// @tc.expect: Verification passes for API9 with any title length | ||
| 33 | +// @tc.type: FUNC | ||
| 34 | +// @tc.require: issueNumber | ||
| 35 | + | ||
| 36 | +fn ut_title_verifier_api9_long_title() { | ||
| 37 | + let verifier = TitleVerifier {}; | ||
| 38 | + let long_title = "a".repeat(300); | ||
| 39 | + let config = create_config_with_title(Version::API9, &long_title); | ||
| 40 | + assert!(verifier.verify(&config).is_ok()); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// @tc.name: ut_title_verifier_api10_valid_title | ||
| 44 | +// @tc.desc: Test TitleVerifier with API10 and valid title | ||
| 45 | +// @tc.precon: NA | ||
| 46 | +// @tc.step: 1. Create TitleVerifier | ||
| 47 | +// 2. Create TaskConfig with API10 version and valid title | ||
| 48 | +// 3. Verify config passes validation | ||
| 49 | +// @tc.expect: Verification passes for API10 with valid title | ||
| 50 | +// @tc.type: FUNC | ||
| 51 | +// @tc.require: issueNumber | ||
| 52 | + | ||
| 53 | +fn ut_title_verifier_api10_valid_title() { | ||
| 54 | + let verifier = TitleVerifier {}; | ||
| 55 | + let config = create_config_with_title(Version::API10, "Test Download Task"); | ||
| 56 | + assert!(verifier.verify(&config).is_ok()); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// @tc.name: ut_title_verifier_api10_max_length_title | ||
| 60 | +// @tc.desc: Test TitleVerifier with API10 and max length title | ||
| 61 | +// @tc.precon: NA | ||
| 62 | +// @tc.step: 1. Create TitleVerifier | ||
| 63 | +// 2. Create TaskConfig with API10 version and max length title (256 chars) | ||
| 64 | +// 3. Verify config passes validation | ||
| 65 | +// @tc.expect: Verification passes for API10 with max length title | ||
| 66 | +// @tc.type: FUNC | ||
| 67 | +// @tc.require: issueNumber | ||
| 68 | + | ||
| 69 | +fn ut_title_verifier_api10_max_length_title() { | ||
| 70 | + let verifier = TitleVerifier {}; | ||
| 71 | + let max_title = "a".repeat(256); | ||
| 72 | + let config = create_config_with_title(Version::API10, &max_title); | ||
| 73 | + assert!(verifier.verify(&config).is_ok()); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +// @tc.name: ut_title_verifier_api10_exceed_max_length | ||
| 77 | +// @tc.desc: Test TitleVerifier with API10 and title exceeding max length | ||
| 78 | +// @tc.precon: NA | ||
| 79 | +// @tc.step: 1. Create TitleVerifier | ||
| 80 | +// 2. Create TaskConfig with API10 version and title exceeding max length (257 chars) | ||
| 81 | +// 3. Verify config fails validation | ||
| 82 | +// @tc.expect: Verification fails with error code 401 | ||
| 83 | +// @tc.type: FUNC | ||
| 84 | +// @tc.require: issueNumber | ||
| 85 | + | ||
| 86 | +fn ut_title_verifier_api10_exceed_max_length() { | ||
| 87 | + let verifier = TitleVerifier {}; | ||
| 88 | + let long_title = "a".repeat(257); | ||
| 89 | + let config = create_config_with_title(Version::API10, &long_title); | ||
| 90 | + let result = verifier.verify(&config); | ||
| 91 | + assert!(result.is_err()); | ||
| 92 | + assert_eq!(result.unwrap_err(), 401); | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +// ==================== DescriptionVerifier Tests ==================== | ||
| 96 | + | ||
| 97 | +fn create_config_with_description(version: Version, description: &str) -> TaskConfig { | ||
| 98 | + TaskConfigBuilder::new(version) | ||
| 99 | + .url("https://example.com/test".to_string()) | ||
| 100 | + .description(description.to_string()) | ||
| 101 | + .build() | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +// @tc.name: ut_description_verifier_api9_long_description | ||
| 105 | +// @tc.desc: Test DescriptionVerifier with API9 version ignores description length | ||
| 106 | +// @tc.precon: NA | ||
| 107 | +// @tc.step: 1. Create DescriptionVerifier | ||
| 108 | +// 2. Create TaskConfig with API9 version and long description (2000 chars) | ||
| 109 | +// 3. Verify config passes validation | ||
| 110 | +// @tc.expect: Verification passes for API9 with any description length | ||
| 111 | +// @tc.type: FUNC | ||
| 112 | +// @tc.require: issueNumber | ||
| 113 | + | ||
| 114 | +fn ut_description_verifier_api9_long_description() { | ||
| 115 | + let verifier = DescriptionVerifier {}; | ||
| 116 | + let long_description = "a".repeat(2000); | ||
| 117 | + let config = create_config_with_description(Version::API9, &long_description); | ||
| 118 | + assert!(verifier.verify(&config).is_ok()); | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +// @tc.name: ut_description_verifier_api10_valid_description | ||
| 122 | +// @tc.desc: Test DescriptionVerifier with API10 and valid description | ||
| 123 | +// @tc.precon: NA | ||
| 124 | +// @tc.step: 1. Create DescriptionVerifier | ||
| 125 | +// 2. Create TaskConfig with API10 version and valid description | ||
| 126 | +// 3. Verify config passes validation | ||
| 127 | +// @tc.expect: Verification passes for API10 with valid description | ||
| 128 | +// @tc.type: FUNC | ||
| 129 | +// @tc.require: issueNumber | ||
| 130 | + | ||
| 131 | +fn ut_description_verifier_api10_valid_description() { | ||
| 132 | + let verifier = DescriptionVerifier {}; | ||
| 133 | + let config = create_config_with_description(Version::API10, "Test download task description"); | ||
| 134 | + assert!(verifier.verify(&config).is_ok()); | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +// @tc.name: ut_description_verifier_api10_max_length_description | ||
| 138 | +// @tc.desc: Test DescriptionVerifier with API10 and max length description | ||
| 139 | +// @tc.precon: NA | ||
| 140 | +// @tc.step: 1. Create DescriptionVerifier | ||
| 141 | +// 2. Create TaskConfig with API10 version and max length description (1024 chars) | ||
| 142 | +// 3. Verify config passes validation | ||
| 143 | +// @tc.expect: Verification passes for API10 with max length description | ||
| 144 | +// @tc.type: FUNC | ||
| 145 | +// @tc.require: issueNumber | ||
| 146 | + | ||
| 147 | +fn ut_description_verifier_api10_max_length_description() { | ||
| 148 | + let verifier = DescriptionVerifier {}; | ||
| 149 | + let max_description = "a".repeat(1024); | ||
| 150 | + let config = create_config_with_description(Version::API10, &max_description); | ||
| 151 | + assert!(verifier.verify(&config).is_ok()); | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +// @tc.name: ut_description_verifier_api10_exceed_max_length | ||
| 155 | +// @tc.desc: Test DescriptionVerifier with API10 and description exceeding max length | ||
| 156 | +// @tc.precon: NA | ||
| 157 | +// @tc.step: 1. Create DescriptionVerifier | ||
| 158 | +// 2. Create TaskConfig with API10 version and description exceeding max length (1025 chars) | ||
| 159 | +// 3. Verify config fails validation | ||
| 160 | +// @tc.expect: Verification fails with error code 401 | ||
| 161 | +// @tc.type: FUNC | ||
| 162 | +// @tc.require: issueNumber | ||
| 163 | + | ||
| 164 | +fn ut_description_verifier_api10_exceed_max_length() { | ||
| 165 | + let verifier = DescriptionVerifier {}; | ||
| 166 | + let long_description = "a".repeat(1025); | ||
| 167 | + let config = create_config_with_description(Version::API10, &long_description); | ||
| 168 | + let result = verifier.verify(&config); | ||
| 169 | + assert!(result.is_err()); | ||
| 170 | + assert_eq!(result.unwrap_err(), 401); | ||
| 171 | +} | ||
| @@ -0,0 +1,161 @@ | |||
| 1 | +// Copyright (C) 2025 Huawei Device Co., Ltd. | ||
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +// you may not use this file except in compliance with the License. | ||
| 4 | +// You may obtain a copy of the License at | ||
| 5 | +// | ||
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +// | ||
| 8 | +// Unless required by applicable law or agreed to in writing, software | ||
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +// See the License for the specific language governing permissions and | ||
| 12 | +// limitations under the License. | ||
| 13 | + | ||
| 14 | +use request_core::config::{TaskConfig, TaskConfigBuilder, Version}; | ||
| 15 | +use request_client::verify::url::{get_hostname_from_url, UrlVerifier}; | ||
| 16 | +use request_client::verify::ConfigVerifier; | ||
| 17 | + | ||
| 18 | +fn create_config_with_url(url: &str) -> TaskConfig { | ||
| 19 | + let mut config = TaskConfigBuilder::new(Version::API10).build(); | ||
| 20 | + config.url = url.to_string(); | ||
| 21 | + config | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +// @tc.name: ut_url_verifier_valid_https_url | ||
| 25 | +// @tc.desc: Test UrlVerifier with valid HTTPS URL | ||
| 26 | +// @tc.precon: NA | ||
| 27 | +// @tc.step: 1. Create UrlVerifier | ||
| 28 | +// 2. Create TaskConfig with valid HTTPS URL | ||
| 29 | +// 3. Verify config passes validation | ||
| 30 | +// @tc.expect: Verification passes for valid HTTPS URL | ||
| 31 | +// @tc.type: FUNC | ||
| 32 | +// @tc.require: issueNumber | ||
| 33 | + | ||
| 34 | +fn ut_url_verifier_valid_https_url() { | ||
| 35 | + let verifier = UrlVerifier {}; | ||
| 36 | + let config = create_config_with_url("https://example.com/path/to/file"); | ||
| 37 | + assert!(verifier.verify(&config).is_ok()); | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +// @tc.name: ut_url_verifier_valid_http_url | ||
| 41 | +// @tc.desc: Test UrlVerifier with valid HTTP URL | ||
| 42 | +// @tc.precon: NA | ||
| 43 | +// @tc.step: 1. Create UrlVerifier | ||
| 44 | +// 2. Create TaskConfig with valid HTTP URL | ||
| 45 | +// 3. Verify config passes validation | ||
| 46 | +// @tc.expect: Verification passes for valid HTTP URL | ||
| 47 | +// @tc.type: FUNC | ||
| 48 | +// @tc.require: issueNumber | ||
| 49 | + | ||
| 50 | +fn ut_url_verifier_valid_http_url() { | ||
| 51 | + let verifier = UrlVerifier {}; | ||
| 52 | + let config = create_config_with_url("http://example.com/path/to/file"); | ||
| 53 | + assert!(verifier.verify(&config).is_ok()); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// @tc.name: ut_url_verifier_invalid_scheme | ||
| 57 | +// @tc.desc: Test UrlVerifier with invalid URL scheme | ||
| 58 | +// @tc.precon: NA | ||
| 59 | +// @tc.step: 1. Create UrlVerifier | ||
| 60 | +// 2. Create TaskConfig with FTP URL scheme | ||
| 61 | +// 3. Verify config fails validation | ||
| 62 | +// @tc.expect: Verification fails with error code 401 | ||
| 63 | +// @tc.type: FUNC | ||
| 64 | +// @tc.require: issueNumber | ||
| 65 | + | ||
| 66 | +fn ut_url_verifier_invalid_scheme() { | ||
| 67 | + let verifier = UrlVerifier {}; | ||
| 68 | + let config = create_config_with_url("ftp://example.com/file"); | ||
| 69 | + let result = verifier.verify(&config); | ||
| 70 | + assert!(result.is_err()); | ||
| 71 | + assert_eq!(result.unwrap_err(), 401); | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +// @tc.name: ut_url_verifier_empty_url | ||
| 75 | +// @tc.desc: Test UrlVerifier with empty URL | ||
| 76 | +// @tc.precon: NA | ||
| 77 | +// @tc.step: 1. Create UrlVerifier | ||
| 78 | +// 2. Create TaskConfig with empty URL | ||
| 79 | +// 3. Verify config fails validation | ||
| 80 | +// @tc.expect: Verification fails with error code 401 | ||
| 81 | +// @tc.type: FUNC | ||
| 82 | +// @tc.require: issueNumber | ||
| 83 | + | ||
| 84 | +fn ut_url_verifier_empty_url() { | ||
| 85 | + let verifier = UrlVerifier {}; | ||
| 86 | + let config = create_config_with_url(""); | ||
| 87 | + let result = verifier.verify(&config); | ||
| 88 | + assert!(result.is_err()); | ||
| 89 | + assert_eq!(result.unwrap_err(), 401); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +// @tc.name: ut_url_verifier_exceed_max_length | ||
| 93 | +// @tc.desc: Test UrlVerifier with URL exceeding max length | ||
| 94 | +// @tc.precon: NA | ||
| 95 | +// @tc.step: 1. Create UrlVerifier | ||
| 96 | +// 2. Create TaskConfig with URL exceeding max length | ||
| 97 | +// 3. Verify config fails validation | ||
| 98 | +// @tc.expect: Verification fails with error code 401 | ||
| 99 | +// @tc.type: FUNC | ||
| 100 | +// @tc.require: issueNumber | ||
| 101 | + | ||
| 102 | +fn ut_url_verifier_exceed_max_length() { | ||
| 103 | + let verifier = UrlVerifier {}; | ||
| 104 | + let long_url = format!("https://example.com/{}", "a".repeat(8192)); | ||
| 105 | + let config = create_config_with_url(&long_url); | ||
| 106 | + let result = verifier.verify(&config); | ||
| 107 | + assert!(result.is_err()); | ||
| 108 | + assert_eq!(result.unwrap_err(), 401); | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +// @tc.name: ut_get_hostname_from_url_standard | ||
| 112 | +// @tc.desc: Test get_hostname_from_url with standard URL | ||
| 113 | +// @tc.precon: NA | ||
| 114 | +// @tc.step: 1. Call get_hostname_from_url with standard HTTPS URL | ||
| 115 | +// 2. Verify hostname is extracted correctly | ||
| 116 | +// @tc.expect: Hostname is extracted as "example.com" | ||
| 117 | +// @tc.type: FUNC | ||
| 118 | +// @tc.require: issueNumber | ||
| 119 | + | ||
| 120 | +fn ut_get_hostname_from_url_standard() { | ||
| 121 | + assert_eq!(get_hostname_from_url("https://example.com/path"), "example.com"); | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +// @tc.name: ut_get_hostname_from_url_with_port | ||
| 125 | +// @tc.desc: Test get_hostname_from_url with URL containing port | ||
| 126 | +// @tc.precon: NA | ||
| 127 | +// @tc.step: 1. Call get_hostname_from_url with URL containing port | ||
| 128 | +// 2. Verify hostname is extracted correctly without port | ||
| 129 | +// @tc.expect: Hostname is extracted as "example.com" | ||
| 130 | +// @tc.type: FUNC | ||
| 131 | +// @tc.require: issueNumber | ||
| 132 | + | ||
| 133 | +fn ut_get_hostname_from_url_with_port() { | ||
| 134 | + assert_eq!(get_hostname_from_url("https://example.com:8080/path"), "example.com"); | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +// @tc.name: ut_get_hostname_from_url_empty | ||
| 138 | +// @tc.desc: Test get_hostname_from_url with empty URL | ||
| 139 | +// @tc.precon: NA | ||
| 140 | +// @tc.step: 1. Call get_hostname_from_url with empty URL | ||
| 141 | +// 2. Verify empty string is returned | ||
| 142 | +// @tc.expect: Empty string is returned | ||
| 143 | +// @tc.type: FUNC | ||
| 144 | +// @tc.require: issueNumber | ||
| 145 | + | ||
| 146 | +fn ut_get_hostname_from_url_empty() { | ||
| 147 | + assert_eq!(get_hostname_from_url(""), ""); | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +// @tc.name: ut_get_hostname_from_url_ip_address | ||
| 151 | +// @tc.desc: Test get_hostname_from_url with IP address | ||
| 152 | +// @tc.precon: NA | ||
| 153 | +// @tc.step: 1. Call get_hostname_from_url with IP address URL | ||
| 154 | +// 2. Verify IP address is extracted correctly | ||
| 155 | +// @tc.expect: IP address is extracted as "192.168.1.1" | ||
| 156 | +// @tc.type: FUNC | ||
| 157 | +// @tc.require: issueNumber | ||
| 158 | + | ||
| 159 | +fn ut_get_hostname_from_url_ip_address() { | ||
| 160 | + assert_eq!(get_hostname_from_url("https://192.168.1.1:8080/path"), "192.168.1.1"); | ||
| 161 | +} | ||