askrobots / network-computer-flutter
Public
One Flutter client for network-computer: drive a remote Linux/Mac desktop from Android, iPhone, iPad, or desktop over WebRTC.
Dan Quellhorst
No colour (compare) in ⋯: the desk's picture in grey on this device
c74471a
1 month, 3 weeks ago
History
protocol_test.dart · 1.2 KB · 32 lines
| 1 | import 'dart:convert'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:network_computer/protocol.dart'; |
| 4 | import 'package:network_computer/signaling.dart'; |
| 5 | |
| 6 | void main() { |
| 7 | test('offer carries pin and pairing token in the Go field names', () { |
| 8 | final m = SignalMessage(type: 'offer', to: 'box', sdp: 'v=0', pin: '424242', pair: 'abc.def'); |
| 9 | final j = jsonDecode(jsonEncode(m.toJson())) as Map<String, dynamic>; |
| 10 | expect(j['pin'], '424242'); |
| 11 | expect(j['pair'], 'abc.def'); |
| 12 | }); |
| 13 | |
| 14 | test('answer from the host yields its pairing token', () { |
| 15 | final m = SignalMessage.fromJson( |
| 16 | {'type': 'answer', 'from': 'c3', 'sdp': 'v=0', 'pair': 'tok.sig'}); |
| 17 | expect(m.pair, 'tok.sig'); |
| 18 | }); |
| 19 | |
| 20 | test('absent fields are omitted, not sent as null', () { |
| 21 | final j = SignalMessage(type: 'offer', to: 'box', sdp: 'v=0').toJson(); |
| 22 | expect(j.containsKey('pin'), isFalse); |
| 23 | expect(j.containsKey('pair'), isFalse); |
| 24 | }); |
| 25 | |
| 26 | test('fingerprints normalise from any common format', () { |
| 27 | const hex = 'ab12cd34'; |
| 28 | expect(normalizeFingerprint('AB:12:CD:34'), hex); |
| 29 | expect(normalizeFingerprint('sha256 ab12cd34'), hex); |
| 30 | expect(normalizeFingerprint(' AB12CD34 '), hex); |
| 31 | }); |
| 32 | } |