mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-01-12 22:52:34 +08:00
handle zonefiles more gracefully, fix #1109
This commit is contained in:
committed by
Reed Rosenbluth
parent
77c0a549a5
commit
fc83974283
@@ -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
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user