1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

Permissions: Do not display HTTP/HTTPS URL schemes for unique hosts (#8768)

* only show URL.host in connected-accounts component

* strip scheme from URL for unique hosts

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
Erik Marks 2020-06-09 13:56:24 -07:00 committed by GitHub
parent 4706401f4f
commit a84eedb7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 287 additions and 225 deletions

View File

@ -513,6 +513,11 @@ export class PermissionsController {
...metadata, ...metadata,
lastUpdated: Date.now(), lastUpdated: Date.now(),
} }
if (!newMetadataState[origin].extensionId && !newMetadataState[origin].host) {
newMetadataState[origin].host = new URL(origin).host
}
this._pendingSiteMetadata.add(origin) this._pendingSiteMetadata.add(origin)
this._setDomainMetadata(newMetadataState) this._setDomainMetadata(newMetadataState)
} }

View File

@ -151,10 +151,10 @@ export const getNotifyAllDomains = (notifications = {}) => (notification) => {
* - e.g. permissions, caveats, and permission requests * - e.g. permissions, caveats, and permission requests
*/ */
const ORIGINS = { const DOMAINS = {
a: 'foo.xyz', a: { origin: 'https://foo.xyz', host: 'foo.xyz' },
b: 'bar.abc', b: { origin: 'https://bar.abc', host: 'bar.abc' },
c: 'baz.def', c: { origin: 'https://baz.def', host: 'baz.def' },
} }
const PERM_NAMES = { const PERM_NAMES = {
@ -630,7 +630,7 @@ export const constants = deepFreeze({
c: '3', c: '3',
}, },
ORIGINS: { ...ORIGINS }, DOMAINS: { ...DOMAINS },
ACCOUNTS: { ...ACCOUNTS }, ACCOUNTS: { ...ACCOUNTS },
@ -648,7 +648,7 @@ export const constants = deepFreeze({
case1: [ case1: [
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 1, lastApproved: 1,
accounts: { accounts: {
@ -660,7 +660,7 @@ export const constants = deepFreeze({
}, },
}, },
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 2, lastApproved: 2,
accounts: { accounts: {
@ -675,7 +675,7 @@ export const constants = deepFreeze({
case2: [ case2: [
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 1, lastApproved: 1,
accounts: {}, accounts: {},
@ -686,10 +686,10 @@ export const constants = deepFreeze({
case3: [ case3: [
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.test_method]: { lastApproved: 1 }, [PERM_NAMES.test_method]: { lastApproved: 1 },
}, },
[ORIGINS.b]: { [DOMAINS.b.origin]: {
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 1, lastApproved: 1,
accounts: { accounts: {
@ -697,7 +697,7 @@ export const constants = deepFreeze({
}, },
}, },
}, },
[ORIGINS.c]: { [DOMAINS.c.origin]: {
[PERM_NAMES.test_method]: { lastApproved: 1 }, [PERM_NAMES.test_method]: { lastApproved: 1 },
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 1, lastApproved: 1,
@ -708,10 +708,10 @@ export const constants = deepFreeze({
}, },
}, },
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.test_method]: { lastApproved: 2 }, [PERM_NAMES.test_method]: { lastApproved: 2 },
}, },
[ORIGINS.b]: { [DOMAINS.b.origin]: {
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 1, lastApproved: 1,
accounts: { accounts: {
@ -719,7 +719,7 @@ export const constants = deepFreeze({
}, },
}, },
}, },
[ORIGINS.c]: { [DOMAINS.c.origin]: {
[PERM_NAMES.test_method]: { lastApproved: 1 }, [PERM_NAMES.test_method]: { lastApproved: 1 },
[PERM_NAMES.eth_accounts]: { [PERM_NAMES.eth_accounts]: {
lastApproved: 2, lastApproved: 2,
@ -734,7 +734,7 @@ export const constants = deepFreeze({
case4: [ case4: [
{ {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
[PERM_NAMES.test_method]: { [PERM_NAMES.test_method]: {
lastApproved: 1, lastApproved: 1,
}, },

View File

@ -37,15 +37,15 @@ const {
ALL_ACCOUNTS, ALL_ACCOUNTS,
ACCOUNTS, ACCOUNTS,
DUMMY_ACCOUNT, DUMMY_ACCOUNT,
ORIGINS, DOMAINS,
PERM_NAMES, PERM_NAMES,
REQUEST_IDS, REQUEST_IDS,
EXTRA_ACCOUNT, EXTRA_ACCOUNT,
} = constants } = constants
const initNotifications = () => { const initNotifications = () => {
return Object.values(ORIGINS).reduce((acc, domain) => { return Object.values(DOMAINS).reduce((acc, domain) => {
acc[domain] = [] acc[domain.origin] = []
return acc return acc
}, {}) }, {})
} }
@ -73,19 +73,19 @@ describe('permissions controller', function () {
beforeEach(function () { beforeEach(function () {
permController = initPermController() permController = initPermController()
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
}) })
it('gets permitted accounts for permitted origins', async function () { it('gets permitted accounts for permitted origins', async function () {
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
const bAccounts = await permController.getAccounts(ORIGINS.b) const bAccounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], aAccounts, [ACCOUNTS.a.primary],
@ -98,7 +98,7 @@ describe('permissions controller', function () {
}) })
it('does not get accounts for unpermitted origins', async function () { it('does not get accounts for unpermitted origins', async function () {
const cAccounts = await permController.getAccounts(ORIGINS.c) const cAccounts = await permController.getAccounts(DOMAINS.c.origin)
assert.deepEqual(cAccounts, [], 'origin should have no accounts') assert.deepEqual(cAccounts, [], 'origin should have no accounts')
}) })
@ -114,29 +114,29 @@ describe('permissions controller', function () {
const permController = initPermController() const permController = initPermController()
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.test_method() PERMS.finalizedRequests.test_method()
) )
assert.ok( assert.ok(
permController.hasPermission(ORIGINS.a, 'eth_accounts'), permController.hasPermission(DOMAINS.a.origin, 'eth_accounts'),
'should return true for granted permission' 'should return true for granted permission'
) )
assert.ok( assert.ok(
permController.hasPermission(ORIGINS.b, 'test_method'), permController.hasPermission(DOMAINS.b.origin, 'test_method'),
'should return true for granted permission' 'should return true for granted permission'
) )
assert.ok( assert.ok(
!permController.hasPermission(ORIGINS.a, 'test_method'), !permController.hasPermission(DOMAINS.a.origin, 'test_method'),
'should return false for non-granted permission' 'should return false for non-granted permission'
) )
assert.ok( assert.ok(
!permController.hasPermission(ORIGINS.b, 'eth_accounts'), !permController.hasPermission(DOMAINS.b.origin, 'eth_accounts'),
'should return true for non-granted permission' 'should return true for non-granted permission'
) )
@ -145,7 +145,7 @@ describe('permissions controller', function () {
'should return false for unknown origin' 'should return false for unknown origin'
) )
assert.ok( assert.ok(
!permController.hasPermission(ORIGINS.b, 'foo'), !permController.hasPermission(DOMAINS.b.origin, 'foo'),
'should return false for unknown permission' 'should return false for unknown permission'
) )
}) })
@ -159,21 +159,21 @@ describe('permissions controller', function () {
const permController = initPermController(notifications) const permController = initPermController(notifications)
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted)
) )
let aAccounts = await permController.getAccounts(ORIGINS.a) let aAccounts = await permController.getAccounts(DOMAINS.a.origin)
let bAccounts = await permController.getAccounts(ORIGINS.b) let bAccounts = await permController.getAccounts(DOMAINS.b.origin)
let cAccounts = await permController.getAccounts(ORIGINS.c) let cAccounts = await permController.getAccounts(DOMAINS.c.origin)
assert.deepEqual( assert.deepEqual(
@ -199,9 +199,9 @@ describe('permissions controller', function () {
) )
}) })
aAccounts = await permController.getAccounts(ORIGINS.a) aAccounts = await permController.getAccounts(DOMAINS.a.origin)
bAccounts = await permController.getAccounts(ORIGINS.b) bAccounts = await permController.getAccounts(DOMAINS.b.origin)
cAccounts = await permController.getAccounts(ORIGINS.c) cAccounts = await permController.getAccounts(DOMAINS.c.origin)
assert.deepEqual(aAccounts, [], 'first origin should have no accounts') assert.deepEqual(aAccounts, [], 'first origin should have no accounts')
assert.deepEqual(bAccounts, [], 'second origin should have no accounts') assert.deepEqual(bAccounts, [], 'second origin should have no accounts')
@ -230,19 +230,19 @@ describe('permissions controller', function () {
notifications = initNotifications() notifications = initNotifications()
permController = initPermController(notifications) permController = initPermController(notifications)
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
}) })
it('removes permissions for multiple domains', async function () { it('removes permissions for multiple domains', async function () {
let aAccounts = await permController.getAccounts(ORIGINS.a) let aAccounts = await permController.getAccounts(DOMAINS.a.origin)
let bAccounts = await permController.getAccounts(ORIGINS.b) let bAccounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], aAccounts, [ACCOUNTS.a.primary],
@ -254,22 +254,22 @@ describe('permissions controller', function () {
) )
permController.removePermissionsFor({ permController.removePermissionsFor({
[ORIGINS.a]: [PERM_NAMES.eth_accounts], [DOMAINS.a.origin]: [PERM_NAMES.eth_accounts],
[ORIGINS.b]: [PERM_NAMES.eth_accounts], [DOMAINS.b.origin]: [PERM_NAMES.eth_accounts],
}) })
aAccounts = await permController.getAccounts(ORIGINS.a) aAccounts = await permController.getAccounts(DOMAINS.a.origin)
bAccounts = await permController.getAccounts(ORIGINS.b) bAccounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual(aAccounts, [], 'first origin should have no accounts') assert.deepEqual(aAccounts, [], 'first origin should have no accounts')
assert.deepEqual(bAccounts, [], 'second origin should have no accounts') assert.deepEqual(bAccounts, [], 'second origin should have no accounts')
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.a], [NOTIFICATIONS.removedAccounts()], notifications[DOMAINS.a.origin], [NOTIFICATIONS.removedAccounts()],
'first origin should have correct notification' 'first origin should have correct notification'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], [NOTIFICATIONS.removedAccounts()], notifications[DOMAINS.b.origin], [NOTIFICATIONS.removedAccounts()],
'second origin should have correct notification' 'second origin should have correct notification'
) )
@ -282,10 +282,10 @@ describe('permissions controller', function () {
it('only removes targeted permissions from single domain', async function () { it('only removes targeted permissions from single domain', async function () {
grantPermissions( grantPermissions(
permController, ORIGINS.b, PERMS.finalizedRequests.test_method() permController, DOMAINS.b.origin, PERMS.finalizedRequests.test_method()
) )
let bPermissions = permController.permissions.getPermissionsForDomain(ORIGINS.b) let bPermissions = permController.permissions.getPermissionsForDomain(DOMAINS.b.origin)
assert.ok( assert.ok(
( (
@ -297,10 +297,10 @@ describe('permissions controller', function () {
) )
permController.removePermissionsFor({ permController.removePermissionsFor({
[ORIGINS.b]: [PERM_NAMES.test_method], [DOMAINS.b.origin]: [PERM_NAMES.test_method],
}) })
bPermissions = permController.permissions.getPermissionsForDomain(ORIGINS.b) bPermissions = permController.permissions.getPermissionsForDomain(DOMAINS.b.origin)
assert.ok( assert.ok(
( (
@ -314,11 +314,11 @@ describe('permissions controller', function () {
it('removes permissions for a single domain, without affecting another', async function () { it('removes permissions for a single domain, without affecting another', async function () {
permController.removePermissionsFor({ permController.removePermissionsFor({
[ORIGINS.b]: [PERM_NAMES.eth_accounts], [DOMAINS.b.origin]: [PERM_NAMES.eth_accounts],
}) })
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
const bAccounts = await permController.getAccounts(ORIGINS.b) const bAccounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], aAccounts, [ACCOUNTS.a.primary],
@ -327,16 +327,16 @@ describe('permissions controller', function () {
assert.deepEqual(bAccounts, [], 'second origin should have no accounts') assert.deepEqual(bAccounts, [], 'second origin should have no accounts')
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.a], [], notifications[DOMAINS.a.origin], [],
'first origin should have no notifications' 'first origin should have no notifications'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], [NOTIFICATIONS.removedAccounts()], notifications[DOMAINS.b.origin], [NOTIFICATIONS.removedAccounts()],
'second origin should have correct notification' 'second origin should have correct notification'
) )
assert.deepEqual( assert.deepEqual(
Object.keys(permController.permissions.getDomains()), [ORIGINS.a], Object.keys(permController.permissions.getDomains()), [DOMAINS.a.origin],
'only first origin should remain' 'only first origin should remain'
) )
}) })
@ -345,16 +345,16 @@ describe('permissions controller', function () {
// it knows nothing of this origin // it knows nothing of this origin
permController.removePermissionsFor({ permController.removePermissionsFor({
[ORIGINS.c]: [PERM_NAMES.eth_accounts], [DOMAINS.c.origin]: [PERM_NAMES.eth_accounts],
}) })
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.c], [NOTIFICATIONS.removedAccounts()], notifications[DOMAINS.c.origin], [NOTIFICATIONS.removedAccounts()],
'unknown origin should have notification' 'unknown origin should have notification'
) )
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
const bAccounts = await permController.getAccounts(ORIGINS.b) const bAccounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], aAccounts, [ACCOUNTS.a.primary],
@ -367,7 +367,7 @@ describe('permissions controller', function () {
assert.deepEqual( assert.deepEqual(
Object.keys(permController.permissions.getDomains()), Object.keys(permController.permissions.getDomains()),
[ORIGINS.a, ORIGINS.b], [DOMAINS.a.origin, DOMAINS.b.origin],
'should have correct domains' 'should have correct domains'
) )
}) })
@ -380,11 +380,11 @@ describe('permissions controller', function () {
beforeEach(function () { beforeEach(function () {
permController = initPermController() permController = initPermController()
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
}) })
@ -470,18 +470,18 @@ describe('permissions controller', function () {
notifications = initNotifications() notifications = initNotifications()
permController = initPermController(notifications) permController = initPermController(notifications)
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
}) })
it('should throw if account is not a string', async function () { it('should throw if account is not a string', async function () {
await assert.rejects( await assert.rejects(
() => permController.addPermittedAccount(ORIGINS.a, {}), () => permController.addPermittedAccount(DOMAINS.a.origin, {}),
ERRORS.validatePermittedAccounts.nonKeyringAccount({}), ERRORS.validatePermittedAccounts.nonKeyringAccount({}),
'should throw on non-string account param' 'should throw on non-string account param'
) )
@ -489,7 +489,7 @@ describe('permissions controller', function () {
it('should throw if given account is not in keyring', async function () { it('should throw if given account is not in keyring', async function () {
await assert.rejects( await assert.rejects(
() => permController.addPermittedAccount(ORIGINS.a, DUMMY_ACCOUNT), () => permController.addPermittedAccount(DOMAINS.a.origin, DUMMY_ACCOUNT),
ERRORS.validatePermittedAccounts.nonKeyringAccount(DUMMY_ACCOUNT), ERRORS.validatePermittedAccounts.nonKeyringAccount(DUMMY_ACCOUNT),
'should throw on non-keyring account' 'should throw on non-keyring account'
) )
@ -505,7 +505,7 @@ describe('permissions controller', function () {
it('should throw if origin lacks any permissions', async function () { it('should throw if origin lacks any permissions', async function () {
await assert.rejects( await assert.rejects(
() => permController.addPermittedAccount(ORIGINS.c, EXTRA_ACCOUNT), () => permController.addPermittedAccount(DOMAINS.c.origin, EXTRA_ACCOUNT),
ERRORS.addPermittedAccount.invalidOrigin(), ERRORS.addPermittedAccount.invalidOrigin(),
'should throw on origin without permissions' 'should throw on origin without permissions'
) )
@ -513,12 +513,12 @@ describe('permissions controller', function () {
it('should throw if origin lacks eth_accounts permission', async function () { it('should throw if origin lacks eth_accounts permission', async function () {
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.test_method() PERMS.finalizedRequests.test_method()
) )
await assert.rejects( await assert.rejects(
() => permController.addPermittedAccount(ORIGINS.c, EXTRA_ACCOUNT), () => permController.addPermittedAccount(DOMAINS.c.origin, EXTRA_ACCOUNT),
ERRORS.addPermittedAccount.noEthAccountsPermission(), ERRORS.addPermittedAccount.noEthAccountsPermission(),
'should throw on origin without eth_accounts permission' 'should throw on origin without eth_accounts permission'
) )
@ -526,16 +526,16 @@ describe('permissions controller', function () {
it('should throw if account is already permitted', async function () { it('should throw if account is already permitted', async function () {
await assert.rejects( await assert.rejects(
() => permController.addPermittedAccount(ORIGINS.a, ACCOUNTS.a.permitted[0]), () => permController.addPermittedAccount(DOMAINS.a.origin, ACCOUNTS.a.permitted[0]),
ERRORS.addPermittedAccount.alreadyPermitted(), ERRORS.addPermittedAccount.alreadyPermitted(),
'should throw if account is already permitted' 'should throw if account is already permitted'
) )
}) })
it('should successfully add permitted account', async function () { it('should successfully add permitted account', async function () {
await permController.addPermittedAccount(ORIGINS.a, EXTRA_ACCOUNT) await permController.addPermittedAccount(DOMAINS.a.origin, EXTRA_ACCOUNT)
const accounts = await permController._getPermittedAccounts(ORIGINS.a) const accounts = await permController._getPermittedAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
accounts, [...ACCOUNTS.a.permitted, EXTRA_ACCOUNT], accounts, [...ACCOUNTS.a.permitted, EXTRA_ACCOUNT],
@ -543,7 +543,7 @@ describe('permissions controller', function () {
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.a][0], notifications[DOMAINS.a.origin][0],
NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary]), NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary]),
'origin should have correct notification' 'origin should have correct notification'
) )
@ -557,18 +557,18 @@ describe('permissions controller', function () {
notifications = initNotifications() notifications = initNotifications()
permController = initPermController(notifications) permController = initPermController(notifications)
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.b.permitted)
) )
}) })
it('should throw if account is not a string', async function () { it('should throw if account is not a string', async function () {
await assert.rejects( await assert.rejects(
() => permController.removePermittedAccount(ORIGINS.a, {}), () => permController.removePermittedAccount(DOMAINS.a.origin, {}),
ERRORS.validatePermittedAccounts.nonKeyringAccount({}), ERRORS.validatePermittedAccounts.nonKeyringAccount({}),
'should throw on non-string account param' 'should throw on non-string account param'
) )
@ -576,7 +576,7 @@ describe('permissions controller', function () {
it('should throw if given account is not in keyring', async function () { it('should throw if given account is not in keyring', async function () {
await assert.rejects( await assert.rejects(
() => permController.removePermittedAccount(ORIGINS.a, DUMMY_ACCOUNT), () => permController.removePermittedAccount(DOMAINS.a.origin, DUMMY_ACCOUNT),
ERRORS.validatePermittedAccounts.nonKeyringAccount(DUMMY_ACCOUNT), ERRORS.validatePermittedAccounts.nonKeyringAccount(DUMMY_ACCOUNT),
'should throw on non-keyring account' 'should throw on non-keyring account'
) )
@ -592,7 +592,7 @@ describe('permissions controller', function () {
it('should throw if origin lacks any permissions', async function () { it('should throw if origin lacks any permissions', async function () {
await assert.rejects( await assert.rejects(
() => permController.removePermittedAccount(ORIGINS.c, EXTRA_ACCOUNT), () => permController.removePermittedAccount(DOMAINS.c.origin, EXTRA_ACCOUNT),
ERRORS.removePermittedAccount.invalidOrigin(), ERRORS.removePermittedAccount.invalidOrigin(),
'should throw on origin without permissions' 'should throw on origin without permissions'
) )
@ -600,12 +600,12 @@ describe('permissions controller', function () {
it('should throw if origin lacks eth_accounts permission', async function () { it('should throw if origin lacks eth_accounts permission', async function () {
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.test_method() PERMS.finalizedRequests.test_method()
) )
await assert.rejects( await assert.rejects(
() => permController.removePermittedAccount(ORIGINS.c, EXTRA_ACCOUNT), () => permController.removePermittedAccount(DOMAINS.c.origin, EXTRA_ACCOUNT),
ERRORS.removePermittedAccount.noEthAccountsPermission(), ERRORS.removePermittedAccount.noEthAccountsPermission(),
'should throw on origin without eth_accounts permission' 'should throw on origin without eth_accounts permission'
) )
@ -613,16 +613,16 @@ describe('permissions controller', function () {
it('should throw if account is not permitted', async function () { it('should throw if account is not permitted', async function () {
await assert.rejects( await assert.rejects(
() => permController.removePermittedAccount(ORIGINS.b, ACCOUNTS.c.permitted[0]), () => permController.removePermittedAccount(DOMAINS.b.origin, ACCOUNTS.c.permitted[0]),
ERRORS.removePermittedAccount.notPermitted(), ERRORS.removePermittedAccount.notPermitted(),
'should throw if account is not permitted' 'should throw if account is not permitted'
) )
}) })
it('should successfully remove permitted account', async function () { it('should successfully remove permitted account', async function () {
await permController.removePermittedAccount(ORIGINS.a, ACCOUNTS.a.permitted[1]) await permController.removePermittedAccount(DOMAINS.a.origin, ACCOUNTS.a.permitted[1])
const accounts = await permController._getPermittedAccounts(ORIGINS.a) const accounts = await permController._getPermittedAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
accounts, ACCOUNTS.a.permitted.filter((acc) => acc !== ACCOUNTS.a.permitted[1]), accounts, ACCOUNTS.a.permitted.filter((acc) => acc !== ACCOUNTS.a.permitted[1]),
@ -630,16 +630,16 @@ describe('permissions controller', function () {
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.a][0], notifications[DOMAINS.a.origin][0],
NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary]), NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary]),
'origin should have correct notification' 'origin should have correct notification'
) )
}) })
it('should remove eth_accounts permission if removing only permitted account', async function () { it('should remove eth_accounts permission if removing only permitted account', async function () {
await permController.removePermittedAccount(ORIGINS.b, ACCOUNTS.b.permitted[0]) await permController.removePermittedAccount(DOMAINS.b.origin, ACCOUNTS.b.permitted[0])
const accounts = await permController.getAccounts(ORIGINS.b) const accounts = await permController.getAccounts(DOMAINS.b.origin)
assert.deepEqual( assert.deepEqual(
accounts, [], accounts, [],
@ -647,13 +647,13 @@ describe('permissions controller', function () {
) )
const permission = await permController.permissions.getPermission( const permission = await permController.permissions.getPermission(
ORIGINS.b, PERM_NAMES.eth_accounts DOMAINS.b.origin, PERM_NAMES.eth_accounts
) )
assert.equal(permission, undefined, 'origin should not have eth_accounts permission') assert.equal(permission, undefined, 'origin should not have eth_accounts permission')
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b][0], notifications[DOMAINS.b.origin][0],
NOTIFICATIONS.removedAccounts(), NOTIFICATIONS.removedAccounts(),
'origin should have correct notification' 'origin should have correct notification'
) )
@ -744,11 +744,11 @@ describe('permissions controller', function () {
preferences, preferences,
}) })
grantPermissions( grantPermissions(
permController, ORIGINS.b, permController, DOMAINS.b.origin,
PERMS.finalizedRequests.eth_accounts([...ACCOUNTS.a.permitted, EXTRA_ACCOUNT]) PERMS.finalizedRequests.eth_accounts([...ACCOUNTS.a.permitted, EXTRA_ACCOUNT])
) )
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
}) })
@ -774,11 +774,11 @@ describe('permissions controller', function () {
await onPreferencesUpdate({ selectedAddress: DUMMY_ACCOUNT }) await onPreferencesUpdate({ selectedAddress: DUMMY_ACCOUNT })
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], [], notifications[DOMAINS.b.origin], [],
'should not have emitted notification' 'should not have emitted notification'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.c], [], notifications[DOMAINS.c.origin], [],
'should not have emitted notification' 'should not have emitted notification'
) )
}) })
@ -792,12 +792,12 @@ describe('permissions controller', function () {
await onPreferencesUpdate({ selectedAddress: ACCOUNTS.a.permitted[0] }) await onPreferencesUpdate({ selectedAddress: ACCOUNTS.a.permitted[0] })
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], notifications[DOMAINS.b.origin],
[NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary])], [NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary])],
'should not have emitted notification' 'should not have emitted notification'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.c], notifications[DOMAINS.c.origin],
[NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary])], [NOTIFICATIONS.newAccounts([ACCOUNTS.a.primary])],
'should not have emitted notification' 'should not have emitted notification'
) )
@ -812,12 +812,12 @@ describe('permissions controller', function () {
await onPreferencesUpdate({ selectedAddress: EXTRA_ACCOUNT }) await onPreferencesUpdate({ selectedAddress: EXTRA_ACCOUNT })
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], notifications[DOMAINS.b.origin],
[NOTIFICATIONS.newAccounts([EXTRA_ACCOUNT])], [NOTIFICATIONS.newAccounts([EXTRA_ACCOUNT])],
'should have emitted notification' 'should have emitted notification'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.c], [], notifications[DOMAINS.c.origin], [],
'should not have emitted notification' 'should not have emitted notification'
) )
}) })
@ -831,12 +831,12 @@ describe('permissions controller', function () {
await onPreferencesUpdate({ selectedAddress: ACCOUNTS.a.permitted[1] }) await onPreferencesUpdate({ selectedAddress: ACCOUNTS.a.permitted[1] })
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.b], notifications[DOMAINS.b.origin],
[NOTIFICATIONS.newAccounts([ACCOUNTS.a.permitted[1]])], [NOTIFICATIONS.newAccounts([ACCOUNTS.a.permitted[1]])],
'should have emitted notification' 'should have emitted notification'
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.c], notifications[DOMAINS.c.origin],
[NOTIFICATIONS.newAccounts([ACCOUNTS.c.primary])], [NOTIFICATIONS.newAccounts([ACCOUNTS.c.primary])],
'should have emitted notification' 'should have emitted notification'
) )
@ -1113,7 +1113,7 @@ describe('permissions controller', function () {
let middleware let middleware
assert.doesNotThrow( assert.doesNotThrow(
() => { () => {
middleware = permController.createMiddleware({ origin: ORIGINS.a }) middleware = permController.createMiddleware({ origin: DOMAINS.a.origin })
}, },
'should not throw' 'should not throw'
) )
@ -1137,7 +1137,7 @@ describe('permissions controller', function () {
assert.doesNotThrow( assert.doesNotThrow(
() => { () => {
middleware = permController.createMiddleware({ middleware = permController.createMiddleware({
origin: ORIGINS.a, origin: DOMAINS.a.origin,
extensionId, extensionId,
}) })
}, },
@ -1157,7 +1157,7 @@ describe('permissions controller', function () {
const metadataStore = permController.store.getState()[METADATA_STORE_KEY] const metadataStore = permController.store.getState()[METADATA_STORE_KEY]
assert.deepEqual( assert.deepEqual(
metadataStore[ORIGINS.a], { extensionId, lastUpdated: 1 }, metadataStore[DOMAINS.a.origin], { extensionId, lastUpdated: 1 },
'metadata should be stored' 'metadata should be stored'
) )
}) })
@ -1176,7 +1176,7 @@ describe('permissions controller', function () {
it('notifyAccountsChanged records history and sends notification', async function () { it('notifyAccountsChanged records history and sends notification', async function () {
permController.notifyAccountsChanged( permController.notifyAccountsChanged(
ORIGINS.a, DOMAINS.a.origin,
ACCOUNTS.a.permitted, ACCOUNTS.a.permitted,
) )
@ -1186,7 +1186,7 @@ describe('permissions controller', function () {
) )
assert.deepEqual( assert.deepEqual(
notifications[ORIGINS.a], notifications[DOMAINS.a.origin],
[ NOTIFICATIONS.newAccounts(ACCOUNTS.a.permitted) ], [ NOTIFICATIONS.newAccounts(ACCOUNTS.a.permitted) ],
'origin should have correct notification' 'origin should have correct notification'
) )
@ -1217,7 +1217,7 @@ describe('permissions controller', function () {
assert.throws( assert.throws(
() => permController.notifyAccountsChanged( () => permController.notifyAccountsChanged(
ORIGINS.a, DOMAINS.a.origin,
4, 4,
), ),
ERRORS.notifyAccountsChanged.invalidAccounts(), ERRORS.notifyAccountsChanged.invalidAccounts(),
@ -1226,7 +1226,7 @@ describe('permissions controller', function () {
assert.throws( assert.throws(
() => permController.notifyAccountsChanged( () => permController.notifyAccountsChanged(
ORIGINS.a, DOMAINS.a.origin,
null, null,
), ),
ERRORS.notifyAccountsChanged.invalidAccounts(), ERRORS.notifyAccountsChanged.invalidAccounts(),
@ -1262,13 +1262,13 @@ describe('permissions controller', function () {
permController.store.getState = sinon.fake.returns({ permController.store.getState = sinon.fake.returns({
[METADATA_STORE_KEY]: { [METADATA_STORE_KEY]: {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
foo: 'bar', foo: 'bar',
}, },
}, },
}) })
permController.addDomainMetadata(ORIGINS.b, { foo: 'bar' }) permController.addDomainMetadata(DOMAINS.b.origin, { foo: 'bar' })
assert.ok( assert.ok(
permController.store.getState.called, permController.store.getState.called,
@ -1281,11 +1281,12 @@ describe('permissions controller', function () {
assert.deepEqual( assert.deepEqual(
permController._setDomainMetadata.lastCall.args, permController._setDomainMetadata.lastCall.args,
[{ [{
[ORIGINS.a]: { [DOMAINS.a.origin]: {
foo: 'bar', foo: 'bar',
}, },
[ORIGINS.b]: { [DOMAINS.b.origin]: {
foo: 'bar', foo: 'bar',
host: DOMAINS.b.host,
lastUpdated: 1, lastUpdated: 1,
}, },
}] }]
@ -1296,16 +1297,16 @@ describe('permissions controller', function () {
permController.store.getState = sinon.fake.returns({ permController.store.getState = sinon.fake.returns({
[METADATA_STORE_KEY]: { [METADATA_STORE_KEY]: {
[ORIGINS.a]: { [DOMAINS.a.origin]: {
foo: 'bar', foo: 'bar',
}, },
[ORIGINS.b]: { [DOMAINS.b.origin]: {
bar: 'baz', bar: 'baz',
}, },
}, },
}) })
permController.addDomainMetadata(ORIGINS.b, { foo: 'bar' }) permController.addDomainMetadata(DOMAINS.b.origin, { foo: 'bar' })
assert.ok( assert.ok(
permController.store.getState.called, permController.store.getState.called,
@ -1318,12 +1319,13 @@ describe('permissions controller', function () {
assert.deepEqual( assert.deepEqual(
permController._setDomainMetadata.lastCall.args, permController._setDomainMetadata.lastCall.args,
[{ [{
[ORIGINS.a]: { [DOMAINS.a.origin]: {
foo: 'bar', foo: 'bar',
}, },
[ORIGINS.b]: { [DOMAINS.b.origin]: {
foo: 'bar', foo: 'bar',
bar: 'baz', bar: 'baz',
host: DOMAINS.b.host,
lastUpdated: 1, lastUpdated: 1,
}, },
}] }]
@ -1347,7 +1349,7 @@ describe('permissions controller', function () {
permController._pendingSiteMetadata.add(origin) permController._pendingSiteMetadata.add(origin)
}) })
permController.addDomainMetadata(ORIGINS.a, { foo: 'bar' }) permController.addDomainMetadata(DOMAINS.a.origin, { foo: 'bar' })
assert.ok( assert.ok(
permController.store.getState.called, permController.store.getState.called,
@ -1356,8 +1358,9 @@ describe('permissions controller', function () {
const expectedMetadata = { const expectedMetadata = {
...mockMetadata, ...mockMetadata,
[ORIGINS.a]: { [DOMAINS.a.origin]: {
foo: 'bar', foo: 'bar',
host: DOMAINS.a.host,
lastUpdated: 1, lastUpdated: 1,
}, },
} }
@ -1385,12 +1388,12 @@ describe('permissions controller', function () {
it('trims domain metadata for domains without permissions', function () { it('trims domain metadata for domains without permissions', function () {
const metadataArg = { const metadataArg = {
[ORIGINS.a]: {}, [DOMAINS.a.origin]: {},
[ORIGINS.b]: {}, [DOMAINS.b.origin]: {},
} }
permController.permissions.getDomains = sinon.fake.returns({ permController.permissions.getDomains = sinon.fake.returns({
[ORIGINS.a]: {}, [DOMAINS.a.origin]: {},
}) })
const metadataResult = permController._trimDomainMetadata(metadataArg) const metadataResult = permController._trimDomainMetadata(metadataArg)
@ -1402,7 +1405,7 @@ describe('permissions controller', function () {
assert.deepEqual( assert.deepEqual(
metadataResult, metadataResult,
{ {
[ORIGINS.a]: {}, [DOMAINS.a.origin]: {},
}, },
'should have produced expected state' 'should have produced expected state'
) )
@ -1430,7 +1433,7 @@ describe('permissions controller', function () {
it('_addPendingApproval: should throw if adding origin twice', function () { it('_addPendingApproval: should throw if adding origin twice', function () {
const id = nanoid() const id = nanoid()
const origin = ORIGINS.a const origin = DOMAINS.a
permController._addPendingApproval(id, origin, noop, noop) permController._addPendingApproval(id, origin, noop, noop)

View File

@ -29,7 +29,7 @@ const {
const { const {
ACCOUNTS, ACCOUNTS,
EXPECTED_HISTORIES, EXPECTED_HISTORIES,
ORIGINS, DOMAINS,
PERM_NAMES, PERM_NAMES,
REQUEST_IDS, REQUEST_IDS,
RESTRICTED_METHODS, RESTRICTED_METHODS,
@ -86,7 +86,7 @@ describe('permissions log', function () {
// test_method, success // test_method, success
req = RPC_REQUESTS.test_method(ORIGINS.a) req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
req.id = REQUEST_IDS.a req.id = REQUEST_IDS.a
res = { foo: 'bar' } res = { foo: 'bar' }
@ -103,7 +103,7 @@ describe('permissions log', function () {
// eth_accounts, failure // eth_accounts, failure
req = RPC_REQUESTS.eth_accounts(ORIGINS.b) req = RPC_REQUESTS.eth_accounts(DOMAINS.b.origin)
req.id = REQUEST_IDS.b req.id = REQUEST_IDS.b
res = { error: new Error('Unauthorized.') } res = { error: new Error('Unauthorized.') }
@ -120,7 +120,7 @@ describe('permissions log', function () {
// eth_requestAccounts, success // eth_requestAccounts, success
req = RPC_REQUESTS.eth_requestAccounts(ORIGINS.c) req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin)
req.id = REQUEST_IDS.c req.id = REQUEST_IDS.c
res = { result: ACCOUNTS.c.permitted } res = { result: ACCOUNTS.c.permitted }
@ -137,7 +137,7 @@ describe('permissions log', function () {
// test_method, no response // test_method, no response
req = RPC_REQUESTS.test_method(ORIGINS.a) req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
req.id = REQUEST_IDS.a req.id = REQUEST_IDS.a
res = null res = null
@ -170,7 +170,7 @@ describe('permissions log', function () {
const id2 = nanoid() const id2 = nanoid()
const id3 = nanoid() const id3 = nanoid()
const req = RPC_REQUESTS.test_method(ORIGINS.a) const req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
// get make requests // get make requests
req.id = id1 req.id = id1
@ -230,7 +230,7 @@ describe('permissions log', function () {
it('handles a lack of response', function () { it('handles a lack of response', function () {
let req = RPC_REQUESTS.test_method(ORIGINS.a) let req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
req.id = REQUEST_IDS.a req.id = REQUEST_IDS.a
let res = { foo: 'bar' } let res = { foo: 'bar' }
@ -247,7 +247,7 @@ describe('permissions log', function () {
) )
// next request should be handled as normal // next request should be handled as normal
req = RPC_REQUESTS.eth_accounts(ORIGINS.b) req = RPC_REQUESTS.eth_accounts(DOMAINS.b.origin)
req.id = REQUEST_IDS.b req.id = REQUEST_IDS.b
res = { result: ACCOUNTS.b.permitted } res = { result: ACCOUNTS.b.permitted }
@ -272,9 +272,9 @@ describe('permissions log', function () {
assert.equal(log.length, 0, 'log should be empty') assert.equal(log.length, 0, 'log should be empty')
const res = { foo: 'bar' } const res = { foo: 'bar' }
const req1 = RPC_REQUESTS.wallet_sendDomainMetadata(ORIGINS.c, 'foobar') const req1 = RPC_REQUESTS.wallet_sendDomainMetadata(DOMAINS.c.origin, 'foobar')
const req2 = RPC_REQUESTS.custom(ORIGINS.b, 'eth_getBlockNumber') const req2 = RPC_REQUESTS.custom(DOMAINS.b.origin, 'eth_getBlockNumber')
const req3 = RPC_REQUESTS.custom(ORIGINS.b, 'net_version') const req3 = RPC_REQUESTS.custom(DOMAINS.b.origin, 'net_version')
logMiddleware(req1, res) logMiddleware(req1, res)
logMiddleware(req2, res) logMiddleware(req2, res)
@ -286,7 +286,7 @@ describe('permissions log', function () {
it('enforces log limit', function () { it('enforces log limit', function () {
const req = RPC_REQUESTS.test_method(ORIGINS.a) const req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
const res = { foo: 'bar' } const res = { foo: 'bar' }
// max out log // max out log
@ -352,7 +352,7 @@ describe('permissions log', function () {
let permHistory let permHistory
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
) )
const res = { result: [ PERMS.granted.test_method() ] } const res = { result: [ PERMS.granted.test_method() ] }
@ -371,7 +371,7 @@ describe('permissions log', function () {
'history should have single origin' 'history should have single origin'
) )
assert.ok( assert.ok(
Boolean(permHistory[ORIGINS.a]), Boolean(permHistory[DOMAINS.a.origin]),
'history should have expected origin' 'history should have expected origin'
) )
}) })
@ -379,7 +379,7 @@ describe('permissions log', function () {
it('ignores malformed permissions requests', function () { it('ignores malformed permissions requests', function () {
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
) )
delete req.params delete req.params
const res = { result: [ PERMS.granted.test_method() ] } const res = { result: [ PERMS.granted.test_method() ] }
@ -395,7 +395,7 @@ describe('permissions log', function () {
let permHistory let permHistory
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = { const res = {
result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ], result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ],
@ -433,7 +433,7 @@ describe('permissions log', function () {
it('handles eth_accounts response without caveats', async function () { it('handles eth_accounts response without caveats', async function () {
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = { const res = {
result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ], result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ],
@ -453,7 +453,7 @@ describe('permissions log', function () {
it('handles extra caveats for eth_accounts', async function () { it('handles extra caveats for eth_accounts', async function () {
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = { const res = {
result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ], result: [ PERMS.granted.eth_accounts(ACCOUNTS.a.permitted) ],
@ -476,7 +476,7 @@ describe('permissions log', function () {
it('handles unrequested permissions on the response', async function () { it('handles unrequested permissions on the response', async function () {
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = { const res = {
result: [ result: [
@ -499,7 +499,7 @@ describe('permissions log', function () {
it('does not update history if no new permissions are approved', async function () { it('does not update history if no new permissions are approved', async function () {
let req = RPC_REQUESTS.requestPermission( let req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
) )
let res = { let res = {
result: [ result: [
@ -522,7 +522,7 @@ describe('permissions log', function () {
clock.tick(1) clock.tick(1)
req = RPC_REQUESTS.requestPermission( req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
res = { res = {
result: [ result: [
@ -553,7 +553,7 @@ describe('permissions log', function () {
// first origin // first origin
round1.push({ round1.push({
req: RPC_REQUESTS.requestPermission( req: RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
), ),
res: { res: {
result: [ PERMS.granted.test_method() ], result: [ PERMS.granted.test_method() ],
@ -563,7 +563,7 @@ describe('permissions log', function () {
// second origin // second origin
round1.push({ round1.push({
req: RPC_REQUESTS.requestPermission( req: RPC_REQUESTS.requestPermission(
ORIGINS.b, PERM_NAMES.eth_accounts DOMAINS.b.origin, PERM_NAMES.eth_accounts
), ),
res: { res: {
result: [ PERMS.granted.eth_accounts(ACCOUNTS.b.permitted) ], result: [ PERMS.granted.eth_accounts(ACCOUNTS.b.permitted) ],
@ -572,7 +572,7 @@ describe('permissions log', function () {
// third origin // third origin
round1.push({ round1.push({
req: RPC_REQUESTS.requestPermissions(ORIGINS.c, { req: RPC_REQUESTS.requestPermissions(DOMAINS.c.origin, {
[PERM_NAMES.test_method]: {}, [PERM_NAMES.test_method]: {},
[PERM_NAMES.eth_accounts]: {}, [PERM_NAMES.eth_accounts]: {},
}), }),
@ -611,7 +611,7 @@ describe('permissions log', function () {
// first origin // first origin
round2.push({ round2.push({
req: RPC_REQUESTS.requestPermission( req: RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
), ),
res: { res: {
result: [ PERMS.granted.test_method() ], result: [ PERMS.granted.test_method() ],
@ -622,7 +622,7 @@ describe('permissions log', function () {
// third origin // third origin
round2.push({ round2.push({
req: RPC_REQUESTS.requestPermissions(ORIGINS.c, { req: RPC_REQUESTS.requestPermissions(DOMAINS.c.origin, {
[PERM_NAMES.eth_accounts]: {}, [PERM_NAMES.eth_accounts]: {},
}), }),
res: { res: {

View File

@ -30,7 +30,7 @@ const {
const { const {
ACCOUNTS, ACCOUNTS,
ORIGINS, DOMAINS,
PERM_NAMES, PERM_NAMES,
} = constants } = constants
@ -63,10 +63,10 @@ describe('permissions middleware', function () {
it('grants permissions on user approval', async function () { it('grants permissions on user approval', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = {} const res = {}
@ -99,11 +99,11 @@ describe('permissions middleware', function () {
validatePermission( validatePermission(
res.result[0], res.result[0],
PERM_NAMES.eth_accounts, PERM_NAMES.eth_accounts,
ORIGINS.a, DOMAINS.a.origin,
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) CAVEATS.eth_accounts(ACCOUNTS.a.permitted)
) )
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], aAccounts, [ACCOUNTS.a.primary],
'origin should have correct accounts' 'origin should have correct accounts'
@ -111,7 +111,7 @@ describe('permissions middleware', function () {
assert.ok( assert.ok(
permController.notifyAccountsChanged.calledOnceWith( permController.notifyAccountsChanged.calledOnceWith(
ORIGINS.a, aAccounts, DOMAINS.a.origin, aAccounts,
), ),
'expected notification call should have been made' 'expected notification call should have been made'
) )
@ -119,12 +119,12 @@ describe('permissions middleware', function () {
it('handles serial approved requests that overwrite existing permissions', async function () { it('handles serial approved requests that overwrite existing permissions', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
// create first request // create first request
const req1 = RPC_REQUESTS.requestPermission( const req1 = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res1 = {} const res1 = {}
@ -155,11 +155,11 @@ describe('permissions middleware', function () {
validatePermission( validatePermission(
res1.result[0], res1.result[0],
PERM_NAMES.eth_accounts, PERM_NAMES.eth_accounts,
ORIGINS.a, DOMAINS.a.origin,
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) CAVEATS.eth_accounts(ACCOUNTS.a.permitted)
) )
const accounts1 = await permController.getAccounts(ORIGINS.a) const accounts1 = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
accounts1, [ACCOUNTS.a.primary], accounts1, [ACCOUNTS.a.primary],
'origin should have correct accounts' 'origin should have correct accounts'
@ -167,7 +167,7 @@ describe('permissions middleware', function () {
assert.ok( assert.ok(
permController.notifyAccountsChanged.calledOnceWith( permController.notifyAccountsChanged.calledOnceWith(
ORIGINS.a, accounts1, DOMAINS.a.origin, accounts1,
), ),
'expected notification call should have been made' 'expected notification call should have been made'
) )
@ -180,7 +180,7 @@ describe('permissions middleware', function () {
} }
const req2 = RPC_REQUESTS.requestPermissions( const req2 = RPC_REQUESTS.requestPermissions(
ORIGINS.a, { ...requestedPerms2 } DOMAINS.a.origin, { ...requestedPerms2 }
) )
const res2 = {} const res2 = {}
@ -211,17 +211,17 @@ describe('permissions middleware', function () {
validatePermission( validatePermission(
res2.result[0], res2.result[0],
PERM_NAMES.eth_accounts, PERM_NAMES.eth_accounts,
ORIGINS.a, DOMAINS.a.origin,
CAVEATS.eth_accounts(ACCOUNTS.b.permitted) CAVEATS.eth_accounts(ACCOUNTS.b.permitted)
) )
validatePermission( validatePermission(
res2.result[1], res2.result[1],
PERM_NAMES.test_method, PERM_NAMES.test_method,
ORIGINS.a, DOMAINS.a.origin,
) )
const accounts2 = await permController.getAccounts(ORIGINS.a) const accounts2 = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
accounts2, [ACCOUNTS.b.primary], accounts2, [ACCOUNTS.b.primary],
'origin should have correct accounts' 'origin should have correct accounts'
@ -234,7 +234,7 @@ describe('permissions middleware', function () {
assert.ok( assert.ok(
permController.notifyAccountsChanged.lastCall.calledWith( permController.notifyAccountsChanged.lastCall.calledWith(
ORIGINS.a, accounts2, DOMAINS.a.origin, accounts2,
), ),
'expected notification call should have been made' 'expected notification call should have been made'
) )
@ -242,10 +242,10 @@ describe('permissions middleware', function () {
it('rejects permissions on user rejection', async function () { it('rejects permissions on user rejection', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.requestPermission( const req = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.eth_accounts DOMAINS.a.origin, PERM_NAMES.eth_accounts
) )
const res = {} const res = {}
@ -275,7 +275,7 @@ describe('permissions middleware', function () {
'response should have expected error and no result' 'response should have expected error and no result'
) )
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [], 'origin should have have correct accounts' aAccounts, [], 'origin should have have correct accounts'
) )
@ -288,10 +288,10 @@ describe('permissions middleware', function () {
it('rejects requests with unknown permissions', async function () { it('rejects requests with unknown permissions', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.requestPermissions( const req = RPC_REQUESTS.requestPermissions(
ORIGINS.a, { DOMAINS.a.origin, {
...PERMS.requests.does_not_exist(), ...PERMS.requests.does_not_exist(),
...PERMS.requests.test_method(), ...PERMS.requests.test_method(),
} }
@ -333,13 +333,13 @@ describe('permissions middleware', function () {
// two middlewares for two origins // two middlewares for two origins
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const bMiddleware = getPermissionsMiddleware(permController, ORIGINS.b) const bMiddleware = getPermissionsMiddleware(permController, DOMAINS.b.origin)
// create and start processing first request for first origin // create and start processing first request for first origin
const reqA1 = RPC_REQUESTS.requestPermission( const reqA1 = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
) )
const resA1 = {} const resA1 = {}
@ -351,7 +351,7 @@ describe('permissions middleware', function () {
// create and start processing first request for second origin // create and start processing first request for second origin
const reqB1 = RPC_REQUESTS.requestPermission( const reqB1 = RPC_REQUESTS.requestPermission(
ORIGINS.b, PERM_NAMES.test_method DOMAINS.b.origin, PERM_NAMES.test_method
) )
const resB1 = {} const resB1 = {}
@ -369,7 +369,7 @@ describe('permissions middleware', function () {
// which should throw // which should throw
const reqA2 = RPC_REQUESTS.requestPermission( const reqA2 = RPC_REQUESTS.requestPermission(
ORIGINS.a, PERM_NAMES.test_method DOMAINS.a.origin, PERM_NAMES.test_method
) )
const resA2 = {} const resA2 = {}
@ -439,9 +439,9 @@ describe('permissions middleware', function () {
it('prevents restricted method access for unpermitted domain', async function () { it('prevents restricted method access for unpermitted domain', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.test_method(ORIGINS.a) const req = RPC_REQUESTS.test_method(DOMAINS.a.origin)
const res = {} const res = {}
const expectedError = ERRORS.rpcCap.unauthorized() const expectedError = ERRORS.rpcCap.unauthorized()
@ -463,11 +463,11 @@ describe('permissions middleware', function () {
it('allows restricted method access for permitted domain', async function () { it('allows restricted method access for permitted domain', async function () {
const bMiddleware = getPermissionsMiddleware(permController, ORIGINS.b) const bMiddleware = getPermissionsMiddleware(permController, DOMAINS.b.origin)
grantPermissions(permController, ORIGINS.b, PERMS.finalizedRequests.test_method()) grantPermissions(permController, DOMAINS.b.origin, PERMS.finalizedRequests.test_method())
const req = RPC_REQUESTS.test_method(ORIGINS.b, true) const req = RPC_REQUESTS.test_method(DOMAINS.b.origin, true)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -492,9 +492,9 @@ describe('permissions middleware', function () {
it('returns empty array for non-permitted domain', async function () { it('returns empty array for non-permitted domain', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.eth_accounts(ORIGINS.a) const req = RPC_REQUESTS.eth_accounts(DOMAINS.a.origin)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -514,14 +514,14 @@ describe('permissions middleware', function () {
it('returns correct accounts for permitted domain', async function () { it('returns correct accounts for permitted domain', async function () {
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
grantPermissions( grantPermissions(
permController, ORIGINS.a, permController, DOMAINS.a.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted)
) )
const req = RPC_REQUESTS.eth_accounts(ORIGINS.a) const req = RPC_REQUESTS.eth_accounts(DOMAINS.a.origin)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -552,9 +552,9 @@ describe('permissions middleware', function () {
const userApprovalPromise = getUserApprovalPromise(permController) const userApprovalPromise = getUserApprovalPromise(permController)
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.eth_requestAccounts(ORIGINS.a) const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.a.origin)
const res = {} const res = {}
const pendingApproval = assert.doesNotReject( const pendingApproval = assert.doesNotReject(
@ -577,7 +577,7 @@ describe('permissions middleware', function () {
// wait for permission to be granted // wait for permission to be granted
await pendingApproval await pendingApproval
const perms = permController.permissions.getPermissionsForDomain(ORIGINS.a) const perms = permController.permissions.getPermissionsForDomain(DOMAINS.a.origin)
assert.equal( assert.equal(
perms.length, 1, perms.length, 1,
@ -587,7 +587,7 @@ describe('permissions middleware', function () {
validatePermission( validatePermission(
perms[0], perms[0],
PERM_NAMES.eth_accounts, PERM_NAMES.eth_accounts,
ORIGINS.a, DOMAINS.a.origin,
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) CAVEATS.eth_accounts(ACCOUNTS.a.permitted)
) )
@ -603,7 +603,7 @@ describe('permissions middleware', function () {
) )
// we should also be able to get the accounts independently // we should also be able to get the accounts independently
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [ACCOUNTS.a.primary], 'origin should have have correct accounts' aAccounts, [ACCOUNTS.a.primary], 'origin should have have correct accounts'
) )
@ -613,9 +613,9 @@ describe('permissions middleware', function () {
const userApprovalPromise = getUserApprovalPromise(permController) const userApprovalPromise = getUserApprovalPromise(permController)
const aMiddleware = getPermissionsMiddleware(permController, ORIGINS.a) const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin)
const req = RPC_REQUESTS.eth_requestAccounts(ORIGINS.a) const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.a.origin)
const res = {} const res = {}
const expectedError = ERRORS.rejectPermissionsRequest.rejection() const expectedError = ERRORS.rejectPermissionsRequest.rejection()
@ -646,7 +646,7 @@ describe('permissions middleware', function () {
'response should have expected error and no result' 'response should have expected error and no result'
) )
const aAccounts = await permController.getAccounts(ORIGINS.a) const aAccounts = await permController.getAccounts(DOMAINS.a.origin)
assert.deepEqual( assert.deepEqual(
aAccounts, [], 'origin should have have correct accounts' aAccounts, [], 'origin should have have correct accounts'
) )
@ -654,14 +654,14 @@ describe('permissions middleware', function () {
it('directly returns accounts for permitted domain', async function () { it('directly returns accounts for permitted domain', async function () {
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin)
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted)
) )
const req = RPC_REQUESTS.eth_requestAccounts(ORIGINS.c) const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -688,14 +688,14 @@ describe('permissions middleware', function () {
permController.getUnlockPromise = () => unlockPromise permController.getUnlockPromise = () => unlockPromise
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin)
grantPermissions( grantPermissions(
permController, ORIGINS.c, permController, DOMAINS.c.origin,
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted) PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted)
) )
const req = RPC_REQUESTS.eth_requestAccounts(ORIGINS.c) const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin)
const res = {} const res = {}
// this will block until we resolve the unlock Promise // this will block until we resolve the unlock Promise
@ -743,9 +743,9 @@ describe('permissions middleware', function () {
const name = 'BAZ' const name = 'BAZ'
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin)
const req = RPC_REQUESTS.wallet_sendDomainMetadata(ORIGINS.c, name) const req = RPC_REQUESTS.wallet_sendDomainMetadata(DOMAINS.c.origin, name)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -759,7 +759,13 @@ describe('permissions middleware', function () {
assert.deepEqual( assert.deepEqual(
metadataStore, metadataStore,
{ [ORIGINS.c]: { name, lastUpdated: 1 } }, {
[DOMAINS.c.origin]: {
name,
host: DOMAINS.c.host,
lastUpdated: 1,
},
},
'metadata should have been added to store' 'metadata should have been added to store'
) )
}) })
@ -770,9 +776,9 @@ describe('permissions middleware', function () {
const name = 'BAZ' const name = 'BAZ'
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c, extensionId) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin, extensionId)
const req = RPC_REQUESTS.wallet_sendDomainMetadata(ORIGINS.c, name) const req = RPC_REQUESTS.wallet_sendDomainMetadata(DOMAINS.c.origin, name)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -786,7 +792,7 @@ describe('permissions middleware', function () {
assert.deepEqual( assert.deepEqual(
metadataStore, metadataStore,
{ [ORIGINS.c]: { name, extensionId, lastUpdated: 1 } }, { [DOMAINS.c.origin]: { name, extensionId, lastUpdated: 1 } },
'metadata should have been added to store' 'metadata should have been added to store'
) )
}) })
@ -795,9 +801,9 @@ describe('permissions middleware', function () {
const name = null const name = null
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin)
const req = RPC_REQUESTS.wallet_sendDomainMetadata(ORIGINS.c, name) const req = RPC_REQUESTS.wallet_sendDomainMetadata(DOMAINS.c.origin, name)
const res = {} const res = {}
await assert.doesNotReject( await assert.doesNotReject(
@ -817,9 +823,9 @@ describe('permissions middleware', function () {
it('should not record domain metadata if no metadata', async function () { it('should not record domain metadata if no metadata', async function () {
const cMiddleware = getPermissionsMiddleware(permController, ORIGINS.c) const cMiddleware = getPermissionsMiddleware(permController, DOMAINS.c.origin)
const req = RPC_REQUESTS.wallet_sendDomainMetadata(ORIGINS.c) const req = RPC_REQUESTS.wallet_sendDomainMetadata(DOMAINS.c.origin)
delete req.domainMetadata delete req.domainMetadata
const res = {} const res = {}

View File

@ -1,6 +1,7 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import IconWithFallBack from '../../ui/icon-with-fallback' import IconWithFallBack from '../../ui/icon-with-fallback'
import { stripHttpSchemes } from '../../../helpers/utils/util'
export default class ConnectedSitesList extends Component { export default class ConnectedSitesList extends Component {
static contextTypes = { static contextTypes = {
@ -11,9 +12,11 @@ export default class ConnectedSitesList extends Component {
connectedDomains: PropTypes.arrayOf(PropTypes.shape({ connectedDomains: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string, name: PropTypes.string,
icon: PropTypes.string, icon: PropTypes.string,
key: PropTypes.string, origin: PropTypes.string,
host: PropTypes.string,
})).isRequired, })).isRequired,
onDisconnect: PropTypes.func.isRequired, onDisconnect: PropTypes.func.isRequired,
domainHostCount: PropTypes.objectOf(PropTypes.number).isRequired,
} }
render () { render () {
@ -23,25 +26,31 @@ export default class ConnectedSitesList extends Component {
return ( return (
<main className="connected-sites-list__content-rows"> <main className="connected-sites-list__content-rows">
{ connectedDomains.map((domain) => ( { connectedDomains.map((domain) => (
<div key={domain.key} className="connected-sites-list__content-row"> <div key={domain.origin} className="connected-sites-list__content-row">
<div className="connected-sites-list__domain-info"> <div className="connected-sites-list__domain-info">
<IconWithFallBack icon={domain.icon} name={domain.name} /> <IconWithFallBack icon={domain.icon} name={domain.name} />
<span className="connected-sites-list__domain-name" title={domain.extensionId || domain.key}> <span className="connected-sites-list__domain-name" title={domain.extensionId || domain.origin}>
{ {this.getDomainDisplayName(domain)}
domain.extensionId
? t('externalExtension')
: domain.key
}
</span> </span>
</div> </div>
<i <i
className="fas fa-trash-alt connected-sites-list__trash" className="fas fa-trash-alt connected-sites-list__trash"
title={t('disconnect')} title={t('disconnect')}
onClick={() => onDisconnect(domain.key)} onClick={() => onDisconnect(domain.origin)}
/> />
</div> </div>
)) } )) }
</main> </main>
) )
} }
getDomainDisplayName (domain) {
if (domain.extensionId) {
return this.context.t('externalExtension')
}
return this.props.domainHostCount[domain.host] > 1
? domain.origin
: stripHttpSchemes(domain.origin)
}
} }

View File

@ -297,3 +297,15 @@ export function isValidAddressHead (address) {
export function getAccountByAddress (accounts = [], targetAddress) { export function getAccountByAddress (accounts = [], targetAddress) {
return accounts.find(({ address }) => address === targetAddress) return accounts.find(({ address }) => address === targetAddress)
} }
/**
* Strips the following schemes from URL strings:
* - http
* - https
*
* @param {string} urlString - The URL string to strip the scheme from.
* @returns {string} The URL string, without the scheme, if it was stripped.
*/
export function stripHttpSchemes (urlString) {
return urlString.replace(/^https?:\/\//u, '')
}

View File

@ -54,7 +54,7 @@ export default class ConnectedAccounts extends PureComponent {
return ( return (
<Popover <Popover
title={isActiveTabExtension ? t('currentExtension') : activeTabOrigin} title={isActiveTabExtension ? t('currentExtension') : new URL(activeTabOrigin).host}
subtitle={connectedAccounts.length ? connectedAccountsDescription : t('connectedAccountsEmptyDescription')} subtitle={connectedAccounts.length ? connectedAccountsDescription : t('connectedAccountsEmptyDescription')}
onClose={() => history.push(mostRecentOverviewPage)} onClose={() => history.push(mostRecentOverviewPage)}
footerClassName="connected-accounts__footer" footerClassName="connected-accounts__footer"

View File

@ -17,6 +17,7 @@ export default class ConnectedSites extends Component {
accountLabel: PropTypes.string.isRequired, accountLabel: PropTypes.string.isRequired,
closePopover: PropTypes.func.isRequired, closePopover: PropTypes.func.isRequired,
connectedDomains: PropTypes.arrayOf(PropTypes.object).isRequired, connectedDomains: PropTypes.arrayOf(PropTypes.object).isRequired,
domainHostCount: PropTypes.objectOf(PropTypes.number).isRequired,
disconnectAllAccounts: PropTypes.func.isRequired, disconnectAllAccounts: PropTypes.func.isRequired,
disconnectAccount: PropTypes.func.isRequired, disconnectAccount: PropTypes.func.isRequired,
getOpenMetamaskTabsIds: PropTypes.func.isRequired, getOpenMetamaskTabsIds: PropTypes.func.isRequired,
@ -69,6 +70,7 @@ export default class ConnectedSites extends Component {
renderConnectedSitesList () { renderConnectedSitesList () {
return ( return (
<ConnectedSitesList <ConnectedSitesList
domainHostCount={this.props.domainHostCount}
connectedDomains={this.props.connectedDomains} connectedDomains={this.props.connectedDomains}
onDisconnect={this.setPendingDisconnect} onDisconnect={this.setPendingDisconnect}
/> />

View File

@ -11,6 +11,7 @@ import {
getCurrentAccountWithSendEtherInfo, getCurrentAccountWithSendEtherInfo,
getOriginOfCurrentTab, getOriginOfCurrentTab,
getPermissionDomains, getPermissionDomains,
getPermissionsMetadataHostCounts,
getPermittedAccountsByOrigin, getPermittedAccountsByOrigin,
getSelectedAddress, getSelectedAddress,
} from '../../selectors' } from '../../selectors'
@ -40,6 +41,7 @@ const mapStateToProps = (state) => {
accountLabel: getCurrentAccountWithSendEtherInfo(state).name, accountLabel: getCurrentAccountWithSendEtherInfo(state).name,
connectedDomains, connectedDomains,
domains: getPermissionDomains(state), domains: getPermissionDomains(state),
domainHostCount: getPermissionsMetadataHostCounts(state),
mostRecentOverviewPage: getMostRecentOverviewPage(state), mostRecentOverviewPage: getMostRecentOverviewPage(state),
permittedAccountsByOrigin, permittedAccountsByOrigin,
selectedAddress, selectedAddress,

View File

@ -104,13 +104,15 @@ export function getConnectedDomainsForSelectedAddress (state) {
extensionId, extensionId,
name, name,
icon, icon,
host,
} = domainMetadata[domainKey] || {} } = domainMetadata[domainKey] || {}
connectedDomains.push({ connectedDomains.push({
extensionId, extensionId,
key: domainKey, origin: domainKey,
name, name,
icon, icon,
host,
}) })
}) })
@ -261,6 +263,20 @@ export function getLastConnectedInfo (state) {
}, {}) }, {})
} }
export function getPermissionsMetadataHostCounts (state) {
const metadata = getPermissionDomainsMetadata(state)
return Object.values(metadata).reduce((counts, { host }) => {
if (host) {
if (!counts[host]) {
counts[host] = 1
} else {
counts[host] += 1
}
}
return counts
}, {})
}
export function getPermissionsRequests (state) { export function getPermissionsRequests (state) {
return state.metamask.permissionsRequests || [] return state.metamask.permissionsRequests || []
} }

View File

@ -16,10 +16,12 @@ describe('selectors', function () {
'peepeth.com': { 'peepeth.com': {
'icon': 'https://peepeth.com/favicon-32x32.png', 'icon': 'https://peepeth.com/favicon-32x32.png',
'name': 'Peepeth', 'name': 'Peepeth',
'host': 'peepeth.com',
}, },
'https://remix.ethereum.org': { 'https://remix.ethereum.org': {
'icon': 'https://remix.ethereum.org/icon.png', 'icon': 'https://remix.ethereum.org/icon.png',
'name': 'Remix - Ethereum IDE', 'name': 'Remix - Ethereum IDE',
'host': 'remix.ethereum.org',
}, },
}, },
domains: { domains: {
@ -74,13 +76,15 @@ describe('selectors', function () {
assert.deepEqual(getConnectedDomainsForSelectedAddress(mockState), [{ assert.deepEqual(getConnectedDomainsForSelectedAddress(mockState), [{
extensionId, extensionId,
icon: 'https://peepeth.com/favicon-32x32.png', icon: 'https://peepeth.com/favicon-32x32.png',
key: 'peepeth.com', origin: 'peepeth.com',
name: 'Peepeth', name: 'Peepeth',
host: 'peepeth.com',
}, { }, {
extensionId, extensionId,
name: 'Remix - Ethereum IDE', name: 'Remix - Ethereum IDE',
icon: 'https://remix.ethereum.org/icon.png', icon: 'https://remix.ethereum.org/icon.png',
key: 'https://remix.ethereum.org', origin: 'https://remix.ethereum.org',
host: 'remix.ethereum.org',
}]) }])
}) })
@ -92,10 +96,12 @@ describe('selectors', function () {
'peepeth.com': { 'peepeth.com': {
'icon': 'https://peepeth.com/favicon-32x32.png', 'icon': 'https://peepeth.com/favicon-32x32.png',
'name': 'Peepeth', 'name': 'Peepeth',
'host': 'peepeth.com',
}, },
'https://remix.ethereum.org': { 'https://remix.ethereum.org': {
'icon': 'https://remix.ethereum.org/icon.png', 'icon': 'https://remix.ethereum.org/icon.png',
'name': 'Remix - Ethereum IDE', 'name': 'Remix - Ethereum IDE',
'host': 'remix.ethereum.com',
}, },
}, },
domains: { domains: {
@ -152,7 +158,8 @@ describe('selectors', function () {
extensionId, extensionId,
name: 'Remix - Ethereum IDE', name: 'Remix - Ethereum IDE',
icon: 'https://remix.ethereum.org/icon.png', icon: 'https://remix.ethereum.org/icon.png',
key: 'https://remix.ethereum.org', origin: 'https://remix.ethereum.org',
host: 'remix.ethereum.com',
}]) }])
}) })
}) })