blob: a610a755bfd6ad0adb2515ed32065fe63c0e4edc [file] [log] [blame]
Andrew Scull70934312018-01-03 11:51:54 +00001/*
2 * Copyright (C) 2018 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#include <android/hardware/authsecret/1.0/IAuthSecret.h>
18
19#include <VtsHalHidlTargetTestBase.h>
20
21using ::android::hardware::hidl_vec;
22using ::android::hardware::authsecret::V1_0::IAuthSecret;
23using ::android::sp;
24
25/**
26 * There is no expected behaviour that can be tested so these tests check the
27 * HAL doesn't crash with different execution orders.
28 */
29struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase {
30 virtual void SetUp() override {
31 authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>();
32 ASSERT_NE(authsecret, nullptr);
Andrew Scullbd4e48c2018-01-19 19:17:56 +000033
34 // All tests must enroll the correct secret first as this cannot be changed
35 // without a factory reset and the order of tests could change.
36 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000037 }
38
39 sp<IAuthSecret> authsecret;
Andrew Scullbd4e48c2018-01-19 19:17:56 +000040 hidl_vec<uint8_t> CORRECT_SECRET{61, 93, 124, 240, 5, 0, 7, 201, 9, 129, 11, 12, 0, 14, 0, 16};
41 hidl_vec<uint8_t> WRONG_SECRET{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
Andrew Scull70934312018-01-03 11:51:54 +000042};
43
44/* Provision the primary user with a secret. */
45TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredential) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000046 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000047}
48
49/* Provision the primary user with a secret and pass the secret again. */
50TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000051 // Secret provisioned by SetUp()
52 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000053}
54
55/* Provision the primary user with a secret and pass the secret again repeatedly. */
56TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000057 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000058 constexpr int N = 5;
59 for (int i = 0; i < N; ++i) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000060 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000061 }
62}
63
Andrew Scullbd4e48c2018-01-19 19:17:56 +000064/* Provision the primary user with a secret and then pass the wrong secret. This
65 * should never happen and is an framework bug if it does. As the secret is
66 * wrong, the HAL implementation may not be able to function correctly but it
67 * should fail gracefully. */
68TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
69 // Secret provisioned by SetUp()
70 authsecret->primaryUserCredential(WRONG_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000071}