Skip to content

Commit

Permalink
Throw an exception for empty app ids (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Feb 1, 2024
1 parent 019413a commit 7397eb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None

### Fixed
* None
* Creating an `AppConfiguration` with an empty appId will now throw an exception rather than crashing the app. (Issue [#1487](https://github.com/realm/realm-dart/issues/1487))

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
6 changes: 5 additions & 1 deletion lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ class AppConfiguration {
HttpClient? httpClient,
}) : baseUrl = baseUrl ?? Uri.parse('https://realm.mongodb.com'),
baseFilePath = baseFilePath ?? Directory(_path.dirname(Configuration.defaultRealmPath)),
httpClient = httpClient ?? _defaultClient;
httpClient = httpClient ?? _defaultClient {
if (appId == '') {
throw RealmException('Supplied appId must be a non-empty value');
}
}
}

/// An [App] is the main client-side entry point for interacting with an [Atlas App Services](https://www.mongodb.com/docs/atlas/app-services/) application.
Expand Down
4 changes: 4 additions & 0 deletions test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ void main() {

expect(log, contains('App constructor called on Isolate'));
});

test('AppConfiguration(empty-id) throws', () {
expect(() => AppConfiguration(''), throwsA(isA<RealmException>()));
});
}

extension PersonExt on Person {
Expand Down

0 comments on commit 7397eb5

Please sign in to comment.