Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/services/transfer/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { readableBytes, isDirectory, isFileDocument, getDomainFromEndpoint } from '../utils';
import {
readableBytes,
isDirectory,
isFileDocument,
getDomainFromEndpoint,
isGlobusHostname,
} from '../utils';

describe('readableBytes', () => {
it('should return the correct readable string for bytes', () => {
Expand Down Expand Up @@ -58,6 +64,17 @@ describe('isFileDocument', () => {
});
});

describe('isGlobusHostname', () => {
it('should return true for valid Globus hostnames', () => {
expect(isGlobusHostname('collection.dn.glob.us')).toBe(true);
expect(isGlobusHostname('m-4d5adb.fa5e.bd7c.data.globus.org')).toBe(true);
});
it('should return false for invalid Globus hostnames', () => {
expect(isGlobusHostname('example.com')).toBe(false);
expect(isGlobusHostname('example.org')).toBe(false);
});
});

describe('getDomainFromEndpoint', () => {
it('should return the domain from a valid endpoint', () => {
/**
Expand Down
13 changes: 11 additions & 2 deletions src/services/transfer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ export function readableBytes(bytes: number, truncate = 2) {
/**
* Known Globus DNS domains.
*/
const GLOBUS_DNS_DOMAINS = ['dnsteam.globuscs.info', 'data.globus.org', 'dn.glob.us'];
export const GLOBUS_DNS_DOMAINS = ['dnsteam.globuscs.info', 'data.globus.org', 'dn.glob.us'];

/**
* Check the given hostname to determine if it is one of the known Globus DNS domains.
* @param hostname The hostname to check.
* @returns `true` if the hostname is a known Globus DNS domain, `false` otherwise.
*/
export function isGlobusHostname(hostname: string): boolean {
return Boolean(GLOBUS_DNS_DOMAINS.find((d) => hostname.endsWith(d)));
}

/**
* Returns DNS domain, if any, for a collection or endpoint.
Expand All @@ -87,7 +96,7 @@ export function getDomainFromEndpoint(endpoint: Record<string, unknown>) {
* Swap the protocol to `https` so we can use the URL API to extract the hostname.
*/
const { hostname } = new URL(tls.replace('tlsftp', 'https'));
const hasCustomDomain = !GLOBUS_DNS_DOMAINS.find((d) => hostname.endsWith(d));
const hasCustomDomain = !isGlobusHostname(hostname);
const customDomain = hasCustomDomain && /(?:[gm]-\w{6}.)?(\w+(\.\w+)+)$/.exec(hostname)?.[1];

return customDomain || hostname || null;
Expand Down