Commit 86e051e5 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Expose compromiseTime via chrome.passwordsPrivate

This change adds the compromiseTime field to the CompromisedCredential
dictionary that is exposed via the chrome.passwordsPrivate extension
API. This field is required to be able to sort newly discovered
CompromisedCredentials by recency in the UI.

Bug: 1047726
Change-Id: Id79f8646daa58e885e623999847bfe26d78b5036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089702
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748160}
parent a87a4dd3
......@@ -202,6 +202,8 @@ PasswordCheckDelegate::GetCompromisedCredentialsInfo() {
compromised_credential_id_generator_.GenerateId(credential);
api_credential.signon_realm = credential.signon_realm;
api_credential.username = base::UTF16ToUTF8(credential.username);
api_credential.compromise_time =
credential.create_time.ToJsTimeIgnoringNull();
api_credential.elapsed_time_since_compromise = base::UTF16ToUTF8(
TimeFormat::Simple(TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_LONG,
base::Time::Now() - credential.create_time));
......
......@@ -176,15 +176,19 @@ auto ExpectCompromisedCredential(
const std::string& formatted_origin,
const std::string& change_password_url,
const std::string& username,
const std::string& elapsed_time_since_compromise,
base::TimeDelta elapsed_time_since_compromise,
const std::string& elapsed_time_since_compromise_str,
api::passwords_private::CompromiseType compromise_type) {
return AllOf(
Field(&CompromisedCredential::formatted_origin, formatted_origin),
Field(&CompromisedCredential::change_password_url,
Pointee(change_password_url)),
Field(&CompromisedCredential::username, username),
Field(&CompromisedCredential::compromise_time,
(base::Time::Now() - elapsed_time_since_compromise)
.ToJsTimeIgnoringNull()),
Field(&CompromisedCredential::elapsed_time_since_compromise,
elapsed_time_since_compromise),
elapsed_time_since_compromise_str),
Field(&CompromisedCredential::compromise_type, compromise_type));
}
......@@ -251,16 +255,20 @@ TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoOrders) {
EXPECT_THAT(
delegate().GetCompromisedCredentialsInfo().compromised_credentials,
ElementsAre(ExpectCompromisedCredential(
"example.com", kExampleCom, kUsername2, "2 minutes ago",
"example.com", kExampleCom, kUsername2,
base::TimeDelta::FromMinutes(2), "2 minutes ago",
api::passwords_private::COMPROMISE_TYPE_PHISHED),
ExpectCompromisedCredential(
"example.org", kExampleOrg, kUsername1, "4 minutes ago",
"example.org", kExampleOrg, kUsername1,
base::TimeDelta::FromMinutes(4), "4 minutes ago",
api::passwords_private::COMPROMISE_TYPE_PHISHED),
ExpectCompromisedCredential(
"example.com", kExampleCom, kUsername1, "1 minute ago",
"example.com", kExampleCom, kUsername1,
base::TimeDelta::FromMinutes(1), "1 minute ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED),
ExpectCompromisedCredential(
"example.org", kExampleOrg, kUsername2, "3 minutes ago",
"example.org", kExampleOrg, kUsername2,
base::TimeDelta::FromMinutes(3), "3 minutes ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED)));
}
......@@ -286,13 +294,16 @@ TEST_F(PasswordCheckDelegateTest, GetCompromisedCredentialsInfoInjectsAndroid) {
EXPECT_THAT(
delegate().GetCompromisedCredentialsInfo().compromised_credentials,
ElementsAre(ExpectCompromisedCredential(
"Example App", kExampleCom, kUsername2, "3 days ago",
"Example App", kExampleCom, kUsername2,
base::TimeDelta::FromDays(3), "3 days ago",
api::passwords_private::COMPROMISE_TYPE_PHISHED),
ExpectCompromisedCredential(
"App (com.example.app)", "", kUsername1, "4 days ago",
"App (com.example.app)", "", kUsername1,
base::TimeDelta::FromDays(4), "4 days ago",
api::passwords_private::COMPROMISE_TYPE_PHISHED),
ExpectCompromisedCredential(
"example.com", kExampleCom, kUsername1, "5 minutes ago",
"example.com", kExampleCom, kUsername1,
base::TimeDelta::FromMinutes(5), "5 minutes ago",
api::passwords_private::COMPROMISE_TYPE_LEAKED)));
}
......
......@@ -181,6 +181,7 @@ class TestDelegate : public PasswordsPrivateDelegate {
credential.change_password_url =
std::make_unique<std::string>("https://example.com/change-password");
credential.compromise_type = api::passwords_private::COMPROMISE_TYPE_LEAKED;
credential.compromise_time = 1583236800000; // Mar 03 2020 12:00:00 UTC
credential.elapsed_time_since_compromise = base::UTF16ToUTF8(
TimeFormat::Simple(TimeFormat::FORMAT_ELAPSED, TimeFormat::LENGTH_LONG,
base::TimeDelta::FromDays(3)));
......
......@@ -119,7 +119,7 @@ namespace passwordsPrivate {
long id;
// The formatted origin of the compromised credential. Can be the origin of
// a website (exluding scheme) or the name of an App.
// a website (excluding scheme) or the name of an App.
DOMString formattedOrigin;
// The URL where the compromised password can be changed. Might be not set
......@@ -136,6 +136,11 @@ namespace passwordsPrivate {
// requested.
DOMString? password;
// The timestamp of when this credential was determined to be compromised.
// Specified in milliseconds since the UNIX epoch. Intended to be passed to
// the JavaScript Date() constructor.
double compromiseTime;
// The elapsed time since this credential was determined to be compromised.
// This is passed as an already formatted string, since JavaScript lacks the
// required formatting APIs. Example: "5 minutes ago"
......
......@@ -6,6 +6,9 @@
// that callbacks are correctly invoked, expected parameters are correct,
// and failures are detected.
const COMPROMISE_TIME = 158322960000;
var availableTests = [
function changeSavedPassword() {
var numCalls = 0;
......@@ -221,6 +224,9 @@ var availableTests = [
'https://example.com/change-password',
compromisedCredential.changePasswordUrl);
chrome.test.assertEq('alice', compromisedCredential.username);
const compromiseTime = new Date(compromisedCredential.compromiseTime);
chrome.test.assertEq(
'Tue, 03 Mar 2020 12:00:00 GMT', compromiseTime.toUTCString());
chrome.test.assertEq(
'3 days ago', compromisedCredential.elapsedTimeSinceCompromise);
chrome.test.assertEq('LEAKED', compromisedCredential.compromiseType);
......@@ -236,6 +242,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
};
......@@ -254,6 +261,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
};
......@@ -276,6 +284,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
},
......@@ -294,6 +303,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
},
......@@ -310,6 +320,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
},
......@@ -329,6 +340,7 @@ var availableTests = [
formattedOrigin: 'example.com',
signonRealm: 'https://example.com',
username: 'alice',
compromiseTime: COMPROMISE_TIME,
elapsedTimeSinceCompromise: '3 days ago',
compromiseType: 'LEAKED',
},
......
......@@ -106,6 +106,7 @@ chrome.passwordsPrivate.PasswordExportProgress;
* signonRealm: string,
* username: string,
* password: (string|undefined),
* compromiseTime: number,
* elapsedTimeSinceCompromise: string,
* compromiseType: !chrome.passwordsPrivate.CompromiseType
* }}
......
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