1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 03:12:42 +02:00

Force an update of the phishing warning configuration (#20381)

The "last fetched" state for the `PhishingController` has been deleted
to force an immediate full update of the phishing configuration state.
We're doing this because the state was cleared in v10.34.2 because the
format of that state had changed.

This has been implemented in migration 92. The previous migration 92
has been renamed to 93 because it won't be included until a future
release. We need the migrations to remain sequential, and this will
save us from having to resolve a complex conflict when releasing this.
This commit is contained in:
Mark Stacey 2023-08-03 13:12:21 -02:30 committed by Dan J Miller
parent f526c170e2
commit 75dcb03069
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,78 @@
import { cloneDeep } from 'lodash';
import { migrate, version } from './092';
const PREVIOUS_VERSION = version - 1;
describe('migration #92', () => {
it('should update the version metadata', async () => {
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: {},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({
version,
});
});
it('should return state unaltered if there is no phishing controller state', async () => {
const oldData = {
other: 'data',
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(cloneDeep(oldStorage));
expect(newStorage.data).toStrictEqual(oldData);
});
it('should return state unaltered if there is no phishing controller last fetched state', async () => {
const oldData = {
other: 'data',
PhishingController: {
whitelist: [],
},
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(cloneDeep(oldStorage));
expect(newStorage.data).toStrictEqual(oldData);
});
it('should remove both last fetched properties from phishing controller state', async () => {
const oldData = {
other: 'data',
PhishingController: {
whitelist: [],
hotlistLastFetched: 0,
stalelistLastFetched: 0,
},
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
other: 'data',
PhishingController: {
whitelist: [],
},
});
});
});

View File

@ -0,0 +1,35 @@
import { cloneDeep } from 'lodash';
import { hasProperty, isObject } from '@metamask/utils';
export const version = 92;
/**
* Delete `stalelistLastFetched` and `hotlistLastFetched` to force a phishing configuration refresh
* because the format has changed.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(originalVersionedData: {
meta: { version: number };
data: Record<string, unknown>;
}) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
versionedData.data = transformState(versionedData.data);
return versionedData;
}
function transformState(state: Record<string, unknown>) {
if (
hasProperty(state, 'PhishingController') &&
isObject(state.PhishingController)
) {
delete state.PhishingController.stalelistLastFetched;
delete state.PhishingController.hotlistLastFetched;
}
return state;
}

View File

@ -95,6 +95,7 @@ import * as m088 from './088';
import * as m089 from './089';
import * as m090 from './090';
import * as m091 from './091';
import * as m092 from './092';
const migrations = [
m002,
@ -187,6 +188,7 @@ const migrations = [
m089,
m090,
m091,
m092,
];
export default migrations;