omemo_dart/test/trust_test.dart

41 lines
1.5 KiB
Dart
Raw Normal View History

2022-08-08 16:47:43 +00:00
import 'package:omemo_dart/omemo_dart.dart';
import 'package:test/test.dart';
void main() {
test('Test the Blind Trust Before Verification TrustManager', () async {
// Caroline's BTBV manager
2023-06-17 13:21:11 +00:00
final btbv = BlindTrustBeforeVerificationTrustManager();
2022-08-08 16:47:43 +00:00
// Example data
const aliceJid = 'alice@some.server';
const bobJid = 'bob@other.server';
2023-06-12 17:20:43 +00:00
2022-08-08 16:47:43 +00:00
// Caroline starts a chat a device from Alice
await btbv.onNewSession(aliceJid, 1);
expect(await btbv.isTrusted(aliceJid, 1), true);
expect(await btbv.isEnabled(aliceJid, 1), true);
2022-08-08 16:47:43 +00:00
// Caroline meets with Alice and verifies her fingerprint
await btbv.setDeviceTrust(aliceJid, 1, BTBVTrustState.verified);
expect(await btbv.isTrusted(aliceJid, 1), true);
// Alice adds a new device
await btbv.onNewSession(aliceJid, 2);
expect(await btbv.isTrusted(aliceJid, 2), false);
expect(btbv.getDeviceTrust(aliceJid, 2), BTBVTrustState.notTrusted);
expect(await btbv.isEnabled(aliceJid, 2), false);
2022-08-08 16:47:43 +00:00
// Caronline starts a chat with Bob but since they live far apart, Caroline cannot
// verify his fingerprint.
await btbv.onNewSession(bobJid, 3);
// Bob adds a new device
await btbv.onNewSession(bobJid, 4);
expect(await btbv.isTrusted(bobJid, 3), true);
expect(await btbv.isTrusted(bobJid, 4), true);
expect(btbv.getDeviceTrust(bobJid, 3), BTBVTrustState.blindTrust);
expect(btbv.getDeviceTrust(bobJid, 4), BTBVTrustState.blindTrust);
expect(await btbv.isEnabled(bobJid, 3), true);
expect(await btbv.isEnabled(bobJid, 4), true);
2022-08-08 16:47:43 +00:00
});
}