handle zonefiles more gracefully, fix #1109

This commit is contained in:
Friedger Müffke
2021-10-07 16:25:13 +02:00
committed by Reed Rosenbluth
parent 77c0a549a5
commit fc83974283
2 changed files with 28 additions and 3 deletions

View File

@@ -302,12 +302,21 @@ export function getTokenFileUrl(zoneFileJson: any): string | null {
if (zoneFileJson.uri.length < 1) {
return null;
}
const firstUriRecord = zoneFileJson.uri[0];
if (!firstUriRecord.hasOwnProperty('target')) {
const validRecords = zoneFileJson.uri.filter(
(record: any) => record.hasOwnProperty('target') && record.name === '_http._tcp'
);
if (validRecords.length < 1) {
return null;
}
let tokenFileUrl = firstUriRecord.target;
const firstValidRecord = validRecords[0];
if (!firstValidRecord.hasOwnProperty('target')) {
return null;
}
let tokenFileUrl = firstValidRecord.target;
if (tokenFileUrl.startsWith('https')) {
// pass

View File

@@ -1,9 +1,11 @@
import { parseZoneFile } from 'zone-file'
import {
signProfileToken,
wrapProfileToken,
verifyProfileToken,
extractProfile,
makeProfileZoneFile,
getTokenFileUrl,
} from '../src'
import { sampleProfiles } from './sampleData'
@@ -56,4 +58,18 @@ profiles.forEach(profile => {
expect(actualZoneFile).toEqual(expectedZoneFile)
})
test('getTokenFileUrl', () => {
const zoneFile = '$ORIGIN satoshi.id\n$TTL 3600\n_http._tcp IN URI 10 1 "https://example.com/satoshi.json"\n\n'
const expectedTokenFileUrl = "https://example.com/satoshi.json"
const actualTokenFileUrl = getTokenFileUrl(parseZoneFile(zoneFile))
expect(actualTokenFileUrl).toEqual(expectedTokenFileUrl)
})
test('getTokenFileUrl from zonefile with redirect', () => {
const zoneFile = '$ORIGIN satoshi.id\n$TTL 3600\n_redirect IN URI 10 1 "https://example.com/"\n_http._tcp IN URI 10 1 "https://example.com/satoshi.json"\n\n'
const expectedTokenFileUrl = "https://example.com/satoshi.json"
const actualTokenFileUrl = getTokenFileUrl(parseZoneFile(zoneFile))
expect(actualTokenFileUrl).toEqual(expectedTokenFileUrl)
})
});