the-mews/app/test/tofu_test.dart

44 lines
1.5 KiB
Dart
Raw Normal View History

import 'package:flutter_test/flutter_test.dart';
import 'package:mews/protocols/tofu.dart';
void main() {
test('a first visit accepts and pins what was presented', () {
final now = DateTime(2026, 10, 11);
expect(decideTofu(null, 'aa', now), TofuDecision.firstUse);
});
test('the pinned certificate is accepted again', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2030));
expect(decideTofu(pin, 'aa', now), TofuDecision.match);
});
test('a change is a renewal when the pin has expired', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2020));
expect(decideTofu(pin, 'bb', now), TofuDecision.rePin);
});
test('a change is refused while the pin is still valid', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2030));
expect(decideTofu(pin, 'bb', now), TofuDecision.refuse);
});
test('a pin that ends exactly now counts as expired', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: now);
expect(decideTofu(pin, 'bb', now), TofuDecision.rePin);
});
test('a fingerprint comes from the DER encoding', () {
final pin = pinOf([1, 2, 3], expires: DateTime(2030));
// sha256 of the three bytes, as lowercase hex.
expect(
pin.fingerprint,
'039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81',
);
});
}