Skip to content

Commit 44c7baf

Browse files
committed
Add basic test for encryption
1 parent 52ac4f7 commit 44c7baf

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ jobs:
187187

188188
- name: Web tests
189189
run: |
190-
curl https://storage.googleapis.com/simon-public-euw3/assets/sqlite3/wasm/2.4.6/sqlite3.wasm -o example/web/sqlite3.wasm
190+
curl https://simon-public.fsn1.your-objectstorage.com/assets/sqlite3/2.6.0/sqlite3.wasm -o example/web/sqlite3.wasm
191+
curl https://simon-public.fsn1.your-objectstorage.com/assets/sqlite3/2.6.0/sqlite3mc.wasm -o example/web/sqlite3.wasm
191192
dart test -P web -r expanded
192193
# If browsers behave differently on different platforms, surely that's not our fault...
193194
# So, only run browser tests on Linux to be faster.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@Tags(['wasm'])
2+
library;
3+
4+
import 'package:sqlite3/wasm.dart';
5+
import 'package:test/test.dart';
6+
7+
import 'utils.dart';
8+
9+
void main() {
10+
test('can open databases with sqlite3mc', () async {
11+
final sqlite3 = await loadSqlite3WithoutVfs(encryption: true);
12+
sqlite3.registerVirtualFileSystem(InMemoryFileSystem(), makeDefault: true);
13+
14+
sqlite3.open('/test')
15+
..execute('pragma key = "key"')
16+
..execute('CREATE TABLE foo (bar TEXT) STRICT;')
17+
..execute('INSERT INTO foo VALUES (?)', ['test'])
18+
..dispose();
19+
20+
final database = sqlite3.open('/test');
21+
expect(
22+
() => database.select('SELECT * FROM foo'),
23+
throwsA(isA<SqliteException>()
24+
.having((e) => e.message, 'message', contains('not a database'))),
25+
);
26+
27+
database.execute('pragma key = "key"');
28+
expect(database.select('SELECT * FROM foo'), isNotEmpty);
29+
});
30+
}

sqlite3/test/wasm/sqlite3_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ library;
33

44
import 'dart:js_interop';
55
import 'dart:js_interop_unsafe';
6-
import 'dart:math';
76

87
import 'package:http/http.dart' as http;
98
import 'package:sqlite3/wasm.dart';
@@ -35,9 +34,7 @@ void main() {
3534

3635
sqlite3 = await WasmSqlite3.load(response.bodyBytes);
3736
sqlite3.registerVirtualFileSystem(
38-
// Not using the default Random.secure() because it's not supported
39-
// by dart2wasm
40-
InMemoryFileSystem(random: Random()),
37+
InMemoryFileSystem(),
4138
makeDefault: true,
4239
);
4340
}

sqlite3/test/wasm/utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 'package:sqlite3/wasm.dart';
22
import 'package:test/scaffolding.dart';
33

4-
Future<WasmSqlite3> loadSqlite3WithoutVfs() async {
4+
Future<WasmSqlite3> loadSqlite3WithoutVfs({bool encryption = false}) async {
55
final channel = spawnHybridUri('/test/wasm/asset_server.dart');
66
final port = (await channel.stream.first as double).toInt();
77

8-
final sqliteWasm =
9-
Uri.parse('http://localhost:$port/example/web/sqlite3.wasm');
8+
final filename = encryption ? 'sqlite3mc.wasm' : 'sqlite3.wasm';
9+
final sqliteWasm = Uri.parse('http://localhost:$port/example/web/$filename');
1010

1111
return await WasmSqlite3.loadFromUrl(sqliteWasm);
1212
}

0 commit comments

Comments
 (0)