diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-07-18 03:05:58 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-07-18 03:05:58 +0000 |
commit | 3d680407311f214514d2de06fd042f5765b9ff65 (patch) | |
tree | 42aa4b15944385f1dd4590c1628697e9f2bb01ee | |
parent | 7ba30df1c855b26ad01b4712a541a26ff4597600 (diff) | |
parent | da7a2cdecabe0440f8757531732e355a3cdb68ee (diff) | |
download | system-test-harness-3d680407311f214514d2de06fd042f5765b9ff65.tar.gz |
Snap for 5736565 from da7a2cdecabe0440f8757531732e355a3cdb68ee to qt-c2f2-release
Change-Id: I71874e7c1e8f2ed71b498acc4e60f85a5f2d8cc9
-rw-r--r-- | src/faceauth_tests.cc | 53 | ||||
-rw-r--r-- | src/nugget_core_tests.cc | 5 |
2 files changed, 40 insertions, 18 deletions
diff --git a/src/faceauth_tests.cc b/src/faceauth_tests.cc index 5aff16e..629a57d 100644 --- a/src/faceauth_tests.cc +++ b/src/faceauth_tests.cc @@ -16,18 +16,19 @@ using std::unique_ptr; namespace { -const uint8_t EMBEDDING_VECTOR_NULL = 0x0; -const uint8_t EMBEDDING_VECTOR_1 = 0x11; -const uint8_t EMBEDDING_VECTOR_2 = 0xAA; +vector<uint8_t> EMBEDDING_VECTOR_NULL(128, 0); +const vector<uint8_t> EMBEDDING_VECTOR_1(64, 16); +const vector<uint8_t> EMBEDDING_VECTOR_2(64, (uint8_t)-16); + +const uint32_t PROFILE_1 = 1; +const uint32_t PROFILE_2 = 2; +const uint32_t PROFILE_3 = 3; +const uint32_t PROFILE_4 = 4; +const uint32_t PROFILE_5 = 5; +const uint32_t PROFILE_6 = 6; class FaceAuthTest: public testing::Test { public: - const uint32_t PROFILE_1 = 1; - const uint32_t PROFILE_2 = 2; - const uint32_t PROFILE_3 = 3; - const uint32_t PROFILE_4 = 4; - const uint32_t PROFILE_5 = 5; - const uint32_t PROFILE_6 = 6; static unique_ptr<nos::NuggetClientInterface> client; static unique_ptr<test_harness::TestHarness> uart_printer; @@ -36,6 +37,7 @@ class FaceAuthTest: public testing::Test { static void SetUpTestCase(); static void TearDownTestCase(); + static void DisengageGlobalLockout(); }; unique_ptr<nos::NuggetClientInterface> FaceAuthTest::client; @@ -48,6 +50,10 @@ void FaceAuthTest::SetUpTestCase() { client = nugget_tools::MakeNuggetClient(); client->Open(); EXPECT_TRUE(client->IsOpen()) << "Unable to connect"; + + /* We need any embedding vector to have magnitude of 128 */ + EMBEDDING_VECTOR_NULL[127] = 128; + DisengageGlobalLockout(); } void FaceAuthTest::TearDownTestCase() { @@ -117,10 +123,12 @@ class Task { class Embedding { public: Embedding() { memset(&embed, 0, sizeof(embed)); } - Embedding(uint8_t base, uint32_t version = 1) { - memset(&embed, base, sizeof(embed)); + Embedding(vector<uint8_t> base, uint32_t version = 1) { + memset(&embed, 0, sizeof(embed)); embed.version = version; embed.valid = 0; + std::copy(base.begin(), base.end(), &embed.face_id[0]); + std::copy(base.begin(), base.end(), &embed.depth_id[0]); } void Finalize() { @@ -395,6 +403,19 @@ void FaceAuthTest::SetUp() { EXPECT_REQ(Device::Erase(i + 1), Result(FACEAUTH_SUCCESS)); } +void FaceAuthTest::DisengageGlobalLockout() { + /* Send Auth Token */ + Result generate_result = Device::GenerateChallenge(); + EXPECT_REQ(generate_result, + Result(FACEAUTH_SUCCESS).SetChallenge(Device::GetChallenge())); + EXPECT_REQ(Transaction(Task(PROFILE_1, FACEAUTH_CMD_ENROLL).Finalize(), + Embedding(EMBEDDING_VECTOR_1, 1), + Token(Device::GetChallenge(), 0, 0)) + .Run() + .GetResult(), + Result(FACEAUTH_ERR_CRC)); +} + TEST_F(FaceAuthTest, OldFirmwareVersionShouldError) { EXPECT_REQ(Transaction(Task(PROFILE_1, FACEAUTH_CMD_ERASE, FACEAUTH_MIN_ABH_VERSION - 0x100), @@ -541,7 +562,7 @@ TEST_F(FaceAuthTest, ValidProfileIDTest) { class User { public: - User(uint8_t embed_base) : embed_base(embed_base) { + User(vector<uint8_t> embed_base) : embed_base(embed_base) { user_id = rand(); user_id <<= 32; user_id += rand(); @@ -552,7 +573,7 @@ class User { return *this; } - User& SetEmbeddingBase(uint8_t base) { + User& SetEmbeddingBase(vector<uint8_t> base) { embed_base = base; return *this; } @@ -643,7 +664,7 @@ class User { } void LockProfile(uint32_t profile_id) { - uint8_t original_embed_base = embed_base; + vector<uint8_t> original_embed_base = embed_base; embed_base = EMBEDDING_VECTOR_NULL; /* Fail Authentication 4 times */ for (int i = 0; i < 4; ++i) { @@ -708,7 +729,7 @@ class User { uint64_t operation_id; uint64_t auth_id = 0; uint64_t user_id; - uint8_t embed_base; + vector<uint8_t> embed_base; uint8_t embed_version; }; @@ -1048,7 +1069,7 @@ TEST_F(FaceAuthTest, ExhaustiveLockoutTest) { vector<User> users; for (int i = 0; i < MAX_NUM_PROFILES; ++i) { - users.push_back(User(EMBEDDING_VECTOR_NULL).SetEmbeddingVersion(1)); + users.push_back(User(EMBEDDING_VECTOR_1).SetEmbeddingVersion(1)); Result enroll_result = users[i].Enroll(i + 1); EXPECT_REQ(enroll_result, Result(FACEAUTH_SUCCESS).SetChallenge(users[i].GetAuthID())); diff --git a/src/nugget_core_tests.cc b/src/nugget_core_tests.cc index 5fc06e0..e0e95bb 100644 --- a/src/nugget_core_tests.cc +++ b/src/nugget_core_tests.cc @@ -94,9 +94,10 @@ TEST_F(NuggetCoreTest, GetLowPowerStats) { ASSERT_NO_ERROR(NuggetCoreTest::client->CallApp( APP_ID_NUGGET, NUGGET_PARAM_GET_LOW_POWER_STATS, buffer, &buffer), ""); - ASSERT_GE(buffer.size(), sizeof(stats)); + ASSERT_GE(buffer.size(), sizeof(uint64_t) * 8); // was 8, now 10, both okay - memcpy(&stats, buffer.data(), sizeof(stats)); + memset(&stats, 0, sizeof(stats)); + memcpy(&stats, buffer.data(), std::min(sizeof(stats), buffer.size())); /* We must have booted once and been awake long enough to reply, but that's * about all we can be certain of. */ |