@@ -14,9 +14,37 @@ import {
14
14
assertIsValidSnapId ,
15
15
verifyRequestedSnapPermissions ,
16
16
stripSnapPrefix ,
17
+ isSnapId ,
17
18
} from './snaps' ;
19
+ import { MOCK_SNAP_ID } from './test-utils' ;
18
20
import { uri , WALLET_SNAP_PERMISSION_KEY } from './types' ;
19
21
22
+ describe ( 'isSnapId' , ( ) => {
23
+ it . each ( [ 'npm:@metamask/test-snap-bip44' , 'local:http://localhost:8000' ] ) (
24
+ 'returns `true` for "%s"' ,
25
+ ( value ) => {
26
+ expect ( isSnapId ( value ) ) . toBe ( true ) ;
27
+ } ,
28
+ ) ;
29
+
30
+ it . each ( [
31
+ undefined ,
32
+ { } ,
33
+ null ,
34
+ true ,
35
+ 2 ,
36
+ 'foo:bar' ,
37
+ ' local:http://localhost:8000' ,
38
+ 'local:http://localhost:8000 ' ,
39
+ 'local:http://localhost:8000\n' ,
40
+ 'local:http://localhost:8000\r' ,
41
+ 'local:😎' ,
42
+ 'local:␡' ,
43
+ ] ) ( 'returns `false` for "%s"' , ( value ) => {
44
+ expect ( isSnapId ( value ) ) . toBe ( false ) ;
45
+ } ) ;
46
+ } ) ;
47
+
20
48
describe ( 'assertIsValidSnapId' , ( ) => {
21
49
it . each ( [ undefined , { } , null , true , 2 ] ) (
22
50
'throws for non-strings (#%#)' ,
@@ -239,7 +267,7 @@ describe('isSnapPermitted', () => {
239
267
{
240
268
type : 'snapIds' ,
241
269
value : {
242
- foo : { } ,
270
+ [ MOCK_SNAP_ID ] : { } ,
243
271
} ,
244
272
} ,
245
273
] ,
@@ -273,9 +301,9 @@ describe('isSnapPermitted', () => {
273
301
} ,
274
302
} ;
275
303
276
- expect ( isSnapPermitted ( validPermissions , 'foo' ) ) . toBe ( true ) ;
277
- expect ( isSnapPermitted ( invalidPermissions1 , 'foo' ) ) . toBe ( false ) ;
278
- expect ( isSnapPermitted ( invalidPermissions2 , 'foo' ) ) . toBe ( false ) ;
304
+ expect ( isSnapPermitted ( validPermissions , MOCK_SNAP_ID ) ) . toBe ( true ) ;
305
+ expect ( isSnapPermitted ( invalidPermissions1 , MOCK_SNAP_ID ) ) . toBe ( false ) ;
306
+ expect ( isSnapPermitted ( invalidPermissions2 , MOCK_SNAP_ID ) ) . toBe ( false ) ;
279
307
} ) ;
280
308
281
309
describe ( 'verifyRequestedSnapPermissions' , ( ) => {
0 commit comments