Skip to content

Commit 344d7ad

Browse files
Fix permissions
1 parent d2161d8 commit 344d7ad

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
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,
@@ -10156,32 +10156,34 @@ describe('SnapController', () => {
1015610156
snapController.destroy();
1015710157
});
1015810158

10159-
it.only('updates preinstalled Snaps', async () => {
10159+
it('updates preinstalled Snaps', async () => {
1016010160
const registry = new MockSnapsRegistry();
1016110161
const rootMessenger = getControllerMessenger(registry);
1016210162
const messenger = getSnapControllerMessenger(rootMessenger);
1016310163

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

10166-
const mockSnap = getPersistedSnapObject({ id: snapId, preinstalled: true });
10166+
const mockSnap = getPersistedSnapObject({
10167+
id: snapId,
10168+
preinstalled: true,
10169+
});
1016710170

1016810171
const updateVersion = '1.2.1';
10169-
10172+
1017010173
registry.resolveVersion.mockResolvedValue(updateVersion);
10171-
const fetchFunction = jest.fn()
10172-
.mockResolvedValueOnce({
10173-
// eslint-disable-next-line no-restricted-globals
10174-
headers: new Headers({ 'content-length': '5477' }),
10175-
ok: true,
10176-
body: Readable.toWeb(
10177-
createReadStream(
10178-
path.resolve(
10179-
__dirname,
10180-
`../../test/fixtures/metamask-jsx-example-snap-${updateVersion}.tgz`,
10181-
),
10182-
),
10183-
),
10184-
} as any);
10174+
const fetchFunction = jest.fn().mockResolvedValueOnce({
10175+
// eslint-disable-next-line no-restricted-globals
10176+
headers: new Headers({ 'content-length': '5477' }),
10177+
ok: true,
10178+
body: Readable.toWeb(
10179+
createReadStream(
10180+
path.resolve(
10181+
__dirname,
10182+
`../../test/fixtures/metamask-jsx-example-snap-${updateVersion}.tgz`,
10183+
),
10184+
),
10185+
),
10186+
} as any);
1018510187

1018610188
const snapController = getSnapController(
1018710189
getSnapControllerOptions({

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,8 @@ export class SnapController extends BaseController<
28922892
* @param options.snapId - The id of the Snap to be updated.
28932893
* @param options.location - The location implementation of the snap.
28942894
* @param options.versionRange - A semver version range in which the maximum version will be chosen.
2895+
* @param options.automaticUpdate - An optional boolean flag to indicate whether this update should be done
2896+
* automatically.
28952897
* @returns The snap metadata if updated, `null` otherwise.
28962898
*/
28972899
async #updateSnap({
@@ -2981,7 +2983,6 @@ export class SnapController extends BaseController<
29812983
let requestData;
29822984

29832985
if (automaticUpdate) {
2984-
// TODO: This probably doesn't work as it doesn't account for initialConnections.
29852986
approvedNewPermissions = newPermissions;
29862987
} else {
29872988
assert(pendingApproval);
@@ -2997,9 +2998,12 @@ export class SnapController extends BaseController<
29972998
loading: false,
29982999
});
29993000

3000-
const { permissions: approvedNewPermissions, ...requestData } =
3001+
const { permissions, ...rest } =
30013002
(await pendingApproval.promise) as PermissionsRequest;
30023003

3004+
approvedNewPermissions = permissions;
3005+
requestData = rest;
3006+
30033007
pendingApproval = this.#createApproval({
30043008
origin,
30053009
snapId,

0 commit comments

Comments
 (0)