|
|
|
|
@ -53,6 +53,87 @@ void main() {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('offband.app links (#1309)', () {
|
|
|
|
|
String https(String host, String kind, String fields) =>
|
|
|
|
|
'https://$host/add/$kind#$fields';
|
|
|
|
|
|
|
|
|
|
test('read the same as their meshcore:// twins, on both hosts', () {
|
|
|
|
|
for (final host in shareLinkHosts) {
|
|
|
|
|
final channel =
|
|
|
|
|
parseShareLink(
|
|
|
|
|
https(
|
|
|
|
|
host,
|
|
|
|
|
'channel',
|
|
|
|
|
'name=%23echo&secret=5d25cf40b1f5b4a7eb0cf9703634a948',
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
as ChannelShareLink;
|
|
|
|
|
final twin = parseShareLink(_channelLink) as ChannelShareLink;
|
|
|
|
|
expect(channel.channel.name, twin.channel.name);
|
|
|
|
|
expect(channel.channel.pskHex, twin.channel.pskHex);
|
|
|
|
|
|
|
|
|
|
final hashtag =
|
|
|
|
|
parseShareLink(https(host, 'channel', 'name=%23example'))
|
|
|
|
|
as ChannelShareLink;
|
|
|
|
|
expect(hashtag.channel.name, '#example');
|
|
|
|
|
|
|
|
|
|
final contact =
|
|
|
|
|
parseShareLink(
|
|
|
|
|
https(host, 'contact', 'name=Bob&public_key=$_key&type=1'),
|
|
|
|
|
)
|
|
|
|
|
as ContactShareLink;
|
|
|
|
|
expect(contact.contact.name, 'Bob');
|
|
|
|
|
// The add-contact dialog reads the link again, in the form it knows.
|
|
|
|
|
expect(contact.uri, _contactLink);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('keep a name with reserved characters intact', () {
|
|
|
|
|
const secret = '5d25cf40b1f5b4a7eb0cf9703634a948';
|
|
|
|
|
for (final name in ['a&b', 'x=y', '50% off', 'one+two', 'a b', '#c#d']) {
|
|
|
|
|
final link =
|
|
|
|
|
Channel(
|
|
|
|
|
index: 0,
|
|
|
|
|
name: name,
|
|
|
|
|
psk: Channel.parsePskHex(secret),
|
|
|
|
|
).toShareUri().replaceFirst(
|
|
|
|
|
'meshcore://channel/add?',
|
|
|
|
|
'https://offband.app/add/channel#',
|
|
|
|
|
);
|
|
|
|
|
final parsed = parseShareLink(link) as ChannelShareLink;
|
|
|
|
|
expect(parsed.channel.name, name, reason: link);
|
|
|
|
|
expect(parsed.channel.pskHex, secret, reason: link);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('accept the host in any case and a trailing slash', () {
|
|
|
|
|
expect(
|
|
|
|
|
parseShareLink('https://Offband.App/add/channel/#name=%23example'),
|
|
|
|
|
isA<ChannelShareLink>(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('anything else is not one', () {
|
|
|
|
|
for (final bad in [
|
|
|
|
|
'http://offband.app/add/channel#name=%23example',
|
|
|
|
|
'https://example.com/add/channel#name=%23example',
|
|
|
|
|
'https://offband.app.example.com/add/channel#name=%23example',
|
|
|
|
|
'https://offband.app:8443/add/channel#name=%23example',
|
|
|
|
|
'https://offband.app/add/channel',
|
|
|
|
|
'https://offband.app/add/channel#',
|
|
|
|
|
// Fields in the query would reach the server's logs.
|
|
|
|
|
'https://offband.app/add/channel?name=%23example',
|
|
|
|
|
'https://offband.app/add/channel?x=1#name=%23example',
|
|
|
|
|
'https://offband.app/add/group#name=%23example',
|
|
|
|
|
'https://offband.app/add/channel/more#name=%23example',
|
|
|
|
|
'https://offband.app/channel#name=%23example',
|
|
|
|
|
]) {
|
|
|
|
|
expect(meshcoreFormOf(bad), isNull, reason: bad);
|
|
|
|
|
expect(parseShareLink(bad), isNull, reason: bad);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('LinkRouter', () {
|
|
|
|
|
test('a malformed link is reported, not dropped', () {
|
|
|
|
|
final router = LinkRouter();
|
|
|
|
|
@ -118,6 +199,37 @@ void main() {
|
|
|
|
|
expect(router.takeRejected(), isNotNull, reason: 'a broken share link');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an offband.app link from the OS is taken and cleared (#1309)', () {
|
|
|
|
|
var cleared = 0;
|
|
|
|
|
final router = LinkRouter(clearAddressLink: () => cleared++);
|
|
|
|
|
router.handleFromOs(
|
|
|
|
|
Uri.parse('https://offband.app/add/channel#name=%23example'),
|
|
|
|
|
);
|
|
|
|
|
expect(router.pending, isA<ChannelShareLink>());
|
|
|
|
|
expect(cleared, 1);
|
|
|
|
|
|
|
|
|
|
// An /add/ address with broken fields is still a share link: it is
|
|
|
|
|
// reported, and still cleared so a reload does not report it again.
|
|
|
|
|
router.handleFromOs(Uri.parse('https://offband.app/add/channel'));
|
|
|
|
|
expect(router.takeRejected(), isNotNull);
|
|
|
|
|
expect(cleared, 2);
|
|
|
|
|
|
|
|
|
|
// The site's other pages are not links.
|
|
|
|
|
router.handleFromOs(Uri.parse('https://offband.app/'));
|
|
|
|
|
router.handleFromOs(Uri.parse('https://offband.app/privacy#top'));
|
|
|
|
|
router.handleFromOs(Uri.parse('https://example.com/add/channel#x=1'));
|
|
|
|
|
expect(router.takeRejected(), isNull);
|
|
|
|
|
expect(cleared, 2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('a meshcore:// link from the OS clears nothing', () {
|
|
|
|
|
var cleared = 0;
|
|
|
|
|
LinkRouter(
|
|
|
|
|
clearAddressLink: () => cleared++,
|
|
|
|
|
).handleFromOs(Uri.parse(_hashtagLink));
|
|
|
|
|
expect(cleared, 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('a malformed link does not replace a held one', () {
|
|
|
|
|
final router = LinkRouter()..handle(_channelLink);
|
|
|
|
|
router.handle('meshcore://nope');
|
|
|
|
|
|