mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Making addPermittedAccount and removePermittedAccount methods idempotent (#15709)
This commit is contained in:
parent
cd5398b2b2
commit
8c8539d1f5
@ -14,9 +14,7 @@ export function getPermissionBackgroundApiMethods(permissionController) {
|
||||
);
|
||||
|
||||
if (existing.value.includes(account)) {
|
||||
throw new Error(
|
||||
`eth_accounts permission for origin "${origin}" already permits account "${account}".`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
permissionController.updateCaveat(
|
||||
@ -35,9 +33,7 @@ export function getPermissionBackgroundApiMethods(permissionController) {
|
||||
);
|
||||
|
||||
if (!existing.value.includes(account)) {
|
||||
throw new Error(
|
||||
`eth_accounts permission for origin "${origin}" already does not permit account "${account}".`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const remainingAccounts = existing.value.filter(
|
||||
|
@ -34,7 +34,7 @@ describe('permission background API methods', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('throws if the specified account is already permitted', () => {
|
||||
it('does not add a permitted account', () => {
|
||||
const permissionController = {
|
||||
getCaveat: jest.fn().mockImplementationOnce(() => {
|
||||
return { type: CaveatTypes.restrictReturnedAccounts, value: ['0x1'] };
|
||||
@ -42,14 +42,9 @@ describe('permission background API methods', () => {
|
||||
updateCaveat: jest.fn(),
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
getPermissionBackgroundApiMethods(
|
||||
permissionController,
|
||||
).addPermittedAccount('foo.com', '0x1'),
|
||||
).toThrow(
|
||||
`eth_accounts permission for origin "foo.com" already permits account "0x1".`,
|
||||
);
|
||||
|
||||
getPermissionBackgroundApiMethods(
|
||||
permissionController,
|
||||
).addPermittedAccount('foo.com', '0x1');
|
||||
expect(permissionController.getCaveat).toHaveBeenCalledTimes(1);
|
||||
expect(permissionController.getCaveat).toHaveBeenCalledWith(
|
||||
'foo.com',
|
||||
@ -128,7 +123,7 @@ describe('permission background API methods', () => {
|
||||
expect(permissionController.updateCaveat).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws if the specified account is not permitted', () => {
|
||||
it('does not call permissionController.updateCaveat if the specified account is not permitted', () => {
|
||||
const permissionController = {
|
||||
getCaveat: jest.fn().mockImplementationOnce(() => {
|
||||
return { type: CaveatTypes.restrictReturnedAccounts, value: ['0x1'] };
|
||||
@ -137,14 +132,9 @@ describe('permission background API methods', () => {
|
||||
updateCaveat: jest.fn(),
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
getPermissionBackgroundApiMethods(
|
||||
permissionController,
|
||||
).removePermittedAccount('foo.com', '0x2'),
|
||||
).toThrow(
|
||||
`eth_accounts permission for origin "foo.com" already does not permit account "0x2".`,
|
||||
);
|
||||
|
||||
getPermissionBackgroundApiMethods(
|
||||
permissionController,
|
||||
).removePermittedAccount('foo.com', '0x2');
|
||||
expect(permissionController.getCaveat).toHaveBeenCalledTimes(1);
|
||||
expect(permissionController.getCaveat).toHaveBeenCalledWith(
|
||||
'foo.com',
|
||||
|
Loading…
Reference in New Issue
Block a user