Skip to content

Commit

Permalink
Merge branch 'trunk' into apkam_onboarding_changes_with_enrollment_st…
Browse files Browse the repository at this point in the history
…atus
  • Loading branch information
gkc authored Apr 11, 2024
2 parents 8b727d9 + da80132 commit be3cd10
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/at_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ dependencies:
async: ^2.9.0
at_utf7: ^1.0.0
at_base2e15: ^1.0.0
at_commons: ^4.0.1
at_commons: ^4.0.6
at_utils: ^3.0.16
at_chops: ^2.0.0
at_lookup: ^3.0.46
at_auth: ^2.0.0
at_persistence_spec: ^2.0.14
at_persistence_secondary_server: ^3.0.61
at_persistence_secondary_server: ^3.0.62
meta: ^1.8.0
version: ^3.0.2

Expand Down
19 changes: 19 additions & 0 deletions packages/at_client/test/at_client_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:at_persistence_secondary_server/at_persistence_secondary_server.
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import 'test_utils/test_utils.dart';

class MockAtCompactionJob extends Mock implements AtCompactionJob {
bool isCronScheduled = false;

Expand Down Expand Up @@ -364,4 +366,21 @@ void main() {
AtClientImpl.atClientInstanceMap.remove(atSign);
});
});
group('A group of test to validate max length of a key', () {
MockRemoteSecondary mockRemoteSecondary = MockRemoteSecondary();
test('test max length for put method', () async {
AtClient? client = await AtClientImpl.create(
'@alice', 'buzz', AtClientPreference(),
remoteSecondary: mockRemoteSecondary);
var key = TestUtils.createRandomString(250);
var atKey = AtKey.fromString('$key@alice');

expect(
() async => await client.put(atKey, 'hello'),
throwsA(predicate((dynamic e) =>
e is AtClientException &&
e.message ==
'Key length exceeds maximum permissible length of 248 characters')));
});
});
}
53 changes: 53 additions & 0 deletions packages/at_client/test/local_secondary_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:crypton/crypton.dart';
import 'package:test/test.dart';
import 'package:mocktail/mocktail.dart';

import 'test_utils/test_utils.dart';

class MockSecondaryKeyStore extends Mock implements SecondaryKeyStore {
static const String hiddenKey1 = 'public:__location.wavi@alice';
static const String hiddenKey2 = '_profilePic.wavi@alice';
Expand Down Expand Up @@ -163,6 +165,57 @@ void main() {
expect(executeResult!.startsWith('data:'), true);
});

test('test update verb builder max key length check', () async {
final atClientManager = AtClientManager(atSign);
final preference = AtClientPreference()
..syncRegex = '.wavi'
..hiveStoragePath = 'test/hive';
AtClient atClient = await AtClientImpl.create(atSign, 'wavi', preference,
atClientManager: atClientManager);
final localSecondary = LocalSecondary(atClient);
var key = TestUtils.createRandomString(250);
final verbBuilder = UpdateVerbBuilder()
..atKey = (AtKey()
..key = key
..sharedBy = atSign
..metadata = (Metadata()..isPublic = true))
..value = '[email protected]';
expect(
() async =>
await localSecondary.executeVerb(verbBuilder, sync: false),
throwsA(predicate((dynamic e) =>
e is DataStoreException &&
e.message ==
'key length ${'public:'.length + key.length + atSign.length} is greater than max allowed 248 chars')));
});

test('test update verb builder max key length check for cached key',
() async {
final atClientManager = AtClientManager(atSign);
final preference = AtClientPreference()
..syncRegex = '.wavi'
..hiveStoragePath = 'test/hive';
AtClient atClient = await AtClientImpl.create(atSign, 'wavi', preference,
atClientManager: atClientManager);
final localSecondary = LocalSecondary(atClient);
var key = TestUtils.createRandomString(250);
final verbBuilder = UpdateVerbBuilder()
..atKey = (AtKey()
..key = key
..sharedBy = atSign
..metadata = (Metadata()
..isCached = true
..isPublic = true))
..value = '[email protected]';
expect(
() async =>
await localSecondary.executeVerb(verbBuilder, sync: false),
throwsA(predicate((dynamic e) =>
e is DataStoreException &&
e.message ==
'key length ${'cached:'.length + 'public:'.length + key.length + atSign.length} is greater than max allowed 255 chars')));
});

test('test llookup verb builder', () async {
final atClientManager = AtClientManager(atSign);
final preference = AtClientPreference()
Expand Down
10 changes: 10 additions & 0 deletions packages/at_client/test/test_utils/test_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'dart:math';

class TestUtils {
static String createRandomString(int length) {
final String characters =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
return String.fromCharCodes(Iterable.generate(length,
(index) => characters.codeUnitAt(Random().nextInt(characters.length))));
}
}

0 comments on commit be3cd10

Please sign in to comment.