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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "u2f_apdu_command.h"
8 #include "u2f_device.h"
9
10 namespace device {
11
12 class U2fDeviceTest : public testing::Test {};
13
14 TEST_F(U2fDeviceTest, TestBuildApdu) {
15 std::vector<uint8_t> appid(U2fDevice::kAppIdDigestLen, 0x01);
16 std::vector<uint8_t> challenge(U2fDevice::kChallengeDigestLen, 0xff);
17 scoped_refptr<U2fApduCommand> cmd =
18 U2fDevice::BuildRegisterCommand(appid, challenge);
19 ASSERT_NE(nullptr, cmd);
20 EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
21 ->GetEncodedCommand(),
22 testing::ContainerEq(cmd->GetEncodedCommand()));
23 // Expect null result with appid.size() > kAppIdDigestLen
24 appid.push_back(0xff);
25 cmd = U2fDevice::BuildRegisterCommand(appid, challenge);
26 EXPECT_EQ(nullptr, cmd);
27
28 appid.pop_back();
29 std::vector<uint8_t> key_handle(U2fDevice::kMaxKeyHandleLength);
30 cmd = U2fDevice::BuildSignCommand(appid, challenge, key_handle);
31 ASSERT_NE(nullptr, cmd);
32 EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
33 ->GetEncodedCommand(),
34 testing::ContainerEq(cmd->GetEncodedCommand()));
35 // Expect null result with appid.size() > kMaxKeyHandleLength
36 key_handle.push_back(0x0f);
37 cmd = U2fDevice::BuildSignCommand(appid, challenge, key_handle);
38 EXPECT_EQ(nullptr, cmd);
39 }
40
41 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698