Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2549)

Unified Diff: device/u2f/u2f_device_unittest.cc

Issue 2655853006: Define FIDO U2f Device abstraction (Closed)
Patch Set: Define FIDO U2f Device abstraction Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/u2f/u2f_device_unittest.cc
diff --git a/device/u2f/u2f_device_unittest.cc b/device/u2f/u2f_device_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae997bd7bec0a50f2440bbcd566d52e680ec776c
--- /dev/null
+++ b/device/u2f/u2f_device_unittest.cc
@@ -0,0 +1,41 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "u2f_apdu_command.h"
+#include "u2f_device.h"
+
+namespace device {
+
+class U2fDeviceTest : public testing::Test {};
+
+TEST_F(U2fDeviceTest, TestBuildApdu) {
+ std::vector<uint8_t> appid(U2fDevice::kAppIdDigestLen, 0x01);
+ std::vector<uint8_t> challenge(U2fDevice::kChallengeDigestLen, 0xff);
+ scoped_refptr<U2fApduCommand> cmd =
+ U2fDevice::BuildRegisterCommand(appid, challenge);
+ ASSERT_NE(nullptr, cmd);
+ EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
+ ->GetEncodedCommand(),
+ testing::ContainerEq(cmd->GetEncodedCommand()));
+ // Expect null result with appid.size() > kAppIdDigestLen
+ appid.push_back(0xff);
+ cmd = U2fDevice::BuildRegisterCommand(appid, challenge);
+ EXPECT_EQ(nullptr, cmd);
+
+ appid.pop_back();
+ std::vector<uint8_t> key_handle(U2fDevice::kMaxKeyHandleLength);
+ cmd = U2fDevice::BuildSignCommand(appid, challenge, key_handle);
+ ASSERT_NE(nullptr, cmd);
+ EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
+ ->GetEncodedCommand(),
+ testing::ContainerEq(cmd->GetEncodedCommand()));
+ // Expect null result with appid.size() > kMaxKeyHandleLength
+ key_handle.push_back(0x0f);
+ cmd = U2fDevice::BuildSignCommand(appid, challenge, key_handle);
+ EXPECT_EQ(nullptr, cmd);
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698