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

Unified Diff: device/u2f/u2f_apdu_unittest.cc

Issue 2665493002: Add builders to APDU command class (Closed)
Patch Set: Remove unused constant 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
« device/u2f/u2f_apdu_command.cc ('K') | « device/u2f/u2f_apdu_command.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/u2f/u2f_apdu_unittest.cc
diff --git a/device/u2f/u2f_apdu_unittest.cc b/device/u2f/u2f_apdu_unittest.cc
index a0435eb0d97ef560663e540fb9fd0d7262d97986..0526b2f55ba9439ee52c76ec949a42b45bd3bd7b 100644
--- a/device/u2f/u2f_apdu_unittest.cc
+++ b/device/u2f/u2f_apdu_unittest.cc
@@ -181,4 +181,31 @@ TEST_F(U2fApduTest, TestSerializeEdgeCases) {
U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
->GetEncodedCommand()));
}
+
+TEST_F(U2fApduTest, TestBuildApdu) {
juanlang (chromium.org) 2017/01/28 00:08:39 BuildGetVersionCommand and BuildGetLegacyVersionCo
Reilly Grant (use Gerrit) 2017/01/28 00:29:29 Put each one in its own test method.
Casey Piper 2017/01/30 21:51:41 Done.
Casey Piper 2017/01/30 21:51:41 Done.
+ std::vector<uint8_t> appid(U2fApduCommand::kAppIdDigestLen, 0x01);
+ std::vector<uint8_t> challenge(U2fApduCommand::kChallengeDigestLen, 0xff);
+ scoped_refptr<U2fApduCommand> cmd =
+ U2fApduCommand::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 = U2fApduCommand::BuildRegisterCommand(appid, challenge);
+ EXPECT_EQ(nullptr, cmd);
+
+ appid.pop_back();
+ std::vector<uint8_t> key_handle(U2fApduCommand::kMaxKeyHandleLength);
+ cmd = U2fApduCommand::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 = U2fApduCommand::BuildSignCommand(appid, challenge, key_handle);
+ EXPECT_EQ(nullptr, cmd);
+}
} // namespace device
« device/u2f/u2f_apdu_command.cc ('K') | « device/u2f/u2f_apdu_command.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698