summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2019-03-25 22:15:23 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-03-25 22:15:23 +0000
commit58f3820418b52711bf4938b933b30c1e2d441236 (patch)
tree40072acec725e141fbed3a2dc9dfdbc1b1271701
parent09f8cb156de3b6d125ac1bab692f77f3707e4763 (diff)
parent5c6af7527439af1ec8be0c3944345678eb9afd88 (diff)
downloadsecurity-58f3820418b52711bf4938b933b30c1e2d441236.tar.gz
Merge "ConfirmationUI: Invocation native test"
-rw-r--r--keystore/tests/Android.bp30
-rw-r--r--keystore/tests/confirmationui_invocation_test.cpp92
2 files changed, 122 insertions, 0 deletions
diff --git a/keystore/tests/Android.bp b/keystore/tests/Android.bp
index 1ce1210f..25fa10b9 100644
--- a/keystore/tests/Android.bp
+++ b/keystore/tests/Android.bp
@@ -37,3 +37,33 @@ cc_test {
cfi: false,
}
}
+
+cc_test {
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wextra",
+ "-O0",
+ ],
+ srcs: [
+ "confirmationui_invocation_test.cpp",
+ "gtest_main.cpp",
+ ],
+ name: "confirmationui_invocation_test",
+ static_libs: [
+ "android.hardware.confirmationui@1.0",
+ "libbase",
+ "libgtest_main",
+ "libutils",
+ "liblog",
+ ],
+ shared_libs: [
+ "libbinder",
+ "libkeystore_aidl", // for IKeyStoreService.asInterface()
+ "libkeystore_binder",
+ "libkeystore_parcelables",
+ ],
+ sanitize: {
+ cfi: false,
+ }
+}
diff --git a/keystore/tests/confirmationui_invocation_test.cpp b/keystore/tests/confirmationui_invocation_test.cpp
new file mode 100644
index 00000000..f5182b53
--- /dev/null
+++ b/keystore/tests/confirmationui_invocation_test.cpp
@@ -0,0 +1,92 @@
+/*
+**
+** Copyright 2019, 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 <android/hardware/confirmationui/1.0/types.h>
+#include <android/security/BnConfirmationPromptCallback.h>
+#include <android/security/keystore/IKeystoreService.h>
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+
+#include <gtest/gtest.h>
+
+#include <chrono>
+#include <future>
+#include <tuple>
+#include <vector>
+
+using ConfirmationResponseCode = android::hardware::confirmationui::V1_0::ResponseCode;
+using android::IBinder;
+using android::IServiceManager;
+using android::sp;
+using android::String16;
+using android::security::keystore::IKeystoreService;
+
+using namespace std::literals::chrono_literals;
+
+class ConfirmationListener
+ : public android::security::BnConfirmationPromptCallback,
+ public std::promise<std::tuple<ConfirmationResponseCode, std::vector<uint8_t>>> {
+ public:
+ ConfirmationListener() {}
+
+ virtual ::android::binder::Status
+ onConfirmationPromptCompleted(int32_t result,
+ const ::std::vector<uint8_t>& dataThatWasConfirmed) override {
+ this->set_value({static_cast<ConfirmationResponseCode>(result), dataThatWasConfirmed});
+ return ::android::binder::Status::ok();
+ }
+};
+
+TEST(ConfirmationInvocationTest, InvokeAndCancel) {
+ android::ProcessState::self()->startThreadPool();
+
+ sp<IServiceManager> sm = android::defaultServiceManager();
+ sp<IBinder> binder = sm->getService(String16("android.security.keystore"));
+ sp<IKeystoreService> service = android::interface_cast<IKeystoreService>(binder);
+ ASSERT_TRUE(service);
+
+ String16 promptText16("Just a little test!");
+ String16 locale16("en");
+ std::vector<uint8_t> extraData{0xaa, 0xff, 0x00, 0x55};
+
+ sp<ConfirmationListener> listener = new ConfirmationListener();
+
+ auto future = listener->get_future();
+ int32_t aidl_return;
+
+ android::binder::Status status = service->presentConfirmationPrompt(
+ listener, promptText16, extraData, locale16, 0, &aidl_return);
+ ASSERT_TRUE(status.isOk()) << "Presenting confirmation prompt failed with binder status '"
+ << status.toString8().c_str() << "'.\n";
+ ConfirmationResponseCode responseCode = static_cast<ConfirmationResponseCode>(aidl_return);
+ ASSERT_EQ(responseCode, ConfirmationResponseCode::OK)
+ << "Presenting confirmation prompt failed with response code " << aidl_return << ".\n";
+
+ auto fstatus = future.wait_for(2s);
+ EXPECT_EQ(fstatus, std::future_status::timeout);
+
+ status = service->cancelConfirmationPrompt(listener, &aidl_return);
+ ASSERT_TRUE(status.isOk());
+
+ responseCode = static_cast<ConfirmationResponseCode>(aidl_return);
+ ASSERT_EQ(responseCode, ConfirmationResponseCode::OK);
+
+ future.wait();
+ auto [rc, dataThatWasConfirmed] = future.get();
+
+ ASSERT_EQ(rc, ConfirmationResponseCode::Aborted);
+}