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

Test unicode symbols #1186

Merged
merged 31 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
175084a
Upgrade core 13.5.0 and fix error messages
desistefanova Feb 24, 2023
62f5d3d
ChangeLog update
desistefanova Feb 24, 2023
fda1a86
Fix text message
desistefanova Feb 24, 2023
7dfaacb
SyncErrorCategory.webSocket
desistefanova Feb 24, 2023
e83fc09
Fix Changelog
desistefanova Feb 24, 2023
af389b6
websocket unknown code 9999
desistefanova Feb 24, 2023
b1a5eda
Test error messages - issue #1181
desistefanova Feb 25, 2023
010d40d
Fix SyncWebSocketErrorCode mapping
desistefanova Feb 28, 2023
8d7deb6
Update changelog
desistefanova Feb 28, 2023
8b1f1d8
Test unicode symbols
desistefanova Feb 28, 2023
70a0d83
Fix query strings
desistefanova Feb 28, 2023
c063e5e
Fixig emails allowed symbols
desistefanova Feb 28, 2023
e00735e
Fix query by unicodes
desistefanova Feb 28, 2023
250d622
Add specific test with unicode symbols
desistefanova Feb 28, 2023
ccf1e3d
Fix test name
desistefanova Feb 28, 2023
070935f
Reuse random generator funciton
desistefanova Feb 28, 2023
c703c77
Test local realm with unicode symbols
desistefanova Mar 1, 2023
c9b24bc
Upgrade core to 13.6.0
desistefanova Mar 6, 2023
b436410
Update Changelog
desistefanova Mar 6, 2023
f8061e6
Merge from main
desistefanova Mar 6, 2023
8630fa4
Added case-insensitive tests
desistefanova Mar 6, 2023
6b4cd1d
Merge branch 'ds/upgrade_core_13.6.0' into ds/unicode_file_path
desistefanova Mar 6, 2023
161d8ee
Force CI
desistefanova Mar 6, 2023
cef2d3f
Remove redundant test and changelog
desistefanova Mar 13, 2023
381a624
Merge branch 'main' into ds/unicode_file_path
desistefanova Mar 13, 2023
3886603
Revert "Merge branch 'main' into ds/unicode_file_path"
desistefanova Mar 22, 2023
0dd7de7
Code review changes
desistefanova Mar 22, 2023
72ce82f
Remove the usage of an old method
desistefanova Mar 22, 2023
2704713
Code review changes
desistefanova Mar 22, 2023
fbb156c
Code review changes
desistefanova Mar 23, 2023
de45cff
Code review changes
desistefanova Mar 23, 2023
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
2 changes: 1 addition & 1 deletion lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ enum SyncResolveErrorCode {
///
/// These errors will be reported via the error handlers of the affected sessions.
enum SyncWebSocketErrorCode {

/// Web socket resolution failed
websocketResolveFailed(4400),

Expand Down
2 changes: 1 addition & 1 deletion test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Future<void> main([List<String>? args]) async {
baasTest('App delete user', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "realm_tests_do_autoverify${generateRandomString(5)}@realm.io";
String username = "realm_tests_do_autoverify${generateRandomEmail()}";
const String strongPassword = "SWV23R#@T#VFQDV";
await authProvider.registerUser(username, strongPassword);
final user = await loginWithRetry(app, Credentials.emailPassword(username, strongPassword));
Expand Down
28 changes: 14 additions & 14 deletions test/credentials_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - register user confirmation throws', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
await expectLater(() {
// For confirmationType = 'runConfirmationFunction' as it is by default
// only usernames that contain 'realm_tests_do_autoverify' are confirmed.
Expand All @@ -61,7 +61,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - register user', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "realm_tests_do_autoverify${generateRandomString(5)}@realm.io";
String username = "realm_tests_do_autoverify${generateRandomEmail()}";
await authProvider.registerUser(username, strongPassword);
final user = await loginWithRetry(app, Credentials.emailPassword(username, strongPassword));
expect(user, isNotNull);
Expand All @@ -70,7 +70,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - register user auto confirm', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
// For application with name 'autoConfirm' and with confirmationType = 'auto'
// all the usernames are automatically confirmed.

Expand All @@ -82,15 +82,15 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - register user twice throws', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
await authProvider.registerUser(username, strongPassword);
await expectLater(() => authProvider.registerUser(username, strongPassword), throws<AppException>("name already in use"));
}, appName: AppNames.autoConfirm);

baasTest('Email/Password - register user with weak/empty password throws', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
await expectLater(() => authProvider.registerUser(username, "pwd"), throws<AppException>("password must be between 6 and 128 characters"));
await expectLater(() => authProvider.registerUser(username, ""), throws<AppException>("password must be between 6 and 128 characters"));
}, appName: AppNames.autoConfirm);
Expand All @@ -104,7 +104,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - confirm user token expired', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@hotmail.com";
String username = generateRandomEmail();
await authProvider.registerUser(username, strongPassword);
await expectLater(
() => authProvider.confirmUser(
Expand All @@ -116,7 +116,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - confirm user token invalid', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@hotmail.com";
String username = generateRandomEmail();
await authProvider.registerUser(username, strongPassword);
await expectLater(() => authProvider.confirmUser("abc", "123"), throws<AppException>("invalid token data"));
}, appName: AppNames.emailConfirm);
Expand Down Expand Up @@ -153,7 +153,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - retry custom confirmation function', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "realm_tests_pending_confirm_${generateRandomString(5)}@realm.io";
String username = "realm_tests_pending_confirm_${generateRandomEmail()}";
await authProvider.registerUser(username, strongPassword);

await authProvider.retryCustomConfirmationFunction(username);
Expand All @@ -165,7 +165,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - retry custom confirmation after user is confirmed', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "realm_tests_do_autoverify_${generateRandomString(5)}@realm.io";
String username = "realm_tests_do_autoverify_${generateRandomEmail()}";
// Custom confirmation function confirms automatically username with 'realm_tests_do_autoverify'.
await authProvider.registerUser(username, strongPassword);

Expand All @@ -175,7 +175,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - retry custom confirmation for not registered user', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
await expectLater(() => authProvider.retryCustomConfirmationFunction(username), throws<AppException>("user not found"));
});

Expand Down Expand Up @@ -213,7 +213,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Email/Password - reset password of non-existent user throws', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
await expectLater(() => authProvider.resetPassword(username), throws<AppException>("user not found"));
}, appName: AppNames.emailConfirm);

