1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #[cfg(test)]
18 mod tests {
19     use tipc::{Handle, TipcError};
20     use trusty_std::ffi::{CString, FallibleCString};
21 
22     test::init!();
23 
24     #[test]
test_access_policy_unauthorized()25     fn test_access_policy_unauthorized() {
26         if !cfg!(kmr_enabled) {
27             test::skip!("KeyMint Rust TA not configured");
28         }
29 
30         /// Port that handles secure world messages
31         const KM_SEC_TIPC_SRV_PORT: &str = "com.android.trusty.keymaster.secure";
32 
33         let port2 = CString::try_new(KM_SEC_TIPC_SRV_PORT).unwrap();
34         let err1 = Handle::connect(port2.as_c_str()).expect_err(
35             "An error is expected because the uuid of this test app is
36                           not in the allowed uuid list of the keymint access policy.",
37         );
38         assert_eq!(err1, TipcError::SystemError(trusty_sys::Error::ChannelClosed));
39     }
40 }
41