Skip to content

Commit e17d256

Browse files
committed
Add Dart package tests (smoke + access-token round-trip)
Ship tests in support/dart/test, copied into the generated package by the dart-package flow. Covers the FFI smoke path (buildVersion) and a real JWT/HMAC round-trip (generate -> verify -> decode, plus wrong-secret rejection) to exercise Rust logic across the boundary.
1 parent e7474d2 commit e17d256

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

livekit-uniffi/Makefile.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,23 @@ script = """
679679
cp ${LIB_PATH} ${PACKAGES_DIR}/${LANG}/
680680
"""
681681

682+
[tasks.dart-copy-tests]
683+
private = true
684+
script_runner = "@shell"
685+
script = """
686+
mkdir -p ${PACKAGES_DIR}/${LANG}/test
687+
cp ${SUPPORT_DIR}/${LANG}/test/*.dart ${PACKAGES_DIR}/${LANG}/test/
688+
"""
689+
682690
[tasks.dart-package-flow]
683691
private = true
684692
dependencies = [
685693
"bindgen-dart",
686694
"dart-move-code-into-lib",
687695
"dart-generate-manifest",
688696
"dart-copy-hook",
689-
"dart-copy-lib"
697+
"dart-copy-lib",
698+
"dart-copy-tests"
690699
]
691700

692701
[tasks.dart-package]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:test/test.dart';
2+
import 'package:livekit_uniffi/livekit_uniffi.dart';
3+
4+
void main() {
5+
// Exercises real Rust JWT/HMAC logic across the FFI boundary: generate a
6+
// token, then verify and decode it.
7+
final creds = ApiCredentials(key: 'devkey', secret: 'devsecret');
8+
9+
group('access token', () {
10+
test('generate produces a well-formed JWT', () {
11+
final token = tokenGenerate(
12+
options: TokenOptions(identity: 'alice', name: 'Alice'),
13+
credentials: creds,
14+
);
15+
// header.payload.signature
16+
expect(token.split('.'), hasLength(3));
17+
});
18+
19+
test('verify round-trips identity, name, and issuer', () {
20+
final token = tokenGenerate(
21+
options: TokenOptions(identity: 'alice', name: 'Alice'),
22+
credentials: creds,
23+
);
24+
final claims = tokenVerify(token: token, credentials: creds);
25+
expect(claims.sub, equals('alice'));
26+
expect(claims.name, equals('Alice'));
27+
expect(claims.iss, equals('devkey'));
28+
});
29+
30+
test('claims can be read without the secret', () {
31+
final token = tokenGenerate(
32+
options: TokenOptions(identity: 'bob'),
33+
credentials: creds,
34+
);
35+
final claims = tokenClaimsFromUnverified(token: token);
36+
expect(claims.sub, equals('bob'));
37+
});
38+
39+
test('verify rejects a token signed with a different secret', () {
40+
final token = tokenGenerate(
41+
options: TokenOptions(identity: 'alice'),
42+
credentials: creds,
43+
);
44+
final wrong = ApiCredentials(key: 'devkey', secret: 'wrongsecret');
45+
expect(
46+
() => tokenVerify(token: token, credentials: wrong),
47+
throwsA(isA<AccessTokenException>()),
48+
);
49+
});
50+
});
51+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:test/test.dart';
2+
import 'package:livekit_uniffi/livekit_uniffi.dart';
3+
4+
void main() {
5+
// Smoke test for the whole FFI path: the build hook resolves the native
6+
// library, Dart calls a Rust function, and the result crosses back.
7+
test('buildVersion returns a non-empty version string', () {
8+
expect(buildVersion(), isNotEmpty);
9+
});
10+
}

0 commit comments

Comments
 (0)