blob: 687c70cb88d4964345a4549173874528abac34c9 [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
nelsonliff4de282019-10-15 17:09:04 +080019#include <gtest/gtest.h>
20#include <hidl/GtestPrinter.h>
21#include <hidl/ServiceManagement.h>
Andrew Scull70934312018-01-03 11:51:54 +000022
23using ::android::hardware::hidl_vec;
24using ::android::hardware::authsecret::V1_0::IAuthSecret;
25using ::android::sp;
26
27/**
28 * There is no expected behaviour that can be tested so these tests check the
29 * HAL doesn't crash with different execution orders.
30 */
nelsonliff4de282019-10-15 17:09:04 +080031class AuthSecretHidlTest : public testing::TestWithParam<std::string> {
32 public:
Andrew Scull70934312018-01-03 11:51:54 +000033 virtual void SetUp() override {
nelsonliff4de282019-10-15 17:09:04 +080034 authsecret = IAuthSecret::getService(GetParam());
Andrew Scull70934312018-01-03 11:51:54 +000035 ASSERT_NE(authsecret, nullptr);
Andrew Scullbd4e48c2018-01-19 19:17:56 +000036
37 // All tests must enroll the correct secret first as this cannot be changed
38 // without a factory reset and the order of tests could change.
39 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000040 }
41
42 sp<IAuthSecret> authsecret;
Andrew Scullbd4e48c2018-01-19 19:17:56 +000043 hidl_vec<uint8_t> CORRECT_SECRET{61, 93, 124, 240, 5, 0, 7, 201, 9, 129, 11, 12, 0, 14, 0, 16};
44 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 +000045};
46
47/* Provision the primary user with a secret. */
nelsonliff4de282019-10-15 17:09:04 +080048TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredential) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000049 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000050}
51
52/* Provision the primary user with a secret and pass the secret again. */
nelsonliff4de282019-10-15 17:09:04 +080053TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000054 // Secret provisioned by SetUp()
55 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000056}
57
58/* Provision the primary user with a secret and pass the secret again repeatedly. */
nelsonliff4de282019-10-15 17:09:04 +080059TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000060 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000061 constexpr int N = 5;
62 for (int i = 0; i < N; ++i) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000063 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000064 }
65}
66
Andrew Scullbd4e48c2018-01-19 19:17:56 +000067/* Provision the primary user with a secret and then pass the wrong secret. This
68 * should never happen and is an framework bug if it does. As the secret is
69 * wrong, the HAL implementation may not be able to function correctly but it
70 * should fail gracefully. */
nelsonliff4de282019-10-15 17:09:04 +080071TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000072 // Secret provisioned by SetUp()
73 authsecret->primaryUserCredential(WRONG_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000074}
Zhuoyao Zhang3c3b0002018-02-28 18:04:10 -080075
Dan Shiba4d5322020-07-28 13:09:30 -070076GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AuthSecretHidlTest);
nelsonliff4de282019-10-15 17:09:04 +080077INSTANTIATE_TEST_SUITE_P(
78 PerInstance, AuthSecretHidlTest,
79 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IAuthSecret::descriptor)),
80 android::hardware::PrintInstanceNameToString);