@@ -14,9 +14,37 @@ import {
1414 assertIsValidSnapId ,
1515 verifyRequestedSnapPermissions ,
1616 stripSnapPrefix ,
17+ isSnapId ,
1718} from './snaps' ;
19+ import { MOCK_SNAP_ID } from './test-utils' ;
1820import { uri , WALLET_SNAP_PERMISSION_KEY } from './types' ;
1921
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+
2048describe ( 'assertIsValidSnapId' , ( ) => {
2149 it . each ( [ undefined , { } , null , true , 2 ] ) (
2250 'throws for non-strings (#%#)' ,
@@ -239,7 +267,7 @@ describe('isSnapPermitted', () => {
239267 {
240268 type : 'snapIds' ,
241269 value : {
242- foo : { } ,
270+ [ MOCK_SNAP_ID ] : { } ,
243271 } ,
244272 } ,
245273 ] ,
@@ -273,9 +301,9 @@ describe('isSnapPermitted', () => {
273301 } ,
274302 } ;
275303
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 ) ;
279307 } ) ;
280308
281309 describe ( 'verifyRequestedSnapPermissions' , ( ) => {
0 commit comments