1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 use crate::common::*;
17 use asset_sdk::*;
18
19 #[test]
post_query_non_exist_with_auth_challenge()20 fn post_query_non_exist_with_auth_challenge() {
21 let mut query = AssetMap::new();
22 query.insert_attr(Tag::AuthChallenge, vec![0; CHALLENGE_SIZE]);
23 assert!(asset_sdk::Manager::build().unwrap().post_query(&query).is_ok());
24 }
25
26 #[test]
post_query_with_wrong_auth_challenge()27 fn post_query_with_wrong_auth_challenge() {
28 let function_name = function!().as_bytes();
29 add_default_auth_asset(function_name, function_name).unwrap();
30
31 let mut query = AssetMap::new();
32 let challenge = asset_sdk::Manager::build().unwrap().pre_query(&query).unwrap();
33
34 query.insert_attr(Tag::AuthChallenge, vec![0; CHALLENGE_SIZE]);
35 assert!(asset_sdk::Manager::build().unwrap().post_query(&query).is_ok());
36
37 query.insert_attr(Tag::AuthChallenge, challenge);
38 asset_sdk::Manager::build().unwrap().post_query(&query).unwrap();
39 remove_by_alias(function_name).unwrap();
40 }
41
42 #[test]
post_query_normal()43 fn post_query_normal() {
44 let function_name = function!().as_bytes();
45 add_default_auth_asset(function_name, function_name).unwrap();
46
47 let mut query = AssetMap::new();
48 let challenge = asset_sdk::Manager::build().unwrap().pre_query(&query).unwrap();
49
50 query.insert_attr(Tag::AuthChallenge, challenge);
51 assert!(asset_sdk::Manager::build().unwrap().post_query(&query).is_ok());
52 remove_by_alias(function_name).unwrap();
53 }
54