testdata at a83b44d, with resolved_ip.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>v0.13
parent
62107d7cd4
commit
d65e21864d
@ -0,0 +1,63 @@
|
||||
// The IP address that the name of an https address of a locator resolves
|
||||
// to, against testdata/vectors/resolved_ip.json of the draft v0.13 (spec
|
||||
// §44.1): a public address, or an address of NAT64 of 64:ff9b::/96 or of
|
||||
// the prefix of the network whose IPv4 address inside is public, with the
|
||||
// texts of locator.CheckResolvedIP of Go.
|
||||
@TestOn('vm')
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:datekeys/src/ipaddr.dart';
|
||||
import 'package:datekeys/src/locator.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
typedef Json = Map<String, Object?>;
|
||||
|
||||
void main() {
|
||||
final f = jsonDecode(
|
||||
File('testdata/vectors/resolved_ip.json').readAsStringSync(),
|
||||
) as Json;
|
||||
final cases = (f['cases']! as List).cast<Json>();
|
||||
|
||||
test('resolved_ip.json has the cases of README', () {
|
||||
expect(cases, hasLength(greaterThanOrEqualTo(40)));
|
||||
expect(cases.where((c) => c['result'] == 'ok'), isNotEmpty);
|
||||
expect(cases.where((c) => c['result'] == 'error'), isNotEmpty);
|
||||
});
|
||||
|
||||
for (final c in cases) {
|
||||
test('${c['name']}', () {
|
||||
final ip = parseIpAddress(c['ip']! as String)!;
|
||||
final nat64 = c['nat64']! as String;
|
||||
void check() =>
|
||||
checkResolvedIp(ip.bytes, nat64: nat64.isEmpty ? null : nat64);
|
||||
if (c['result'] == 'ok') {
|
||||
check();
|
||||
} else {
|
||||
expect(c['result'], 'error');
|
||||
expect(
|
||||
check,
|
||||
throwsA(
|
||||
isA<LocatorException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
c['error'],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('a prefix that does not parse is an ArgumentError', () {
|
||||
for (final s in ['64:ff9b::', '64:ff9b::/129', '64:ff9b::/-1', 'x/96']) {
|
||||
expect(
|
||||
() => checkResolvedIp([8, 8, 8, 8], nat64: s),
|
||||
throwsArgumentError,
|
||||
reason: s,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,287 @@
|
||||
{
|
||||
"spec": "0.12",
|
||||
"description": "The IP address that the name of an https address of a locator resolves to, and whether a reader may connect (spec v0.13, 44.1): a public address, or an address of NAT64 (RFC 6052) of 64:ff9b::/96 or of the NAT64 prefix of the network, whose IPv4 address inside is public. See testdata/README.md.",
|
||||
"cases": [
|
||||
{
|
||||
"name": "a public IPv4 address",
|
||||
"ip": "203.0.114.5",
|
||||
"nat64": "",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public IPv6 address",
|
||||
"ip": "2a01:4f8::1",
|
||||
"nat64": "",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a private IPv4 address",
|
||||
"ip": "192.168.1.10",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 192.168.1.10, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "loopback",
|
||||
"ip": "127.0.0.1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 127.0.0.1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "IPv6 loopback",
|
||||
"ip": "::1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to ::1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "an IPv6 link-local address",
|
||||
"ip": "fe80::1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to fe80::1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "an IPv6 unique local address",
|
||||
"ip": "fd00::1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to fd00::1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "an IPv4-mapped address of a public IPv4 address",
|
||||
"ip": "::ffff:203.0.114.5",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to ::ffff:203.0.114.5, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "6to4",
|
||||
"ip": "2002:cb00:7205::1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 2002:cb00:7205::1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "Teredo",
|
||||
"ip": "2001:0:cb00:7205::1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 2001:0:cb00:7205::1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with a public IPv4 address",
|
||||
"ip": "64:ff9b::cb00:7205",
|
||||
"nat64": "",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 8.8.8.8",
|
||||
"ip": "64:ff9b::808:808",
|
||||
"nat64": "",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with an IPv4 address of 10.0.0.0/8",
|
||||
"ip": "64:ff9b::a00:1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::a00:1, an address of NAT64 that holds 10.0.0.1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 192.168.1.10",
|
||||
"ip": "64:ff9b::c0a8:10a",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::c0a8:10a, an address of NAT64 that holds 192.168.1.10, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with loopback",
|
||||
"ip": "64:ff9b::7f00:1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::7f00:1, an address of NAT64 that holds 127.0.0.1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 169.254.169.254",
|
||||
"ip": "64:ff9b::a9fe:a9fe",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::a9fe:a9fe, an address of NAT64 that holds 169.254.169.254, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 100.64.0.1",
|
||||
"ip": "64:ff9b::6440:1",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::6440:1, an address of NAT64 that holds 100.64.0.1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 0.0.0.0",
|
||||
"ip": "64:ff9b::",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::, an address of NAT64 that holds 0.0.0.0, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with 255.255.255.255",
|
||||
"ip": "64:ff9b::ffff:ffff",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::ffff:ffff, an address of NAT64 that holds 255.255.255.255, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with a documentation address",
|
||||
"ip": "64:ff9b::cb00:7105",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::cb00:7105, an address of NAT64 that holds 203.0.113.5, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "an address of 64:ff9b::/16 outside 64:ff9b::/96",
|
||||
"ip": "64:ff9b::1:cb00:7205",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b::1:cb00:7205, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the local-use prefix of RFC 8215 without the prefix of the network",
|
||||
"ip": "64:ff9b:1::cb00:7205",
|
||||
"nat64": "",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b:1::cb00:7205, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix, given as the prefix of the network",
|
||||
"ip": "64:ff9b::cb00:7205",
|
||||
"nat64": "64:ff9b::/96",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "the well-known prefix with another prefix of the network",
|
||||
"ip": "64:ff9b::cb00:7205",
|
||||
"nat64": "64:ff9b:1::/48",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "the local-use prefix of RFC 8215, /48",
|
||||
"ip": "64:ff9b:1:cb00:72:500::",
|
||||
"nat64": "64:ff9b:1::/48",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "the local-use prefix, /48, with a private IPv4 address",
|
||||
"ip": "64:ff9b:1:c0a8:1:a00::",
|
||||
"nat64": "64:ff9b:1::/48",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b:1:c0a8:1:a00::, an address of NAT64 that holds 192.168.1.10, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "the local-use prefix, /48, with bits 64 to 71 set",
|
||||
"ip": "64:ff9b:1:cb00:172:500::",
|
||||
"nat64": "64:ff9b:1::/48",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 64:ff9b:1:cb00:172:500::, an address of the NAT64 prefix 64:ff9b:1::/48 whose bits 64 to 71 are not zero"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /96",
|
||||
"ip": "2a01:4f8:c0:64::cb00:7205",
|
||||
"nat64": "2a01:4f8:c0:64::/96",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /96, with a private IPv4 address",
|
||||
"ip": "2a01:4f8:c0:64::c0a8:10a",
|
||||
"nat64": "2a01:4f8:c0:64::/96",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 2a01:4f8:c0:64::c0a8:10a, an address of NAT64 that holds 192.168.1.10, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /96, with loopback",
|
||||
"ip": "2a01:4f8:c0:64::7f00:1",
|
||||
"nat64": "2a01:4f8:c0:64::/96",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 2a01:4f8:c0:64::7f00:1, an address of NAT64 that holds 127.0.0.1, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /32",
|
||||
"ip": "2a01:4f8:cb00:7205::",
|
||||
"nat64": "2a01:4f8::/32",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /40",
|
||||
"ip": "2a01:4f8:c0cb:72:5::",
|
||||
"nat64": "2a01:4f8:c000::/40",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /56",
|
||||
"ip": "2a01:4f8:c0:64cb:0:7205::",
|
||||
"nat64": "2a01:4f8:c0:6400::/56",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /64",
|
||||
"ip": "2a01:4f8:c0:64:cb:72:500:0",
|
||||
"nat64": "2a01:4f8:c0:64::/64",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a public prefix of the network, /64, with a private IPv4 address",
|
||||
"ip": "2a01:4f8:c0:64:c0:a801:a00:0",
|
||||
"nat64": "2a01:4f8:c0:64::/64",
|
||||
"result": "error",
|
||||
"error": "locator: an https address whose name resolves to 2a01:4f8:c0:64:c0:a801:a00:0, an address of NAT64 that holds 192.168.1.10, an IP address that is not public"
|
||||
},
|
||||
{
|
||||
"name": "a public address outside the prefix of the network",
|
||||
"ip": "2a01:4f8::1",
|
||||
"nat64": "64:ff9b:1::/48",
|
||||
"result": "ok"
|
||||
},
|
||||
{
|
||||
"name": "a prefix of the network of 80 bits",
|
||||
"ip": "64:ff9b:1::cb00:7205",
|
||||
"nat64": "64:ff9b:1::/80",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix 64:ff9b:1::/80 is not of 32, 40, 48, 56, 64 or 96 bits (RFC 6052)"
|
||||
},
|
||||
{
|
||||
"name": "a link-local prefix of the network",
|
||||
"ip": "fe80::cb00:7205",
|
||||
"nat64": "fe80::/96",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix fe80::/96 is neither in 64:ff9b::/16 nor a public IPv6 prefix"
|
||||
},
|
||||
{
|
||||
"name": "a unique local prefix of the network",
|
||||
"ip": "fd00::cb00:7205",
|
||||
"nat64": "fd00::/96",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix fd00::/96 is neither in 64:ff9b::/16 nor a public IPv6 prefix"
|
||||
},
|
||||
{
|
||||
"name": "a prefix of the network of 2001:db8::/32",
|
||||
"ip": "2001:db8::cb00:7205",
|
||||
"nat64": "2001:db8::/96",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix 2001:db8::/96 is neither in 64:ff9b::/16 nor a public IPv6 prefix"
|
||||
},
|
||||
{
|
||||
"name": "a prefix of the network with bits after its length",
|
||||
"ip": "64:ff9b::cb00:7205",
|
||||
"nat64": "64:ff9b::1/96",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix 64:ff9b::1/96 has bits set after its length"
|
||||
},
|
||||
{
|
||||
"name": "an IPv4 prefix of the network",
|
||||
"ip": "203.0.114.5",
|
||||
"nat64": "203.0.114.0/24",
|
||||
"result": "error",
|
||||
"error": "locator: the NAT64 prefix 203.0.114.0/24 is not an IPv6 prefix"
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in new issue