From 32367b4339831937683c6cdd59c8569aa04ce9a7 Mon Sep 17 00:00:00 2001 From: Jackson Dean Date: Fri, 13 Oct 2023 11:30:04 -0700 Subject: [PATCH] add test for association limit permissions check --- src/identity/identity.spec.ts | 98 +++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/identity/identity.spec.ts b/src/identity/identity.spec.ts index 73414d4..6e5fd53 100644 --- a/src/identity/identity.spec.ts +++ b/src/identity/identity.spec.ts @@ -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', () => {