@ -461,6 +461,93 @@ describe('permissions controller', function () {
} )
} )
} )
} )
describe ( 'addPermittedAccount' , function ( ) {
let permController , notifications
beforeEach ( function ( ) {
notifications = initNotifications ( )
permController = initPermController ( notifications )
grantPermissions (
permController , ORIGINS . a ,
PERMS . finalizedRequests . eth _accounts ( ACCOUNT _ARRAYS . a )
)
grantPermissions (
permController , ORIGINS . b ,
PERMS . finalizedRequests . eth _accounts ( ACCOUNT _ARRAYS . b )
)
} )
it ( 'should throw if account is not a string' , async function ( ) {
await assert . rejects (
( ) => permController . addPermittedAccount ( ORIGINS . a , { } ) ,
ERRORS . validatePermittedAccounts . nonKeyringAccount ( { } ) ,
'should throw on non-string account param'
)
} )
it ( 'should throw if given account is not in keyring' , async function ( ) {
await assert . rejects (
( ) => permController . addPermittedAccount ( ORIGINS . a , DUMMY _ACCOUNT ) ,
ERRORS . validatePermittedAccounts . nonKeyringAccount ( DUMMY _ACCOUNT ) ,
'should throw on non-keyring account'
)
} )
it ( 'should throw if origin is invalid' , async function ( ) {
await assert . rejects (
( ) => permController . addPermittedAccount ( false , EXTRA _ACCOUNT ) ,
ERRORS . addPermittedAccount . invalidOrigin ( ) ,
'should throw on invalid origin'
)
} )
it ( 'should throw if origin lacks any permissions' , async function ( ) {
await assert . rejects (
( ) => permController . addPermittedAccount ( ORIGINS . c , EXTRA _ACCOUNT ) ,
ERRORS . addPermittedAccount . invalidOrigin ( ) ,
'should throw on origin without permissions'
)
} )
it ( 'should throw if origin lacks eth_accounts permission' , async function ( ) {
grantPermissions (
permController , ORIGINS . c ,
PERMS . finalizedRequests . test _method ( )
)
await assert . rejects (
( ) => permController . addPermittedAccount ( ORIGINS . c , EXTRA _ACCOUNT ) ,
ERRORS . addPermittedAccount . noEthAccountsPermission ( ) ,
'should throw on origin without eth_accounts permission'
)
} )
it ( 'should throw if account is already permitted' , async function ( ) {
await assert . rejects (
( ) => permController . addPermittedAccount ( ORIGINS . a , ACCOUNT _ARRAYS . c [ 0 ] ) ,
ERRORS . addPermittedAccount . alreadyPermitted ( ) ,
'should throw if account is already permitted'
)
} )
it ( 'should successfully add permitted account' , async function ( ) {
await permController . addPermittedAccount ( ORIGINS . a , EXTRA _ACCOUNT )
const accounts = await permController . getAccounts ( ORIGINS . a )
assert . deepEqual (
accounts , [ ... ACCOUNT _ARRAYS . a , EXTRA _ACCOUNT ] ,
'origin should have correct accounts'
)
assert . deepEqual (
notifications [ ORIGINS . a ] [ 0 ] ,
NOTIFICATIONS . newAccounts ( [ ... ACCOUNT _ARRAYS . a , EXTRA _ACCOUNT ] ) ,
'origin should have correct notification'
)
} )
} )
describe ( 'finalizePermissionsRequest' , function ( ) {
describe ( 'finalizePermissionsRequest' , function ( ) {
let permController
let permController