Commit 59614462 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[Nearby] Fix next public certificate expiration time

Returns the correct next expiration time for the stored public
certificates. Because the expirations times were being persisted as a
map using the certificate ID as the key, they were sorted by the ID and
not the expiration time. We now sort by expiration time when retrieving
from prefs.

Changed the fake certificate IDs in the unit tests so tests will fail
if the certificate are not sorted.

Change-Id: Idd546c62939bd4bb4c62be405a3f8d9cec79de70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429287
Commit-Queue: Josh Nohle <nohle@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Auto-Submit: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#810340}
parent 49977962
...@@ -621,6 +621,7 @@ bool NearbyShareCertificateStorageImpl::FetchPublicCertificateExpirations() { ...@@ -621,6 +621,7 @@ bool NearbyShareCertificateStorageImpl::FetchPublicCertificateExpirations() {
if (!dict) { if (!dict) {
return false; return false;
} }
public_certificate_expirations_.reserve(dict->DictSize()); public_certificate_expirations_.reserve(dict->DictSize());
for (const std::pair<const std::string&, const base::Value&>& pair : for (const std::pair<const std::string&, const base::Value&>& pair :
dict->DictItems()) { dict->DictItems()) {
...@@ -631,6 +632,9 @@ bool NearbyShareCertificateStorageImpl::FetchPublicCertificateExpirations() { ...@@ -631,6 +632,9 @@ bool NearbyShareCertificateStorageImpl::FetchPublicCertificateExpirations() {
public_certificate_expirations_.emplace_back(*id, *expiration); public_certificate_expirations_.emplace_back(*id, *expiration);
} }
std::sort(public_certificate_expirations_.begin(),
public_certificate_expirations_.end(), SortBySecond);
return true; return true;
} }
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
namespace { namespace {
const char kSecretId1[] = "secretid1"; // NOTE: Make sure secret ID alphabetical ordering does not match the 1,2,3,..
// ordering to test sorting expiration times.
const char kSecretId1[] = "b_secretid1";
const char kSecretKey1[] = "secretkey1"; const char kSecretKey1[] = "secretkey1";
const char kPublicKey1[] = "publickey1"; const char kPublicKey1[] = "publickey1";
const int64_t kStartSeconds1 = 0; const int64_t kStartSeconds1 = 0;
...@@ -35,7 +37,7 @@ const bool kForSelectedContacts1 = false; ...@@ -35,7 +37,7 @@ const bool kForSelectedContacts1 = false;
const char kMetadataEncryptionKey1[] = "metadataencryptionkey1"; const char kMetadataEncryptionKey1[] = "metadataencryptionkey1";
const char kEncryptedMetadataBytes1[] = "encryptedmetadatabytes1"; const char kEncryptedMetadataBytes1[] = "encryptedmetadatabytes1";
const char kMetadataEncryptionKeyTag1[] = "metadataencryptionkeytag1"; const char kMetadataEncryptionKeyTag1[] = "metadataencryptionkeytag1";
const char kSecretId2[] = "secretid2"; const char kSecretId2[] = "c_secretid2";
const char kSecretKey2[] = "secretkey2"; const char kSecretKey2[] = "secretkey2";
const char kPublicKey2[] = "publickey2"; const char kPublicKey2[] = "publickey2";
const int64_t kStartSeconds2 = 0; const int64_t kStartSeconds2 = 0;
...@@ -46,7 +48,7 @@ const bool kForSelectedContacts2 = false; ...@@ -46,7 +48,7 @@ const bool kForSelectedContacts2 = false;
const char kMetadataEncryptionKey2[] = "metadataencryptionkey2"; const char kMetadataEncryptionKey2[] = "metadataencryptionkey2";
const char kEncryptedMetadataBytes2[] = "encryptedmetadatabytes2"; const char kEncryptedMetadataBytes2[] = "encryptedmetadatabytes2";
const char kMetadataEncryptionKeyTag2[] = "metadataencryptionkeytag2"; const char kMetadataEncryptionKeyTag2[] = "metadataencryptionkeytag2";
const char kSecretId3[] = "secretid3"; const char kSecretId3[] = "a_secretid3";
const char kSecretKey3[] = "secretkey3"; const char kSecretKey3[] = "secretkey3";
const char kPublicKey3[] = "publickey3"; const char kPublicKey3[] = "publickey3";
const int64_t kStartSeconds3 = 0; const int64_t kStartSeconds3 = 0;
...@@ -57,7 +59,7 @@ const bool kForSelectedContacts3 = false; ...@@ -57,7 +59,7 @@ const bool kForSelectedContacts3 = false;
const char kMetadataEncryptionKey3[] = "metadataencryptionkey3"; const char kMetadataEncryptionKey3[] = "metadataencryptionkey3";
const char kEncryptedMetadataBytes3[] = "encryptedmetadatabytes3"; const char kEncryptedMetadataBytes3[] = "encryptedmetadatabytes3";
const char kMetadataEncryptionKeyTag3[] = "metadataencryptionkeytag3"; const char kMetadataEncryptionKeyTag3[] = "metadataencryptionkeytag3";
const char kSecretId4[] = "secretid4"; const char kSecretId4[] = "d_secretid4";
const char kSecretKey4[] = "secretkey4"; const char kSecretKey4[] = "secretkey4";
const char kPublicKey4[] = "publickey4"; const char kPublicKey4[] = "publickey4";
const int64_t kStartSeconds4 = 0; const int64_t kStartSeconds4 = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment