Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/phishing-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6587](https://github.com/MetaMask/core/pull/6587))

### Changed

- Bump `@metamask/base-controller` from `^8.0.1` to `^8.3.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
Expand Down
71 changes: 70 additions & 1 deletion packages/phishing-controller/src/PhishingController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Messenger } from '@metamask/base-controller';
import { deriveStateFromMetadata, Messenger } from '@metamask/base-controller';
import { strict as assert } from 'assert';
import nock, { cleanAll, isDone, pendingMocks } from 'nock';
import sinon from 'sinon';
Expand Down Expand Up @@ -3345,4 +3345,73 @@ describe('URL Scan Cache', () => {
const result2 = await controller.scanUrl(invalidUrl);
expect(result2.fetchError).toBeDefined();
});

describe('metadata', () => {
it('includes expected state in debug snapshots', () => {
const controller = getPhishingController();

expect(
deriveStateFromMetadata(
controller.state,
controller.metadata,
'anonymous',
),
).toMatchInlineSnapshot(`Object {}`);
});

it('includes expected state in state logs', () => {
const controller = getPhishingController();

expect(
deriveStateFromMetadata(
controller.state,
controller.metadata,
'includeInStateLogs',
),
).toMatchInlineSnapshot(`
Object {
"c2DomainBlocklistLastFetched": 0,
"hotlistLastFetched": 0,
"stalelistLastFetched": 0,
}
`);
});

it('persists expected state', () => {
const controller = getPhishingController();

expect(
deriveStateFromMetadata(
controller.state,
controller.metadata,
'persist',
),
).toMatchInlineSnapshot(`
Object {
"c2DomainBlocklistLastFetched": 0,
"hotlistLastFetched": 0,
"phishingLists": Array [],
"stalelistLastFetched": 0,
"urlScanCache": Object {},
"whitelist": Array [],
}
`);
});

it('includes expected state in UI', () => {
const controller = getPhishingController();

expect(
deriveStateFromMetadata(
controller.state,
controller.metadata,
'usedInUi',
),
).toMatchInlineSnapshot(`
Object {
"urlScanCache": Object {},
}
`);
});
});
});
45 changes: 38 additions & 7 deletions packages/phishing-controller/src/PhishingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
ControllerGetStateAction,
ControllerStateChangeEvent,
RestrictedMessenger,
StateMetadata,
} from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import {
Expand Down Expand Up @@ -205,13 +206,43 @@ export const phishingListKeyNameMap = {

const controllerName = 'PhishingController';

const metadata = {
phishingLists: { persist: true, anonymous: false },
whitelist: { persist: true, anonymous: false },
hotlistLastFetched: { persist: true, anonymous: false },
stalelistLastFetched: { persist: true, anonymous: false },
c2DomainBlocklistLastFetched: { persist: true, anonymous: false },
urlScanCache: { persist: true, anonymous: false },
const metadata: StateMetadata<PhishingControllerState> = {
phishingLists: {
includeInStateLogs: false,
persist: true,
anonymous: false,
usedInUi: false,
},
whitelist: {
includeInStateLogs: false,
persist: true,
anonymous: false,
usedInUi: false,
},
hotlistLastFetched: {
includeInStateLogs: true,
persist: true,
anonymous: false,
usedInUi: false,
},
stalelistLastFetched: {
includeInStateLogs: true,
persist: true,
anonymous: false,
usedInUi: false,
},
c2DomainBlocklistLastFetched: {
includeInStateLogs: true,
persist: true,
anonymous: false,
usedInUi: false,
},
urlScanCache: {
includeInStateLogs: false,
persist: true,
anonymous: false,
usedInUi: true,
},
};

/**
Expand Down
Loading