Skip to content

Commit 74d4a94

Browse files
authored
Merge pull request #1156 from forcedotcom/sm/workspaces-support
fix: dns lookup doesn't include port
2 parents 4c909a6 + b62073c commit 74d4a94

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/status/myDomainResolver.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,24 @@ export class MyDomainResolver extends AsyncOptionalCreatable<MyDomainResolver.Op
8383
const self: MyDomainResolver = this;
8484
const pollingOptions: PollingClient.Options = {
8585
async poll(): Promise<StatusResult> {
86-
const { host } = self.options.url;
86+
const { hostname } = self.options.url;
8787
let dnsResult: { address: string };
8888
try {
89-
self.logger.debug(`Attempting to resolve url: ${host}`);
89+
self.logger.debug(`Attempting to resolve url: ${hostname}`);
9090
if (new SfdcUrl(self.options.url).isLocalUrl()) {
9191
return {
9292
completed: true,
9393
payload: '127.0.0.1',
9494
};
9595
}
96-
dnsResult = await promisify(lookup)(host);
97-
self.logger.debug(`Successfully resolved host: ${host} result: ${JSON.stringify(dnsResult)}`);
96+
dnsResult = await promisify(lookup)(hostname);
97+
self.logger.debug(`Successfully resolved host: ${hostname} result: ${JSON.stringify(dnsResult)}`);
9898
return {
9999
completed: true,
100100
payload: dnsResult.address,
101101
};
102102
} catch (e) {
103-
self.logger.debug(`An error occurred trying to resolve: ${host}`);
103+
self.logger.debug(`An error occurred trying to resolve: ${hostname}`);
104104
self.logger.debug(`Error: ${(e as Error).message}`);
105105
self.logger.debug('Re-trying dns lookup again....');
106106
return {

src/util/sfdcUrl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class SfdcUrl extends URL {
135135
'.stm.salesforce.ms',
136136
'.pc-rnd.force.com',
137137
'.pc-rnd.salesforce.com',
138-
'.wc.crm.dev', // workspaces container
138+
'.crm.dev', // workspaces container
139139
];
140140
return (
141141
this.origin.startsWith('https://gs1.') ||

test/unit/status/myDomainResolver.test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ describe('myDomainResolver', () => {
2020
const TEST_IP = '1.1.1.1';
2121
const CALL_COUNT = 3;
2222

23-
let lookupAsyncSpy: { callCount: number };
23+
let lookupAsyncSpy: sinon.SinonStub;
24+
2425
beforeEach(() => {
2526
lookupAsyncSpy = $$.SANDBOX.stub(dns, 'lookup').callsFake((host: string, callback: AnyFunction) => {
2627
const isDefaultHost = host === MyDomainResolver.DEFAULT_DOMAIN.host;
@@ -45,6 +46,17 @@ describe('myDomainResolver', () => {
4546
expect(lookupAsyncSpy.callCount).to.be.equal(CALL_COUNT);
4647
});
4748

49+
it('should do lookup without port', async () => {
50+
const options: MyDomainResolver.Options = {
51+
url: new URL(`https://${POSITIVE_HOST}:6101`),
52+
};
53+
const resolver: MyDomainResolver = await MyDomainResolver.create(options);
54+
const ip = await resolver.resolve();
55+
expect(ip).to.be.equal(TEST_IP);
56+
// verify that it uses hostname (without port) not host
57+
expect(lookupAsyncSpy.args[0][0]).to.be.equal(POSITIVE_HOST);
58+
});
59+
4860
describe('disable dns check', () => {
4961
const env = new Env();
5062
it('should return host if SFDX_DISABLE_DNS_CHECK is set to true', async () => {

test/unit/util/sfdcUrl.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,16 @@ describe('util/sfdcUrl', () => {
180180
expect(url.isLocalUrl()).to.equal(true);
181181
});
182182
it('workspaces with port is internal but not local', () => {
183-
const url = new SfdcUrl('https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wc.crm.dev:6101/');
184-
expect(url.isInternalUrl()).to.equal(true);
185-
expect(url.isLocalUrl()).to.equal(false);
183+
const urls = [
184+
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wc.crm.dev:6101/',
185+
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wb.crm.dev:6101/',
186+
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wa.crm.dev:6101/',
187+
].map((u) => new SfdcUrl(u));
188+
189+
urls.map((url) => {
190+
expect(url.isInternalUrl()).to.equal(true);
191+
expect(url.isLocalUrl()).to.equal(false);
192+
});
186193
});
187194
});
188195

0 commit comments

Comments
 (0)