Skip to content

Commit a072312

Browse files
Fix permissions
1 parent 9cf727b commit a072312

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

packages/snaps-controllers/src/snaps/SnapController.test.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ import {
7070
import { hmac } from '@noble/hashes/hmac';
7171
import { sha512 } from '@noble/hashes/sha512';
7272
import { File } from 'buffer';
73+
import { createReadStream } from 'fs';
7374
import fetchMock from 'jest-fetch-mock';
75+
import path from 'path';
7476
import { pipeline } from 'readable-stream';
7577
import type { Duplex } from 'readable-stream';
7678
import { inc } from 'semver';
77-
import path from 'path';
7879
import { Readable } from 'stream';
7980

8081
import {
@@ -123,7 +124,6 @@ import {
123124
waitForStateChange,
124125
} from '../test-utils';
125126
import { delay } from '../utils';
126-
import { createReadStream } from 'fs';
127127

128128
globalThis.crypto.getRandomValues = <Type extends ArrayBufferView | null>(
129129
array: Type,
@@ -10212,32 +10212,34 @@ describe('SnapController', () => {
1021210212
snapController.destroy();
1021310213
});
1021410214

10215-
it.only('updates preinstalled Snaps', async () => {
10215+
it('updates preinstalled Snaps', async () => {
1021610216
const registry = new MockSnapsRegistry();
1021710217
const rootMessenger = getControllerMessenger(registry);
1021810218
const messenger = getSnapControllerMessenger(rootMessenger);
1021910219

1022010220
const snapId = 'npm:@metamask/jsx-example-snap' as SnapId;
1022110221

10222-
const mockSnap = getPersistedSnapObject({ id: snapId, preinstalled: true });
10222+
const mockSnap = getPersistedSnapObject({
10223+
id: snapId,
10224+
preinstalled: true,
10225+
});
1022310226

1022410227
const updateVersion = '1.2.1';
10225-
10228+
1022610229
registry.resolveVersion.mockResolvedValue(updateVersion);
10227-
const fetchFunction = jest.fn()
10228-
.mockResolvedValueOnce({
10229-
// eslint-disable-next-line no-restricted-globals
10230-
headers: new Headers({ 'content-length': '5477' }),
10231-
ok: true,
10232-
body: Readable.toWeb(
10233-
createReadStream(
10234-
path.resolve(
10235-
__dirname,
10236-
`../../test/fixtures/metamask-jsx-example-snap-${updateVersion}.tgz`,
10237-
),
10238-
),
10239-
),
10240-
} as any);
10230+
const fetchFunction = jest.fn().mockResolvedValueOnce({
10231+
// eslint-disable-next-line no-restricted-globals
10232+
headers: new Headers({ 'content-length': '5477' }),
10233+
ok: true,
10234+
body: Readable.toWeb(
10235+
createReadStream(
10236+
path.resolve(
10237+
__dirname,
10238+
`../../test/fixtures/metamask-jsx-example-snap-${updateVersion}.tgz`,
10239+
),
10240+
),
10241+
),
10242+
} as any);
1024110243

1024210244
const snapController = getSnapController(
1024310245
getSnapControllerOptions({

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,8 @@ export class SnapController extends BaseController<
29002900
* @param location - The location implementation of the snap.
29012901
* @param newVersionRange - A semver version range in which the maximum version will be chosen.
29022902
* @param emitEvent - An optional boolean flag to indicate whether this update should emit an event.
2903-
* @param automaticUpdate
2903+
* @param automaticUpdate - An optional boolean flag to indicate whether this update should be done
2904+
* automatically.
29042905
* @returns The snap metadata if updated, `null` otherwise.
29052906
*/
29062907
// TODO: Make hash private
@@ -2992,7 +2993,6 @@ export class SnapController extends BaseController<
29922993
let requestData;
29932994

29942995
if (automaticUpdate) {
2995-
// TODO: This probably doesn't work as it doesn't account for initialConnections.
29962996
approvedNewPermissions = newPermissions;
29972997
} else {
29982998
assert(pendingApproval);
@@ -3008,9 +3008,12 @@ export class SnapController extends BaseController<
30083008
loading: false,
30093009
});
30103010

3011-
const { permissions: approvedNewPermissions, ...requestData } =
3011+
const { permissions, ...rest } =
30123012
(await pendingApproval.promise) as PermissionsRequest;
30133013

3014+
approvedNewPermissions = permissions;
3015+
requestData = rest;
3016+
30143017
pendingApproval = this.#createApproval({
30153018
origin,
30163019
snapId,

0 commit comments

Comments
 (0)