atsign-foundation / at_client_sdk

The Dart implementation of atSDK used for implementing Atsign's technology into other software
https://pub.dev/publishers/atsign.org/packages
BSD 3-Clause "New" or "Revised" License
1.47k stars 32 forks source link

fix: Skip cached public keys and cached shared keys from enrollment a… #1334

Closed sitaram-kalluri closed 3 weeks ago

sitaram-kalluri commented 3 weeks ago

…uthorization check

- What I did

- How I did it In local_secondary.dart, modify the existing method which excludes the local keys from enrollment authorization check to also exclude the cached sharedkey and encryption public key.

- How to verify it

Attaching the test logs srvd.log sshnp.log sshnpd.log

Pending work:

murali-shris commented 3 weeks ago

is there any test which covers these changes?

sitaram-kalluri commented 3 weeks ago

is there any test which covers these changes?

Created a git issue, working on the changes.

sitaram-kalluri commented 3 weeks ago

is there any test which covers these changes?

Created a git issue, working on the changes.

Completed adding of unit tests.

sitaram-kalluri commented 3 weeks ago

Please add tests which explicitly assert behaviour of LocalSecondary.isEnrollmentAuthorizedForOperation for a variety of verbs and keys

e.g. llookup for cached:@alice:shared_key@bob, cached:@alice:key.in.any.name.space@bob, cached:@alice:foo@bob as well as their non-cached equivalents; and also add tests for updates and deletes and notify

I suggest you modify LocalSecondary renaming _enrollment to enrollment and making it @visibleForTesting to make it possible to write many small test cases like this

    test('test llookup on cached:@alice:shared_key@bob', () async {
      final testEnrollmentId = 'aaa111';

      LocalSecondary ls = 
      <do setup of a LocalSecondary in a test setup function>

      ls.enrollment = Enrollment()
        ..enrollmentId = testEnrollmentId
        ..appName = 'testApkamAuthCachedLLookup'
        ..deviceName = 'testDevice'
        ..namespace = {"fubar": "rw"};

      final bool authorized = await ls.isEnrollmentAuthorizedForOperation(
          'cached:@alice:shared_key@bob', LLookupVerbBuilder());
      expect (authorized, true);
    });

Added unit tests to assert the "isEnrollmentAuthorizedForOperation" method.