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

Side by Side Diff: device/u2f/u2f_apdu_unittest.cc

Issue 2665493002: Add builders to APDU command class (Closed)
Patch Set: Remove unused constant 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gmock/include/gmock/gmock.h" 5 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "u2f_apdu_command.h" 7 #include "u2f_apdu_command.h"
8 #include "u2f_apdu_response.h" 8 #include "u2f_apdu_response.h"
9 9
10 namespace device { 10 namespace device {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 U2fApduCommand::CreateFromMessage(expected)->GetEncodedCommand())); 174 U2fApduCommand::CreateFromMessage(expected)->GetEncodedCommand()));
175 175
176 // Maximum data size 176 // Maximum data size
177 std::vector<uint8_t> oversized(U2fApduCommand::kApduMaxDataLength); 177 std::vector<uint8_t> oversized(U2fApduCommand::kApduMaxDataLength);
178 cmd->set_data(oversized); 178 cmd->set_data(oversized);
179 EXPECT_THAT(cmd->GetEncodedCommand(), 179 EXPECT_THAT(cmd->GetEncodedCommand(),
180 testing::ContainerEq( 180 testing::ContainerEq(
181 U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand()) 181 U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
182 ->GetEncodedCommand())); 182 ->GetEncodedCommand()));
183 } 183 }
184
185 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.
186 std::vector<uint8_t> appid(U2fApduCommand::kAppIdDigestLen, 0x01);
187 std::vector<uint8_t> challenge(U2fApduCommand::kChallengeDigestLen, 0xff);
188 scoped_refptr<U2fApduCommand> cmd =
189 U2fApduCommand::BuildRegisterCommand(appid, challenge);
190 ASSERT_NE(nullptr, cmd);
191 EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
192 ->GetEncodedCommand(),
193 testing::ContainerEq(cmd->GetEncodedCommand()));
194 // Expect null result with appid.size() > kAppIdDigestLen
195 appid.push_back(0xff);
196 cmd = U2fApduCommand::BuildRegisterCommand(appid, challenge);
197 EXPECT_EQ(nullptr, cmd);
198
199 appid.pop_back();
200 std::vector<uint8_t> key_handle(U2fApduCommand::kMaxKeyHandleLength);
201 cmd = U2fApduCommand::BuildSignCommand(appid, challenge, key_handle);
202 ASSERT_NE(nullptr, cmd);
203 EXPECT_THAT(U2fApduCommand::CreateFromMessage(cmd->GetEncodedCommand())
204 ->GetEncodedCommand(),
205 testing::ContainerEq(cmd->GetEncodedCommand()));
206 // Expect null result with appid.size() > kMaxKeyHandleLength
207 key_handle.push_back(0x0f);
208 cmd = U2fApduCommand::BuildSignCommand(appid, challenge, key_handle);
209 EXPECT_EQ(nullptr, cmd);
210 }
184 } // namespace device 211 } // namespace device
OLDNEW
« 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