Expand Down Expand Up @@ -271,7 +271,7 @@ Future<void> main([List<String>? args]) async {

baasTest('Email/Password - call reset password function and login with the new password', (configuration) async {
final app = App(configuration);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
const String newPassword = "!@#!DQXQWD!223eda";
final authProvider = EmailPasswordAuthProvider(app);
await authProvider.registerUser(username, strongPassword);
Expand All @@ -282,7 +282,7 @@ Future<void> main([List<String>? args]) async {

baasTest('Email/Password - call reset password function with no additional arguments', (configuration) async {
final app = App(configuration);
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
const String newPassword = "!@#!DQXQWD!223eda";
final authProvider = EmailPasswordAuthProvider(app);
await authProvider.registerUser(username, strongPassword);
Expand Down Expand Up @@ -458,7 +458,7 @@ Future<void> main([List<String>? args]) async {
baasTest('Function credentials - login with new user', (configuration) async {
final app = App(configuration);
var userId = ObjectId().toString();
String username = "${generateRandomString(5)}@realm.io";
String username = generateRandomEmail();
final payload = '{"username":"$username","userId":"$userId"}';
final credentials = Credentials.function(payload);
final user = await app.logIn(credentials);
Expand Down
39 changes: 39 additions & 0 deletions test/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,45 @@ Future<void> main([List<String>? args]) async {
expect(realmCore.getDeviceName(), matcher);
expect(realmCore.getDeviceVersion(), matcher);
});

test('Realm path with unicode symbols', () {
var config = Configuration.local([Car.schema], path: "${generateRandomUnicodeString()}.realm");
var realm = getRealm(config);
expect(realm.isClosed, false);
});

test('Realm local add/query data with unicode symbols', () {
final productName = generateRandomUnicodeString();
final config = Configuration.local([Product.schema]);
final realm = getRealm(config);
realm.write(() => realm.add(Product(ObjectId(), productName)));
final query = realm.query<Product>(r'name == $0', [productName]);
expect(query.length, 1);
expect(query[0].name, productName);
});

baasTest('Realm synced add/query/sync data with unicode symbols', (appConfiguration) async {
final app = App(appConfiguration);
final productName = generateRandomUnicodeString();
final user = await app.logIn(Credentials.anonymous(reuseCredentials: false));
final config = Configuration.flexibleSync(user, [Product.schema]);
final realm = getRealm(config);
await _addSubscriptions(realm, productName);
realm.write(() => realm.add(Product(ObjectId(), productName)));
final query = realm.query<Product>(r'name == $0', [productName]);
expect(query.length, 1);
expect(query[0].name, productName);
});

test('Realm case-insensitive query', () {
final productName = generateRandomString(10).toUpperCase();
final config = Configuration.local([Product.schema]);
final realm = getRealm(config);
realm.write(() => realm.add(Product(ObjectId(), productName)));
final query = realm.query<Product>(r'name LIKE[c] $0', [productName.toLowerCase()]);
expect(query.length, 1);
expect(query[0].name, productName);
});
}

List<int> generateEncryptionKey() {
Expand Down
18 changes: 13 additions & 5 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,17 @@ String generateRandomRealmPath() {
}

final random = Random();
String generateRandomString(int len) {
const chars = 'abcdefghjklmnopqrstuvwxuz';
return List.generate(len, (index) => chars[random.nextInt(chars.length)]).join();
String generateRandomString(int length, {String characterSet = 'abcdefghjklmnopqrstuvwxuz'}) {
return List.generate(length, (index) => characterSet[random.nextInt(characterSet.length)]).join();
}

String generateRandomUnicodeString({int length = 10}) {
return generateRandomString(length, characterSet: r"uvwxuzфоо-барΛορεμლორემ植物החללجمعتsøren");
}

String generateRandomEmail({int length = 5}) {
String randomString = generateRandomString(length, characterSet: r"abcdefghjklmnopqrstuvwxuz!#$%&*+-'/=?^_`{|}~0123456789");
return "[email protected]";
}

Realm getRealm(Configuration config) {
Expand Down Expand Up @@ -585,7 +593,7 @@ Future<AppConfiguration> getAppConfig({AppNames appName = AppNames.flexible}) as
}

Future<User> getIntegrationUser(App app) async {
final email = 'realm_tests_do_autoverify_${generateRandomString(10)}@realm.io';
final email = 'realm_tests_do_autoverify_${generateRandomEmail()}';
final password = 'password';
await app.emailPasswordAuthProvider.registerUser(email, password);

Expand All @@ -610,7 +618,7 @@ Future<Realm> getIntegrationRealm({App? app, ObjectId? differentiator}) async {
final realm = getRealm(config);
if (differentiator != null) {
realm.subscriptions.update((mutableSubscriptions) {
mutableSubscriptions.add(realm.query<NullableTypes>('differentiator = \$0', [differentiator]));
mutableSubscriptions.add(realm.query<NullableTypes>(r'differentiator = $0', [differentiator]));
});

await realm.subscriptions.waitForSynchronization();
Expand Down
2 changes: 1 addition & 1 deletion test/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Future<void> main([List<String>? args]) async {
expect(user1.identities.singleWhere((identity) => identity.provider == AuthProviderType.anonymous), isA<UserIdentity>());

final authProvider = EmailPasswordAuthProvider(app);
final username = "${generateRandomString(20)}@realm.io";
final username = generateRandomEmail();
final password = generateRandomString(8);
await authProvider.registerUser(username, password);

Expand Down