Commit 6f5caf05 authored by William Lin's avatar William Lin Committed by Commit Bot

Show token account ID in Identity Internals page

Currently, the identity internals debugging page does not display the
account ID that the token belongs to. This information may be useful to
list for debugging cases where multiple accounts are involved.

This CL adds the account ID for each cached token to the Identity
Internals page.

Bug: None
Change-Id: I704748f2521cb34c96ed7ccade0fdac6e99d01dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333545
Commit-Queue: William Lin <williamlin@google.com>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795162}
parent 34e8c4fa
...@@ -34,6 +34,8 @@ cr.define('identity_internals', function() { ...@@ -34,6 +34,8 @@ cr.define('identity_internals', function() {
'Extension Name', this.data_.extensionName, 'extension-name')); 'Extension Name', this.data_.extensionName, 'extension-name'));
tbody.appendChild(this.createEntry_( tbody.appendChild(this.createEntry_(
'Extension Id', this.data_.extensionId, 'extension-id')); 'Extension Id', this.data_.extensionId, 'extension-id'));
tbody.appendChild(this.createEntry_(
'Account Id', this.data_.accountId, 'account-id'));
tbody.appendChild( tbody.appendChild(
this.createEntry_('Token Status', this.data_.status, 'token-status')); this.createEntry_('Token Status', this.data_.status, 'token-status'));
tbody.appendChild(this.createEntry_( tbody.appendChild(this.createEntry_(
......
...@@ -211,6 +211,7 @@ IdentityInternalsUIMessageHandler::GetInfoForToken( ...@@ -211,6 +211,7 @@ IdentityInternalsUIMessageHandler::GetInfoForToken(
const extensions::IdentityTokenCacheValue& token_cache_value) { const extensions::IdentityTokenCacheValue& token_cache_value) {
auto token_data = std::make_unique<base::DictionaryValue>(); auto token_data = std::make_unique<base::DictionaryValue>();
token_data->SetString("extensionId", token_cache_key.extension_id); token_data->SetString("extensionId", token_cache_key.extension_id);
token_data->SetString("accountId", token_cache_key.account_id.ToString());
token_data->SetString("extensionName", GetExtensionName(token_cache_key)); token_data->SetString("extensionName", GetExtensionName(token_cache_key));
token_data->Set("scopes", GetScopes(token_cache_key)); token_data->Set("scopes", GetScopes(token_cache_key));
token_data->SetString("status", GetStatus(token_cache_value)); token_data->SetString("status", GetStatus(token_cache_value));
......
...@@ -28,30 +28,34 @@ void IdentityInternalsUIBrowserTest::SetupTokenCache(int number_of_tokens) { ...@@ -28,30 +28,34 @@ void IdentityInternalsUIBrowserTest::SetupTokenCache(int number_of_tokens) {
token_id += token_number; token_id += token_number;
std::string extension_id("extension"); std::string extension_id("extension");
extension_id += token_number; extension_id += token_number;
std::string account_id("account");
account_id += token_number;
std::vector<std::string> scopes; std::vector<std::string> scopes;
scopes.push_back(std::string("scope_1_") + token_number); scopes.emplace_back("scope_1_" + token_number);
scopes.push_back(std::string("scope_2_") + token_number); scopes.emplace_back("scope_2_" + token_number);
AddTokenToCache(token_id, extension_id, scopes, kOneHour); AddTokenToCache(token_id, extension_id, account_id, scopes, kOneHour);
} }
} }
void IdentityInternalsUIBrowserTest::SetupTokenCacheWithStoreApp() { void IdentityInternalsUIBrowserTest::SetupTokenCacheWithStoreApp() {
std::vector<std::string> scopes; std::vector<std::string> scopes;
scopes.push_back(std::string("store_scope1")); scopes.emplace_back("store_scope1");
scopes.push_back(std::string("store_scope2")); scopes.emplace_back("store_scope2");
AddTokenToCache("store_token", kChromeWebStoreId, scopes, kOneHour); AddTokenToCache("store_token", kChromeWebStoreId, "store_account", scopes,
kOneHour);
} }
void IdentityInternalsUIBrowserTest::AddTokenToCache( void IdentityInternalsUIBrowserTest::AddTokenToCache(
const std::string token_id, const std::string& token_id,
const std::string extension_id, const std::string& extension_id,
const std::string& account_id,
const std::vector<std::string>& scopes, const std::vector<std::string>& scopes,
int time_to_live) { int time_to_live) {
extensions::IdentityTokenCacheValue token_cache_value = extensions::IdentityTokenCacheValue token_cache_value =
extensions::IdentityTokenCacheValue::CreateToken( extensions::IdentityTokenCacheValue::CreateToken(
token_id, base::TimeDelta::FromSeconds(time_to_live)); token_id, base::TimeDelta::FromSeconds(time_to_live));
extensions::ExtensionTokenKey key( extensions::ExtensionTokenKey key(
extension_id, CoreAccountId("account_id"), extension_id, CoreAccountId(account_id),
std::set<std::string>(scopes.begin(), scopes.end())); std::set<std::string>(scopes.begin(), scopes.end()));
extensions::IdentityAPI::GetFactoryInstance() extensions::IdentityAPI::GetFactoryInstance()
->Get(browser()->profile()) ->Get(browser()->profile())
......
...@@ -22,8 +22,9 @@ class IdentityInternalsUIBrowserTest : public WebUIBrowserTest { ...@@ -22,8 +22,9 @@ class IdentityInternalsUIBrowserTest : public WebUIBrowserTest {
void SetupTokenCacheWithStoreApp(); void SetupTokenCacheWithStoreApp();
private: private:
void AddTokenToCache(const std::string token_id, void AddTokenToCache(const std::string& token_id,
const std::string extension_id, const std::string& extension_id,
const std::string& account_id,
const std::vector<std::string>& scopes, const std::vector<std::string>& scopes,
int time_to_live); int time_to_live);
......
...@@ -59,6 +59,15 @@ BaseIdentityInternalsWebUITest.prototype = { ...@@ -59,6 +59,15 @@ BaseIdentityInternalsWebUITest.prototype = {
return tokenEntry.querySelector('.extension-id').innerText; return tokenEntry.querySelector('.extension-id').innerText;
}, },
/**
* Gets the account id displayed on the page for a given entry.
* @param {Element} tokenEntry Display element holding token information.
* @return {string} Account Id of the token.
*/
getAccountId: function(tokenEntry) {
return tokenEntry.querySelector('.account-id').innerText;
},
/** /**
* Gets the extension name displayed on the page for a given entry. * Gets the extension name displayed on the page for a given entry.
* @param {Element} tokenEntry Display element holding token information. * @param {Element} tokenEntry Display element holding token information.
...@@ -70,7 +79,7 @@ BaseIdentityInternalsWebUITest.prototype = { ...@@ -70,7 +79,7 @@ BaseIdentityInternalsWebUITest.prototype = {
/** /**
* Gets the revoke button of the token entry. * Gets the revoke button of the token entry.
* @param {Element} tokenEntry Diplsy element holding token information. * @param {Element} tokenEntry Display element holding token information.
* @return {HTMLButtonElement} Revoke button belonging related to the token. * @return {HTMLButtonElement} Revoke button belonging related to the token.
*/ */
getRevokeButton: function(tokenEntry) { getRevokeButton: function(tokenEntry) {
...@@ -138,6 +147,8 @@ TEST_F('IdentityInternalsSingleTokenWebUITest', 'getAllTokens', function() { ...@@ -138,6 +147,8 @@ TEST_F('IdentityInternalsSingleTokenWebUITest', 'getAllTokens', function() {
expectEquals('Web Store', this.getExtensionName(tokenListEntries[0])); expectEquals('Web Store', this.getExtensionName(tokenListEntries[0]));
expectEquals('ahfgeienlihckogmohjhadlkjgocpleb', expectEquals('ahfgeienlihckogmohjhadlkjgocpleb',
this.getExtensionId(tokenListEntries[0])); this.getExtensionId(tokenListEntries[0]));
expectEquals('store_account',
this.getAccountId(tokenListEntries[0]));
expectEquals('store_token', this.getAccessToken(tokenListEntries[0])); expectEquals('store_token', this.getAccessToken(tokenListEntries[0]));
expectEquals('Token Present', this.getTokenStatus(tokenListEntries[0])); expectEquals('Token Present', this.getTokenStatus(tokenListEntries[0]));
expectLT(this.getExpirationTime(tokenListEntries[0]) - new Date(), expectLT(this.getExpirationTime(tokenListEntries[0]) - new Date(),
...@@ -161,6 +172,8 @@ TEST_F('IdentityInternalsSingleTokenWebUITest', 'verifyGetters', function() { ...@@ -161,6 +172,8 @@ TEST_F('IdentityInternalsSingleTokenWebUITest', 'verifyGetters', function() {
tokenListEntries[0].querySelector('.extension-name').innerText); tokenListEntries[0].querySelector('.extension-name').innerText);
expectEquals(this.getExtensionId(tokenListEntries[0]), expectEquals(this.getExtensionId(tokenListEntries[0]),
tokenListEntries[0].querySelector('.extension-id').innerText); tokenListEntries[0].querySelector('.extension-id').innerText);
expectEquals(this.getAccountId(tokenListEntries[0]),
tokenListEntries[0].querySelector('.account-id').innerText);
expectEquals(this.getAccessToken(tokenListEntries[0]), expectEquals(this.getAccessToken(tokenListEntries[0]),
tokenListEntries[0].querySelector('.access-token').innerText); tokenListEntries[0].querySelector('.access-token').innerText);
expectEquals(this.getTokenStatus(tokenListEntries[0]), expectEquals(this.getTokenStatus(tokenListEntries[0]),
...@@ -205,6 +218,8 @@ TEST_F('IdentityInternalsMultipleTokensWebUITest', 'getAllTokens', function() { ...@@ -205,6 +218,8 @@ TEST_F('IdentityInternalsMultipleTokensWebUITest', 'getAllTokens', function() {
expectEquals('', this.getExtensionName(tokenListEntries[0])); expectEquals('', this.getExtensionName(tokenListEntries[0]));
expectEquals('extension0', expectEquals('extension0',
this.getExtensionId(tokenListEntries[0])); this.getExtensionId(tokenListEntries[0]));
expectEquals('account0',
this.getAccountId(tokenListEntries[0]));
expectEquals('token0', this.getAccessToken(tokenListEntries[0])); expectEquals('token0', this.getAccessToken(tokenListEntries[0]));
expectEquals('Token Present', this.getTokenStatus(tokenListEntries[0])); expectEquals('Token Present', this.getTokenStatus(tokenListEntries[0]));
expectLT(this.getExpirationTime(tokenListEntries[0]) - new Date(), expectLT(this.getExpirationTime(tokenListEntries[0]) - new Date(),
...@@ -217,6 +232,8 @@ TEST_F('IdentityInternalsMultipleTokensWebUITest', 'getAllTokens', function() { ...@@ -217,6 +232,8 @@ TEST_F('IdentityInternalsMultipleTokensWebUITest', 'getAllTokens', function() {
expectEquals('', this.getExtensionName(tokenListEntries[1])); expectEquals('', this.getExtensionName(tokenListEntries[1]));
expectEquals('extension1', expectEquals('extension1',
this.getExtensionId(tokenListEntries[1])); this.getExtensionId(tokenListEntries[1]));
expectEquals('account1',
this.getAccountId(tokenListEntries[1]));
expectEquals('token1', this.getAccessToken(tokenListEntries[1])); expectEquals('token1', this.getAccessToken(tokenListEntries[1]));
expectEquals('Token Present', this.getTokenStatus(tokenListEntries[1])); expectEquals('Token Present', this.getTokenStatus(tokenListEntries[1]));
expectLT(this.getExpirationTime(tokenListEntries[1]) - new Date(), expectLT(this.getExpirationTime(tokenListEntries[1]) - new Date(),
......
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