• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/hardware/interfaces-mnstshlylh


Commit MetaInfo

Revisioncd00105c383f8294dec26220ca05ed58f2a78123 (tree)
Time2019-04-19 08:14:11
AuthorBranden Archer <brarcher@goog...>
CommiterBranden Archer

Log Message

Split Wifi Keystore HAL tests into smaller pieces

There was originally one test per function, which attempted many
possible error conditions and one success condition. It would be
easier to reason through the tests and maintain them if they
were smaller and each test attempted on thing.

Note that the logic on the "wrong user" tests was reversed; the
HAL expects the user to be the wifi user. The reverse may have
originally worked because the HAL library was run within the test
process.

Bug: 130207625
Test: On an AOSP build:

make VtsHalWifiKeystoreV1_0TargetTest;
vts-tradefed run commandAndExit vts -m VtsHalWifiKeystoreV1_0TargetTest

Change-Id: I534b7f66cdb1047a972a4dab708609b15cf287df
Merged-In: I282e151d0b38903578bd9077814c810e44b3b93d

Change Summary

Incremental Difference

--- a/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp
+++ b/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp
@@ -63,7 +63,7 @@ class WifiKeystoreHalTest : public Test {
6363 service_manager->getService(String16(kKeystoreServiceName));
6464 service = interface_cast<IKeystoreService>(keystore_binder);
6565
66- EXPECT_NE(nullptr, service.get());
66+ ASSERT_TRUE(service);
6767
6868 resetState();
6969 }
@@ -206,11 +206,8 @@ class WifiKeystoreHalTest : public Test {
206206 sp<IKeystoreService> service;
207207 };
208208
209-/**
210- * Test for the Wifi Keystore HAL's sign() call.
211- */
212-TEST_F(WifiKeystoreHalTest, Sign) {
213- ::android::system::wifi::keystore::V1_0::IKeystore::KeystoreStatusCode statusCode;
209+TEST_F(WifiKeystoreHalTest, Sign_nullptr_key_name) {
210+ IKeystore::KeystoreStatusCode statusCode;
214211
215212 auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
216213 const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
@@ -219,57 +216,109 @@ TEST_F(WifiKeystoreHalTest, Sign) {
219216 };
220217
221218 ::android::hardware::hidl_vec<uint8_t> dataToSign;
222-
223- // These attempts do not include an existing key to use
224-
219+ dataToSign.resize(100);
225220 keystore->sign(nullptr, dataToSign, callback);
226221 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
222+}
223+
224+TEST_F(WifiKeystoreHalTest, Sign_empty_key_name) {
225+ IKeystore::KeystoreStatusCode statusCode;
226+
227+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
228+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
229+ statusCode = status;
230+ return;
231+ };
227232
233+ ::android::hardware::hidl_vec<uint8_t> dataToSign;
234+ dataToSign.resize(100);
228235 keystore->sign("", dataToSign, callback);
229236 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
237+}
230238
231- bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, UID_SELF);
239+TEST_F(WifiKeystoreHalTest, Sign_empty_data) {
240+ IKeystore::KeystoreStatusCode statusCode;
241+
242+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
243+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
244+ statusCode = status;
245+ return;
246+ };
247+
248+ bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI);
232249 EXPECT_EQ(result, true);
233250
234251 // The data to sign is empty, and a failure is expected
235-
252+ ::android::hardware::hidl_vec<uint8_t> dataToSign;
236253 keystore->sign(kTestKeyName, dataToSign, callback);
237254 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
255+}
238256
239- // With data the signing attempt should succeed
257+TEST_F(WifiKeystoreHalTest, Sign_wrong_key_purpose) {
258+ IKeystore::KeystoreStatusCode statusCode;
240259
241- dataToSign.resize(100);
242- keystore->sign(kTestKeyName, dataToSign, callback);
243- EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode);
260+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
261+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
262+ statusCode = status;
263+ return;
264+ };
244265
245266 // Create a key which cannot sign; any signing attempt should fail.
246-
247- result = deleteKey(kTestKeyName, UID_SELF);
248- EXPECT_EQ(result, true);
249-
250- result = generateKey(kTestKeyName, KeyPurpose::ENCRYPTION, UID_SELF);
267+ bool result = generateKey(kTestKeyName, KeyPurpose::ENCRYPTION, AID_WIFI);
251268 EXPECT_EQ(result, true);
252269
270+ ::android::hardware::hidl_vec<uint8_t> dataToSign;
271+ dataToSign.resize(100);
253272 keystore->sign(kTestKeyName, dataToSign, callback);
254273 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
274+}
275+
276+TEST_F(WifiKeystoreHalTest, Sign_wrong_key_type) {
277+ IKeystore::KeystoreStatusCode statusCode;
278+
279+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
280+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
281+ statusCode = status;
282+ return;
283+ };
284+
285+ ::android::hardware::hidl_vec<uint8_t> dataToSign;
255286
256287 // Generate a TYPE_GENERIC key instead of a TYPE_KEYMASTER_10 key.
257288 // This also cannot be used to sign.
258289
259- result = deleteKey(kTestKeyName, UID_SELF);
290+ bool result = insert(kTestKeyName, AID_WIFI);
260291 EXPECT_EQ(result, true);
261292
262- result = insert(kTestKeyName, UID_SELF);
293+ keystore->sign(kTestKeyName, dataToSign, callback);
294+ EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
295+}
296+
297+TEST_F(WifiKeystoreHalTest, Sign_success) {
298+ IKeystore::KeystoreStatusCode statusCode;
299+
300+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
301+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
302+ statusCode = status;
303+ return;
304+ };
305+
306+ ::android::hardware::hidl_vec<uint8_t> dataToSign;
307+
308+ bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI);
263309 EXPECT_EQ(result, true);
264310
311+ // With data the signing attempt should succeed
312+
313+ dataToSign.resize(100);
265314 keystore->sign(kTestKeyName, dataToSign, callback);
266- EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
315+ EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode);
316+
317+ result = deleteKey(kTestKeyName, AID_WIFI);
318+ EXPECT_EQ(result, true);
267319 }
268320
269-/**
270- * Test for the Wifi Keystore HAL's getBlob() call.
271- */
272-TEST_F(WifiKeystoreHalTest, GetBlob) {
321+TEST_F(WifiKeystoreHalTest, GetBlob_null_key_name) {
273322 IKeystore::KeystoreStatusCode statusCode;
274323
275324 auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
@@ -279,18 +328,49 @@ TEST_F(WifiKeystoreHalTest, GetBlob) {
279328 };
280329
281330 // Attempting to get a blob on a non-existent key should fail.
282-
283331 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
284332 keystore->getBlob(nullptr, callback);
285333 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
334+}
286335
336+TEST_F(WifiKeystoreHalTest, GetBlob_empty_key_name) {
337+ IKeystore::KeystoreStatusCode statusCode;
338+
339+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
340+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
341+ statusCode = status;
342+ return;
343+ };
344+
345+ // Attempting to get a blob on a non-existent key should fail.
287346 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
288347 keystore->getBlob("", callback);
289348 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
349+}
290350
351+TEST_F(WifiKeystoreHalTest, GetBlob_missing_key) {
352+ IKeystore::KeystoreStatusCode statusCode;
353+
354+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
355+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
356+ statusCode = status;
357+ return;
358+ };
359+
360+ // Attempting to get a blob on a non-existent key should fail.
291361 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
292362 keystore->getBlob(kTestKeyName, callback);
293363 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
364+}
365+
366+TEST_F(WifiKeystoreHalTest, GetBlob_wrong_user) {
367+ IKeystore::KeystoreStatusCode statusCode;
368+
369+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
370+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
371+ statusCode = status;
372+ return;
373+ };
294374
295375 // The HAL is expecting the key to belong to the wifi user.
296376 // If the key belongs to another user's space it should fail.
@@ -300,13 +380,20 @@ TEST_F(WifiKeystoreHalTest, GetBlob) {
300380
301381 keystore->getBlob(kTestKeyName, callback);
302382 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
383+}
303384
304- result = deleteKey(kTestKeyName, UID_SELF);
305- EXPECT_EQ(result, true);
385+TEST_F(WifiKeystoreHalTest, GetBlob_success) {
386+ IKeystore::KeystoreStatusCode statusCode;
387+
388+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
389+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
390+ statusCode = status;
391+ return;
392+ };
306393
307394 // Accessing the key belonging to the wifi user should succeed.
308395
309- result = insert(kTestKeyName, AID_WIFI);
396+ bool result = insert(kTestKeyName, AID_WIFI);
310397 EXPECT_EQ(result, true);
311398
312399 keystore->getBlob(kTestKeyName, callback);
@@ -316,10 +403,7 @@ TEST_F(WifiKeystoreHalTest, GetBlob) {
316403 EXPECT_EQ(result, true);
317404 }
318405
319-/**
320- * Test for the Wifi Keystore HAL's getPublicKey() call.
321- */
322-TEST_F(WifiKeystoreHalTest, GetPublicKey) {
406+TEST_F(WifiKeystoreHalTest, GetPublicKey_nullptr_key_name) {
323407 IKeystore::KeystoreStatusCode statusCode;
324408
325409 auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
@@ -329,53 +413,104 @@ TEST_F(WifiKeystoreHalTest, GetPublicKey) {
329413 };
330414
331415 // Attempting to export a non-existent key should fail.
332-
333416 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
334417 keystore->getPublicKey(nullptr, callback);
335418 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
419+}
336420
421+TEST_F(WifiKeystoreHalTest, GetPublicKey_empty_key_name) {
422+ IKeystore::KeystoreStatusCode statusCode;
423+
424+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
425+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
426+ statusCode = status;
427+ return;
428+ };
429+
430+ // Attempting to export a non-existent key should fail.
337431 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
338432 keystore->getPublicKey("", callback);
339433 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
434+}
435+
436+TEST_F(WifiKeystoreHalTest, GetPublicKey_wrong_key_name) {
437+ IKeystore::KeystoreStatusCode statusCode;
438+
439+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
440+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
441+ statusCode = status;
442+ return;
443+ };
340444
445+ // Attempting to export a non-existent key should fail.
341446 statusCode = IKeystore::KeystoreStatusCode::SUCCESS;
342447 keystore->getPublicKey(kTestKeyName, callback);
343448 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
449+}
450+
451+TEST_F(WifiKeystoreHalTest, GetPublicKey_wrong_user) {
452+ IKeystore::KeystoreStatusCode statusCode;
453+
454+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
455+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
456+ statusCode = status;
457+ return;
458+ };
344459
345- // The HAL is expecting the key to belong to the process' user.
346- // If the key belongs to another user's space (e.g. wifi) it should
460+ // The HAL is expecting the key to belong to the wifi user.
461+ // If the key belongs to another user's space (e.g. root) it should
347462 // not be accessible and should fail.
348463
349- bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI);
464+ bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, UID_SELF);
350465 EXPECT_EQ(result, true);
351466
352467 keystore->getPublicKey(kTestKeyName, callback);
353468 EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
354469
355- result = deleteKey(kTestKeyName, AID_WIFI);
470+ result = deleteKey(kTestKeyName, UID_SELF);
356471 EXPECT_EQ(result, true);
472+}
473+
474+TEST_F(WifiKeystoreHalTest, GetPublicKey_wrong_key_type) {
475+ IKeystore::KeystoreStatusCode statusCode;
357476
358- // Accessing the key belonging to the process' uid should succeed.
477+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
478+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
479+ statusCode = status;
480+ return;
481+ };
359482
360- result = generateKey(kTestKeyName, KeyPurpose::SIGNING, UID_SELF);
483+ // A TYPE_GENERIC key (instead of a TYPE_KEYMASTER_10 key)
484+ // should also fail.
485+
486+ bool result = insert(kTestKeyName, AID_WIFI);
361487 EXPECT_EQ(result, true);
362488
363489 keystore->getPublicKey(kTestKeyName, callback);
364- EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode);
490+ EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
365491
366- result = deleteKey(kTestKeyName, UID_SELF);
492+ result = deleteKey(kTestKeyName, AID_WIFI);
367493 EXPECT_EQ(result, true);
494+}
368495
369- // A TYPE_GENERIC key (instead of a TYPE_KEYMASTER_10 key)
370- // should also fail.
496+TEST_F(WifiKeystoreHalTest, GetPublicKey_success) {
497+ IKeystore::KeystoreStatusCode statusCode;
371498
372- result = insert(kTestKeyName, UID_SELF);
499+ auto callback = [&statusCode](IKeystore::KeystoreStatusCode status,
500+ const ::android::hardware::hidl_vec<uint8_t>& /*value*/) {
501+ statusCode = status;
502+ return;
503+ };
504+
505+ // Accessing the key belonging to the wifi uid should succeed.
506+
507+ bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI);
373508 EXPECT_EQ(result, true);
374509
375510 keystore->getPublicKey(kTestKeyName, callback);
376- EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode);
511+ EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode);
377512
378- result = deleteKey(kTestKeyName, UID_SELF);
513+ result = deleteKey(kTestKeyName, AID_WIFI);
379514 EXPECT_EQ(result, true);
380515 }
381516