summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2015-03-06 10:55:18 -0800
committerAndres Morales <anmorales@google.com>2015-03-09 12:36:11 -0700
commit99482129e592892ef40613195d2cbcd640e031cd (patch)
tree5e74836445d23e8fad437885de90b4eb2a544e14 /tests
parentb2abaa89b8090c7f14048d4404a3eb146f709a6a (diff)
downloadgatekeeper-99482129e592892ef40613195d2cbcd640e031cd.tar.gz
SoftKeyguard module
hw module piping for sw based keyguard Change-Id: I335e09180e59b4d4e4fdbd1c35970d58cded3b1b
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.mk5
-rw-r--r--tests/keyguard_device_test.cpp91
2 files changed, 94 insertions, 2 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
index cca7038..fff72ca 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -20,10 +20,11 @@ include $(CLEAR_VARS)
LOCAL_MODULE := keyguard-unit-tests
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_CFLAGS += -g -Wall -Werror -std=gnu++11 -Wno-missing-field-initializers
-LOCAL_SHARED_LIBRARIES := libkeyguard libcrypto
+LOCAL_SHARED_LIBRARIES := libkeyguard libcrypto libhardware
LOCAL_STATIC_LIBRARIES := libscrypt_static
LOCAL_C_INCLUDES := external/scrypt/lib/crypto
LOCAL_SRC_FILES := \
keyguard_messages_test.cpp \
- keyguard_test.cpp
+ keyguard_test.cpp \
+ keyguard_device_test.cpp
include $(BUILD_NATIVE_TEST)
diff --git a/tests/keyguard_device_test.cpp b/tests/keyguard_device_test.cpp
new file mode 100644
index 0000000..0bc7db9
--- /dev/null
+++ b/tests/keyguard_device_test.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gtest/gtest.h>
+#include <hardware/keyguard.h>
+
+using ::testing::Test;
+
+class KeyguardDeviceTest : public virtual Test {
+public:
+ KeyguardDeviceTest() {}
+ virtual ~KeyguardDeviceTest() {}
+
+ virtual void SetUp() {
+ keyguard_device_initialize(&device);
+ }
+
+ virtual void TearDown() {
+ keyguard_close(device);
+ }
+
+ static void keyguard_device_initialize(keyguard_device_t **dev) {
+ int ret;
+ const hw_module_t *mod;
+ ret = hw_get_module_by_class(KEYGUARD_HARDWARE_MODULE_ID, NULL, &mod);
+
+ ASSERT_EQ(0, ret);
+
+ ret = keyguard_open(mod, dev);
+
+ ASSERT_EQ(0, ret);
+ }
+
+ keyguard_device_t *device;
+};
+
+TEST_F(KeyguardDeviceTest, EnrollAndVerify) {
+ size_t password_len = 50;
+ uint8_t password_payload[password_len];
+ uint8_t *password_handle;
+ size_t password_handle_length;
+ uint8_t *auth_token;
+ size_t auth_token_len;
+ int ret;
+
+ ret = device->enroll(device, 0, password_payload, password_len,
+ &password_handle, &password_handle_length);
+
+ ASSERT_EQ(0, ret);
+
+ ret = device->verify(device, 0, password_handle, password_handle_length,
+ password_payload, password_len, &auth_token, &auth_token_len);
+
+ ASSERT_EQ(0, ret);
+}
+
+TEST_F(KeyguardDeviceTest, EnrollAndVerifyBadPassword) {
+ size_t password_len = 50;
+ uint8_t password_payload[password_len];
+ uint8_t *password_handle;
+ size_t password_handle_length;
+ uint8_t *auth_token = NULL;
+ size_t auth_token_len;
+ int ret;
+
+ ret = device->enroll(device, 0, password_payload, password_len,
+ &password_handle, &password_handle_length);
+
+ ASSERT_EQ(0, ret);
+
+ password_payload[0] = 4;
+
+ ret = device->verify(device, 0, password_handle, password_handle_length,
+ password_payload, password_len, &auth_token, &auth_token_len);
+
+ ASSERT_NE(0, ret);
+ ASSERT_EQ(NULL, auth_token);
+}
+