blob: 255d4de3f5a697856a079b104b3425c2162fcf4b [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>
Zhuoyao Zhang3c3b0002018-02-28 18:04:10 -080020#include <VtsHalHidlTargetTestEnvBase.h>
Andrew Scull70934312018-01-03 11:51:54 +000021
22using ::android::hardware::hidl_vec;
23using ::android::hardware::authsecret::V1_0::IAuthSecret;
24using ::android::sp;
25
Zhuoyao Zhang3c3b0002018-02-28 18:04:10 -080026// Test environment for Boot HIDL HAL.
27class AuthSecretHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
28 public:
29 // get the test environment singleton
30 static AuthSecretHidlEnvironment* Instance() {
31 static AuthSecretHidlEnvironment* instance = new AuthSecretHidlEnvironment;
32 return instance;
33 }
34
35 virtual void registerTestServices() override { registerTestService<IAuthSecret>(); }
36
37 private:
38 AuthSecretHidlEnvironment() {}
39};
40
Andrew Scull70934312018-01-03 11:51:54 +000041/**
42 * There is no expected behaviour that can be tested so these tests check the
43 * HAL doesn't crash with different execution orders.
44 */
45struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase {
46 virtual void SetUp() override {
Zhuoyao Zhang3c3b0002018-02-28 18:04:10 -080047 authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>(
48 AuthSecretHidlEnvironment::Instance()->getServiceName<IAuthSecret>());
Andrew Scull70934312018-01-03 11:51:54 +000049 ASSERT_NE(authsecret, nullptr);
Andrew Scullbd4e48c2018-01-19 19:17:56 +000050
51 // All tests must enroll the correct secret first as this cannot be changed
52 // without a factory reset and the order of tests could change.
53 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000054 }
55
56 sp<IAuthSecret> authsecret;
Andrew Scullbd4e48c2018-01-19 19:17:56 +000057 hidl_vec<uint8_t> CORRECT_SECRET{61, 93, 124, 240, 5, 0, 7, 201, 9, 129, 11, 12, 0, 14, 0, 16};
58 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 +000059};
60
61/* Provision the primary user with a secret. */
62TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredential) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000063 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000064}
65
66/* Provision the primary user with a secret and pass the secret again. */
67TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000068 // Secret provisioned by SetUp()
69 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000070}
71
72/* Provision the primary user with a secret and pass the secret again repeatedly. */
73TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000074 // Secret provisioned by SetUp()
Andrew Scull70934312018-01-03 11:51:54 +000075 constexpr int N = 5;
76 for (int i = 0; i < N; ++i) {
Andrew Scullbd4e48c2018-01-19 19:17:56 +000077 authsecret->primaryUserCredential(CORRECT_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000078 }
79}
80
Andrew Scullbd4e48c2018-01-19 19:17:56 +000081/* Provision the primary user with a secret and then pass the wrong secret. This
82 * should never happen and is an framework bug if it does. As the secret is
83 * wrong, the HAL implementation may not be able to function correctly but it
84 * should fail gracefully. */
85TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
86 // Secret provisioned by SetUp()
87 authsecret->primaryUserCredential(WRONG_SECRET);
Andrew Scull70934312018-01-03 11:51:54 +000088}
Zhuoyao Zhang3c3b0002018-02-28 18:04:10 -080089
90int main(int argc, char** argv) {
91 ::testing::AddGlobalTestEnvironment(AuthSecretHidlEnvironment::Instance());
92 ::testing::InitGoogleTest(&argc, argv);
93 AuthSecretHidlEnvironment::Instance()->init(&argc, argv);
94 int status = RUN_ALL_TESTS();
95 ALOGI("Test result = %d", status);
96 return status;
97}