Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for association limit permissions check #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/identity/identity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,104 @@ describe('identity', () => {
});
expect(hasPermissions).toBe(false);
});
it('it works for scoped association limits', () => {
const activeUserKey =
'BC1YLhtBTFXAsKZgoaoYNW8mWAJWdfQjycheAeYjaX46azVrnZfJ94s';
windowFake.localStorage.setItem(
LOCAL_STORAGE_KEYS.activePublicKey,
activeUserKey
);
windowFake.localStorage.setItem(
LOCAL_STORAGE_KEYS.identityUsers,
JSON.stringify({
[activeUserKey]: {
primaryDerivedKey: {
IsValid: true,
transactionSpendingLimits: {
TransactionCountLimitMap: {
CREATE_USER_ASSOCIATION: 'UNLIMITED',
},
AssociationLimitMap: [
{
AssociationClass: 'User',
AssociationType: 'REACTION',
AppScopeType: 'Scoped',
AppPublicKeyBase58Check:
'BC1YLhtBTFXAsKZgoaoYNW8mWAJWdfQjycheAeYjaX46azVrnZfJ94s',
AssociationOperation: 'Create',
OpCount: 'UNLIMITED',
},
],
},
},
},
})
);
let hasPermissions = identity.hasPermissions({
TransactionCountLimitMap: {
CREATE_USER_ASSOCIATION: 'UNLIMITED',
},
AssociationLimitMap: [
{
AssociationClass: 'User',
AssociationType: 'REACTION',
AppScopeType: 'Scoped',
AppPublicKeyBase58Check:
'BC1YLhtBTFXAsKZgoaoYNW8mWAJWdfQjycheAeYjaX46azVrnZfJ94s',
AssociationOperation: 'Create',
OpCount: 'UNLIMITED',
},
],
});
expect(hasPermissions).toBe(true);

// Now try where it should fail
windowFake.localStorage.setItem(
LOCAL_STORAGE_KEYS.identityUsers,
JSON.stringify({
[activeUserKey]: {
primaryDerivedKey: {
IsValid: true,
transactionSpendingLimits: {
TransactionCountLimitMap: {
CREATE_USER_ASSOCIATION: 'UNLIMITED',
},
AssociationLimitMap: [
{
AssociationClass: 'User',
AssociationType: 'REACTION',
AppScopeType: 'Scoped',
AppPublicKeyBase58Check:
'BC1YLhtBTFXAsKZgoaoYNW8mWAJWdfQjycheAeYjaX46azVrnZfJ94s',
// NOTE: this is the only difference from the above
AssociationOperation: 'Delete',
OpCount: 'UNLIMITED',
},
],
},
},
},
})
);
hasPermissions = identity.hasPermissions({
TransactionCountLimitMap: {
CREATE_USER_ASSOCIATION: 'UNLIMITED',
},
AssociationLimitMap: [
{
AssociationClass: 'User',
AssociationType: 'REACTION',
AppScopeType: 'Scoped',
AppPublicKeyBase58Check:
'BC1YLhtBTFXAsKZgoaoYNW8mWAJWdfQjycheAeYjaX46azVrnZfJ94s',
// This should fail because the AssociationOperation is Delete
AssociationOperation: 'Create',
OpCount: 'UNLIMITED',
},
],
});
expect(hasPermissions).toBe(false);
});
});
describe('.desoAddressToEthereumAddress()', () => {
it('works', () => {
Expand Down