mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
fc1ffae406
This PR introduces the concept of subject _types_ to be associated with each subject in the `SubjectMetadataController`, and used for control flow in our RPC stack (`setupProviderEngine` and so forth). We already differentiate between "types" of subjects in various places on an ad hoc basis via boolean flags (e.g. `isInternal` in our RPC stack) or the presence/absence of certain values in the subject's metadata (specifically `metadata.extensionId`). The status quo is manageable if not ideal, but will start to become untenable with the introduction of Snaps in the near future. Therefore, this PR establishes a `SUBJECT_TYPES` enum and adds the `subjectType` property to the metadata of each subject. A new migration is added to accomplish this. Finally, we specify and `INTERNAL` subject type to distinguish internal from external requests.
103 lines
2.9 KiB
JavaScript
103 lines
2.9 KiB
JavaScript
import { SUBJECT_TYPES } from '../../../shared/constants/app';
|
|
import migration69 from './069';
|
|
|
|
describe('migration #69', () => {
|
|
it('should update the version metadata', async () => {
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 68,
|
|
},
|
|
data: {},
|
|
};
|
|
|
|
const newStorage = await migration69.migrate(oldStorage);
|
|
expect(newStorage.meta).toStrictEqual({
|
|
version: 69,
|
|
});
|
|
});
|
|
|
|
it('should migrate all data', async () => {
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 68,
|
|
},
|
|
data: {
|
|
FooController: { a: 'b' },
|
|
SubjectMetadataController: {
|
|
subjectMetadata: {
|
|
'https://1inch.exchange': {
|
|
iconUrl:
|
|
'https://1inch.exchange/assets/favicon/favicon-32x32.png',
|
|
name: 'DEX Aggregator - 1inch.exchange',
|
|
origin: 'https://1inch.exchange',
|
|
extensionId: null,
|
|
},
|
|
'https://ascii-tree-generator.com': {
|
|
iconUrl: 'https://ascii-tree-generator.com/favicon.ico',
|
|
name: 'ASCII Tree Generator',
|
|
origin: 'https://ascii-tree-generator.com',
|
|
extensionId: 'ascii-tree-generator-extension',
|
|
},
|
|
'https://null.com': null,
|
|
'https://foo.com': 'bad data',
|
|
'https://bar.com': ['bad data'],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const newStorage = await migration69.migrate(oldStorage);
|
|
expect(newStorage).toStrictEqual({
|
|
meta: {
|
|
version: 69,
|
|
},
|
|
data: {
|
|
FooController: { a: 'b' },
|
|
SubjectMetadataController: {
|
|
subjectMetadata: {
|
|
'https://1inch.exchange': {
|
|
iconUrl:
|
|
'https://1inch.exchange/assets/favicon/favicon-32x32.png',
|
|
name: 'DEX Aggregator - 1inch.exchange',
|
|
origin: 'https://1inch.exchange',
|
|
extensionId: null,
|
|
subjectType: SUBJECT_TYPES.WEBSITE,
|
|
},
|
|
'https://ascii-tree-generator.com': {
|
|
iconUrl: 'https://ascii-tree-generator.com/favicon.ico',
|
|
name: 'ASCII Tree Generator',
|
|
origin: 'https://ascii-tree-generator.com',
|
|
extensionId: 'ascii-tree-generator-extension',
|
|
subjectType: SUBJECT_TYPES.EXTENSION,
|
|
},
|
|
'https://null.com': null,
|
|
'https://foo.com': 'bad data',
|
|
'https://bar.com': ['bad data'],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should handle missing SubjectMetadataController', async () => {
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 68,
|
|
},
|
|
data: {
|
|
FooController: { a: 'b' },
|
|
},
|
|
};
|
|
|
|
const newStorage = await migration69.migrate(oldStorage);
|
|
expect(newStorage).toStrictEqual({
|
|
meta: {
|
|
version: 69,
|
|
},
|
|
data: {
|
|
FooController: { a: 'b' },
|
|
},
|
|
});
|
|
});
|
|
});
|