|
|
@ -66,13 +66,13 @@ describe('permissions middleware', function () { |
|
|
|
const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin) |
|
|
|
const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin) |
|
|
|
|
|
|
|
|
|
|
|
const req = RPC_REQUESTS.requestPermission( |
|
|
|
const req = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts, |
|
|
|
) |
|
|
|
) |
|
|
|
const res = {} |
|
|
|
const res = {} |
|
|
|
|
|
|
|
|
|
|
|
const pendingApproval = assert.doesNotReject( |
|
|
|
const pendingApproval = assert.doesNotReject( |
|
|
|
aMiddleware(req, res), |
|
|
|
aMiddleware(req, res), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
@ -88,32 +88,32 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
res.result.length, 1, |
|
|
|
res.result.length, 1, |
|
|
|
'origin should have single approved permission' |
|
|
|
'origin should have single approved permission', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
validatePermission( |
|
|
|
validatePermission( |
|
|
|
res.result[0], |
|
|
|
res.result[0], |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
DOMAINS.a.origin, |
|
|
|
DOMAINS.a.origin, |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
aAccounts, [ACCOUNTS.a.primary], |
|
|
|
aAccounts, [ACCOUNTS.a.primary], |
|
|
|
'origin should have correct accounts' |
|
|
|
'origin should have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
permController.notifyAccountsChanged.calledOnceWith( |
|
|
|
permController.notifyAccountsChanged.calledOnceWith( |
|
|
|
DOMAINS.a.origin, aAccounts, |
|
|
|
DOMAINS.a.origin, aAccounts, |
|
|
|
), |
|
|
|
), |
|
|
|
'expected notification call should have been made' |
|
|
|
'expected notification call should have been made', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -124,7 +124,7 @@ describe('permissions middleware', function () { |
|
|
|
// create first request
|
|
|
|
// create first request
|
|
|
|
|
|
|
|
|
|
|
|
const req1 = RPC_REQUESTS.requestPermission( |
|
|
|
const req1 = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts, |
|
|
|
) |
|
|
|
) |
|
|
|
const res1 = {} |
|
|
|
const res1 = {} |
|
|
|
|
|
|
|
|
|
|
@ -133,7 +133,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
const pendingApproval1 = assert.doesNotReject( |
|
|
|
const pendingApproval1 = assert.doesNotReject( |
|
|
|
aMiddleware(req1, res1), |
|
|
|
aMiddleware(req1, res1), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const id1 = permController.pendingApprovals.keys().next().value |
|
|
|
const id1 = permController.pendingApprovals.keys().next().value |
|
|
@ -144,32 +144,32 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res1.result && !res1.error, |
|
|
|
res1.result && !res1.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
res1.result.length, 1, |
|
|
|
res1.result.length, 1, |
|
|
|
'origin should have single approved permission' |
|
|
|
'origin should have single approved permission', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
validatePermission( |
|
|
|
validatePermission( |
|
|
|
res1.result[0], |
|
|
|
res1.result[0], |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
DOMAINS.a.origin, |
|
|
|
DOMAINS.a.origin, |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const accounts1 = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const accounts1 = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
accounts1, [ACCOUNTS.a.primary], |
|
|
|
accounts1, [ACCOUNTS.a.primary], |
|
|
|
'origin should have correct accounts' |
|
|
|
'origin should have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
permController.notifyAccountsChanged.calledOnceWith( |
|
|
|
permController.notifyAccountsChanged.calledOnceWith( |
|
|
|
DOMAINS.a.origin, accounts1, |
|
|
|
DOMAINS.a.origin, accounts1, |
|
|
|
), |
|
|
|
), |
|
|
|
'expected notification call should have been made' |
|
|
|
'expected notification call should have been made', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// create second request
|
|
|
|
// create second request
|
|
|
@ -180,7 +180,7 @@ describe('permissions middleware', function () { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const req2 = RPC_REQUESTS.requestPermissions( |
|
|
|
const req2 = RPC_REQUESTS.requestPermissions( |
|
|
|
DOMAINS.a.origin, { ...requestedPerms2 } |
|
|
|
DOMAINS.a.origin, { ...requestedPerms2 }, |
|
|
|
) |
|
|
|
) |
|
|
|
const res2 = {} |
|
|
|
const res2 = {} |
|
|
|
|
|
|
|
|
|
|
@ -189,7 +189,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
const pendingApproval2 = assert.doesNotReject( |
|
|
|
const pendingApproval2 = assert.doesNotReject( |
|
|
|
aMiddleware(req2, res2), |
|
|
|
aMiddleware(req2, res2), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const id2 = permController.pendingApprovals.keys().next().value |
|
|
|
const id2 = permController.pendingApprovals.keys().next().value |
|
|
@ -200,19 +200,19 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res2.result && !res2.error, |
|
|
|
res2.result && !res2.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
res2.result.length, 2, |
|
|
|
res2.result.length, 2, |
|
|
|
'origin should have single approved permission' |
|
|
|
'origin should have single approved permission', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
validatePermission( |
|
|
|
validatePermission( |
|
|
|
res2.result[0], |
|
|
|
res2.result[0], |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
DOMAINS.a.origin, |
|
|
|
DOMAINS.a.origin, |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.b.permitted) |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.b.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
validatePermission( |
|
|
|
validatePermission( |
|
|
@ -224,19 +224,19 @@ describe('permissions middleware', function () { |
|
|
|
const accounts2 = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const accounts2 = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
accounts2, [ACCOUNTS.b.primary], |
|
|
|
accounts2, [ACCOUNTS.b.primary], |
|
|
|
'origin should have correct accounts' |
|
|
|
'origin should have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
permController.notifyAccountsChanged.callCount, 2, |
|
|
|
permController.notifyAccountsChanged.callCount, 2, |
|
|
|
'should have called notification method 2 times in total' |
|
|
|
'should have called notification method 2 times in total', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
permController.notifyAccountsChanged.lastCall.calledWith( |
|
|
|
permController.notifyAccountsChanged.lastCall.calledWith( |
|
|
|
DOMAINS.a.origin, accounts2, |
|
|
|
DOMAINS.a.origin, accounts2, |
|
|
|
), |
|
|
|
), |
|
|
|
'expected notification call should have been made' |
|
|
|
'expected notification call should have been made', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -245,7 +245,7 @@ describe('permissions middleware', function () { |
|
|
|
const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin) |
|
|
|
const aMiddleware = getPermissionsMiddleware(permController, DOMAINS.a.origin) |
|
|
|
|
|
|
|
|
|
|
|
const req = RPC_REQUESTS.requestPermission( |
|
|
|
const req = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts |
|
|
|
DOMAINS.a.origin, PERM_NAMES.eth_accounts, |
|
|
|
) |
|
|
|
) |
|
|
|
const res = {} |
|
|
|
const res = {} |
|
|
|
|
|
|
|
|
|
|
@ -272,17 +272,17 @@ describe('permissions middleware', function () { |
|
|
|
!res.result && res.error && |
|
|
|
!res.result && res.error && |
|
|
|
res.error.message === expectedError.message |
|
|
|
res.error.message === expectedError.message |
|
|
|
), |
|
|
|
), |
|
|
|
'response should have expected error and no result' |
|
|
|
'response should have expected error and no result', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
aAccounts, [], 'origin should have have correct accounts' |
|
|
|
aAccounts, [], 'origin should have have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
permController.notifyAccountsChanged.notCalled, |
|
|
|
permController.notifyAccountsChanged.notCalled, |
|
|
|
'should not have called notification method' |
|
|
|
'should not have called notification method', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -294,12 +294,12 @@ describe('permissions middleware', function () { |
|
|
|
DOMAINS.a.origin, { |
|
|
|
DOMAINS.a.origin, { |
|
|
|
...PERMS.requests.does_not_exist(), |
|
|
|
...PERMS.requests.does_not_exist(), |
|
|
|
...PERMS.requests.test_method(), |
|
|
|
...PERMS.requests.test_method(), |
|
|
|
} |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
const res = {} |
|
|
|
const res = {} |
|
|
|
|
|
|
|
|
|
|
|
const expectedError = ERRORS.rejectPermissionsRequest.methodNotFound( |
|
|
|
const expectedError = ERRORS.rejectPermissionsRequest.methodNotFound( |
|
|
|
PERM_NAMES.does_not_exist |
|
|
|
PERM_NAMES.does_not_exist, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
await assert.rejects( |
|
|
|
await assert.rejects( |
|
|
@ -318,12 +318,12 @@ describe('permissions middleware', function () { |
|
|
|
!res.result && res.error && |
|
|
|
!res.result && res.error && |
|
|
|
res.error.message === expectedError.message |
|
|
|
res.error.message === expectedError.message |
|
|
|
), |
|
|
|
), |
|
|
|
'response should have expected error and no result' |
|
|
|
'response should have expected error and no result', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
permController.notifyAccountsChanged.notCalled, |
|
|
|
permController.notifyAccountsChanged.notCalled, |
|
|
|
'should not have called notification method' |
|
|
|
'should not have called notification method', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -339,25 +339,25 @@ describe('permissions middleware', function () { |
|
|
|
// create and start processing first request for first origin
|
|
|
|
// create and start processing first request for first origin
|
|
|
|
|
|
|
|
|
|
|
|
const reqA1 = RPC_REQUESTS.requestPermission( |
|
|
|
const reqA1 = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.a.origin, PERM_NAMES.test_method |
|
|
|
DOMAINS.a.origin, PERM_NAMES.test_method, |
|
|
|
) |
|
|
|
) |
|
|
|
const resA1 = {} |
|
|
|
const resA1 = {} |
|
|
|
|
|
|
|
|
|
|
|
const requestApproval1 = assert.doesNotReject( |
|
|
|
const requestApproval1 = assert.doesNotReject( |
|
|
|
aMiddleware(reqA1, resA1), |
|
|
|
aMiddleware(reqA1, resA1), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// create and start processing first request for second origin
|
|
|
|
// create and start processing first request for second origin
|
|
|
|
|
|
|
|
|
|
|
|
const reqB1 = RPC_REQUESTS.requestPermission( |
|
|
|
const reqB1 = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.b.origin, PERM_NAMES.test_method |
|
|
|
DOMAINS.b.origin, PERM_NAMES.test_method, |
|
|
|
) |
|
|
|
) |
|
|
|
const resB1 = {} |
|
|
|
const resB1 = {} |
|
|
|
|
|
|
|
|
|
|
|
const requestApproval2 = assert.doesNotReject( |
|
|
|
const requestApproval2 = assert.doesNotReject( |
|
|
|
bMiddleware(reqB1, resB1), |
|
|
|
bMiddleware(reqB1, resB1), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
@ -369,7 +369,7 @@ describe('permissions middleware', function () { |
|
|
|
// which should throw
|
|
|
|
// which should throw
|
|
|
|
|
|
|
|
|
|
|
|
const reqA2 = RPC_REQUESTS.requestPermission( |
|
|
|
const reqA2 = RPC_REQUESTS.requestPermission( |
|
|
|
DOMAINS.a.origin, PERM_NAMES.test_method |
|
|
|
DOMAINS.a.origin, PERM_NAMES.test_method, |
|
|
|
) |
|
|
|
) |
|
|
|
const resA2 = {} |
|
|
|
const resA2 = {} |
|
|
|
|
|
|
|
|
|
|
@ -384,7 +384,7 @@ describe('permissions middleware', function () { |
|
|
|
!resA2.result && resA2.error && |
|
|
|
!resA2.result && resA2.error && |
|
|
|
resA2.error.message === expectedError.message |
|
|
|
resA2.error.message === expectedError.message |
|
|
|
), |
|
|
|
), |
|
|
|
'response should have expected error and no result' |
|
|
|
'response should have expected error and no result', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// first requests for both origins should remain
|
|
|
|
// first requests for both origins should remain
|
|
|
@ -398,7 +398,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
for (const id of permController.pendingApprovals.keys()) { |
|
|
|
for (const id of permController.pendingApprovals.keys()) { |
|
|
|
await permController.approvePermissionsRequest( |
|
|
|
await permController.approvePermissionsRequest( |
|
|
|
PERMS.approvedRequest(id, PERMS.requests.test_method()) |
|
|
|
PERMS.approvedRequest(id, PERMS.requests.test_method()), |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
await requestApproval1 |
|
|
|
await requestApproval1 |
|
|
@ -406,20 +406,20 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
resA1.result && !resA1.error, |
|
|
|
resA1.result && !resA1.error, |
|
|
|
'first response should have result and no error' |
|
|
|
'first response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
resA1.result.length, 1, |
|
|
|
resA1.result.length, 1, |
|
|
|
'first origin should have single approved permission' |
|
|
|
'first origin should have single approved permission', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
resB1.result && !resB1.error, |
|
|
|
resB1.result && !resB1.error, |
|
|
|
'second response should have result and no error' |
|
|
|
'second response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
resB1.result.length, 1, |
|
|
|
resB1.result.length, 1, |
|
|
|
'second origin should have single approved permission' |
|
|
|
'second origin should have single approved permission', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
@ -457,7 +457,7 @@ describe('permissions middleware', function () { |
|
|
|
!res.result && res.error && |
|
|
|
!res.result && res.error && |
|
|
|
res.error.code === expectedError.code |
|
|
|
res.error.code === expectedError.code |
|
|
|
), |
|
|
|
), |
|
|
|
'response should have expected error and no result' |
|
|
|
'response should have expected error and no result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -472,12 +472,12 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
bMiddleware(req, res), |
|
|
|
bMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && res.result === 1, |
|
|
|
res.result && res.result === 1, |
|
|
|
'response should have correct result' |
|
|
|
'response should have correct result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -499,16 +499,16 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
aMiddleware(req, res), |
|
|
|
aMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
res.result, [], |
|
|
|
res.result, [], |
|
|
|
'response should have correct result' |
|
|
|
'response should have correct result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -518,7 +518,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
grantPermissions( |
|
|
|
grantPermissions( |
|
|
|
permController, DOMAINS.a.origin, |
|
|
|
permController, DOMAINS.a.origin, |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted) |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.a.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const req = RPC_REQUESTS.eth_accounts(DOMAINS.a.origin) |
|
|
|
const req = RPC_REQUESTS.eth_accounts(DOMAINS.a.origin) |
|
|
@ -526,16 +526,16 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
aMiddleware(req, res), |
|
|
|
aMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
res.result, [ACCOUNTS.a.primary], |
|
|
|
res.result, [ACCOUNTS.a.primary], |
|
|
|
'response should have correct result' |
|
|
|
'response should have correct result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -559,7 +559,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
const pendingApproval = assert.doesNotReject( |
|
|
|
const pendingApproval = assert.doesNotReject( |
|
|
|
aMiddleware(req, res), |
|
|
|
aMiddleware(req, res), |
|
|
|
'should not reject permissions request' |
|
|
|
'should not reject permissions request', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
await userApprovalPromise |
|
|
|
await userApprovalPromise |
|
|
@ -581,31 +581,31 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.equal( |
|
|
|
assert.equal( |
|
|
|
perms.length, 1, |
|
|
|
perms.length, 1, |
|
|
|
'domain should have correct number of permissions' |
|
|
|
'domain should have correct number of permissions', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
validatePermission( |
|
|
|
validatePermission( |
|
|
|
perms[0], |
|
|
|
perms[0], |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
PERM_NAMES.eth_accounts, |
|
|
|
DOMAINS.a.origin, |
|
|
|
DOMAINS.a.origin, |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted) |
|
|
|
CAVEATS.eth_accounts(ACCOUNTS.a.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// we should also see the accounts on the response
|
|
|
|
// we should also see the accounts on the response
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
res.result, [ACCOUNTS.a.primary], |
|
|
|
res.result, [ACCOUNTS.a.primary], |
|
|
|
'result should have correct accounts' |
|
|
|
'result should have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// we should also be able to get the accounts independently
|
|
|
|
// we should also be able to get the accounts independently
|
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
aAccounts, [ACCOUNTS.a.primary], 'origin should have have correct accounts' |
|
|
|
aAccounts, [ACCOUNTS.a.primary], 'origin should have have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -643,12 +643,12 @@ describe('permissions middleware', function () { |
|
|
|
!res.result && res.error && |
|
|
|
!res.result && res.error && |
|
|
|
res.error.message === expectedError.message |
|
|
|
res.error.message === expectedError.message |
|
|
|
), |
|
|
|
), |
|
|
|
'response should have expected error and no result' |
|
|
|
'response should have expected error and no result', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
const aAccounts = await permController.getAccounts(DOMAINS.a.origin) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
aAccounts, [], 'origin should have have correct accounts' |
|
|
|
aAccounts, [], 'origin should have have correct accounts', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -658,7 +658,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
grantPermissions( |
|
|
|
grantPermissions( |
|
|
|
permController, DOMAINS.c.origin, |
|
|
|
permController, DOMAINS.c.origin, |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted) |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin) |
|
|
|
const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin) |
|
|
@ -666,16 +666,16 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
res.result, [ACCOUNTS.c.primary], |
|
|
|
res.result, [ACCOUNTS.c.primary], |
|
|
|
'response should have correct result' |
|
|
|
'response should have correct result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -692,7 +692,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
grantPermissions( |
|
|
|
grantPermissions( |
|
|
|
permController, DOMAINS.c.origin, |
|
|
|
permController, DOMAINS.c.origin, |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted) |
|
|
|
PERMS.finalizedRequests.eth_accounts(ACCOUNTS.c.permitted), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin) |
|
|
|
const req = RPC_REQUESTS.eth_requestAccounts(DOMAINS.c.origin) |
|
|
@ -701,13 +701,13 @@ describe('permissions middleware', function () { |
|
|
|
// this will block until we resolve the unlock Promise
|
|
|
|
// this will block until we resolve the unlock Promise
|
|
|
|
const requestApproval = assert.doesNotReject( |
|
|
|
const requestApproval = assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// this will reject because of the already pending request
|
|
|
|
// this will reject because of the already pending request
|
|
|
|
await assert.rejects( |
|
|
|
await assert.rejects( |
|
|
|
cMiddleware({ ...req }, {}), |
|
|
|
cMiddleware({ ...req }, {}), |
|
|
|
ERRORS.eth_requestAccounts.requestAlreadyPending() |
|
|
|
ERRORS.eth_requestAccounts.requestAlreadyPending(), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// now unlock and let through the first request
|
|
|
|
// now unlock and let through the first request
|
|
|
@ -717,11 +717,11 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.ok( |
|
|
|
assert.ok( |
|
|
|
res.result && !res.error, |
|
|
|
res.result && !res.error, |
|
|
|
'response should have result and no error' |
|
|
|
'response should have result and no error', |
|
|
|
) |
|
|
|
) |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
res.result, [ACCOUNTS.c.primary], |
|
|
|
res.result, [ACCOUNTS.c.primary], |
|
|
|
'response should have correct result' |
|
|
|
'response should have correct result', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -750,7 +750,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
@ -766,7 +766,7 @@ describe('permissions middleware', function () { |
|
|
|
lastUpdated: 1, |
|
|
|
lastUpdated: 1, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
'metadata should have been added to store' |
|
|
|
'metadata should have been added to store', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -783,7 +783,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
@ -793,7 +793,7 @@ describe('permissions middleware', function () { |
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
metadataStore, |
|
|
|
metadataStore, |
|
|
|
{ [DOMAINS.c.origin]: { name, extensionId, lastUpdated: 1 } }, |
|
|
|
{ [DOMAINS.c.origin]: { name, extensionId, lastUpdated: 1 } }, |
|
|
|
'metadata should have been added to store' |
|
|
|
'metadata should have been added to store', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -808,7 +808,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
@ -817,7 +817,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
metadataStore, {}, |
|
|
|
metadataStore, {}, |
|
|
|
'metadata should not have been added to store' |
|
|
|
'metadata should not have been added to store', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -831,7 +831,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
await assert.doesNotReject( |
|
|
|
await assert.doesNotReject( |
|
|
|
cMiddleware(req, res), |
|
|
|
cMiddleware(req, res), |
|
|
|
'should not reject' |
|
|
|
'should not reject', |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
|
assert.ok(res.result, 'result should be true') |
|
|
@ -840,7 +840,7 @@ describe('permissions middleware', function () { |
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual( |
|
|
|
assert.deepEqual( |
|
|
|
metadataStore, {}, |
|
|
|
metadataStore, {}, |
|
|
|
'metadata should not have been added to store' |
|
|
|
'metadata should not have been added to store', |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|