Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dns lookup doesn't include port #1156

Merged
merged 3 commits into from
Nov 13, 2024
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
10 changes: 5 additions & 5 deletions src/status/myDomainResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ export class MyDomainResolver extends AsyncOptionalCreatable<MyDomainResolver.Op
const self: MyDomainResolver = this;
const pollingOptions: PollingClient.Options = {
async poll(): Promise<StatusResult> {
const { host } = self.options.url;
const { hostname } = self.options.url;
let dnsResult: { address: string };
try {
self.logger.debug(`Attempting to resolve url: ${host}`);
self.logger.debug(`Attempting to resolve url: ${hostname}`);
if (new SfdcUrl(self.options.url).isLocalUrl()) {
return {
completed: true,
payload: '127.0.0.1',
};
}
dnsResult = await promisify(lookup)(host);
self.logger.debug(`Successfully resolved host: ${host} result: ${JSON.stringify(dnsResult)}`);
dnsResult = await promisify(lookup)(hostname);
self.logger.debug(`Successfully resolved host: ${hostname} result: ${JSON.stringify(dnsResult)}`);
return {
completed: true,
payload: dnsResult.address,
};
} catch (e) {
self.logger.debug(`An error occurred trying to resolve: ${host}`);
self.logger.debug(`An error occurred trying to resolve: ${hostname}`);
self.logger.debug(`Error: ${(e as Error).message}`);
self.logger.debug('Re-trying dns lookup again....');
return {
Expand Down
2 changes: 1 addition & 1 deletion src/util/sfdcUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class SfdcUrl extends URL {
'.stm.salesforce.ms',
'.pc-rnd.force.com',
'.pc-rnd.salesforce.com',
'.wc.crm.dev', // workspaces container
'.crm.dev', // workspaces container
];
return (
this.origin.startsWith('https://gs1.') ||
Expand Down
14 changes: 13 additions & 1 deletion test/unit/status/myDomainResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('myDomainResolver', () => {
const TEST_IP = '1.1.1.1';
const CALL_COUNT = 3;

let lookupAsyncSpy: { callCount: number };
let lookupAsyncSpy: sinon.SinonStub;

beforeEach(() => {
lookupAsyncSpy = $$.SANDBOX.stub(dns, 'lookup').callsFake((host: string, callback: AnyFunction) => {
const isDefaultHost = host === MyDomainResolver.DEFAULT_DOMAIN.host;
Expand All @@ -45,6 +46,17 @@ describe('myDomainResolver', () => {
expect(lookupAsyncSpy.callCount).to.be.equal(CALL_COUNT);
});

it('should do lookup without port', async () => {
const options: MyDomainResolver.Options = {
url: new URL(`https://${POSITIVE_HOST}:6101`),
};
const resolver: MyDomainResolver = await MyDomainResolver.create(options);
const ip = await resolver.resolve();
expect(ip).to.be.equal(TEST_IP);
// verify that it uses hostname (without port) not host
expect(lookupAsyncSpy.args[0][0]).to.be.equal(POSITIVE_HOST);
});

describe('disable dns check', () => {
const env = new Env();
it('should return host if SFDX_DISABLE_DNS_CHECK is set to true', async () => {
Expand Down
13 changes: 10 additions & 3 deletions test/unit/util/sfdcUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,16 @@ describe('util/sfdcUrl', () => {
expect(url.isLocalUrl()).to.equal(true);
});
it('workspaces with port is internal but not local', () => {
const url = new SfdcUrl('https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wc.crm.dev:6101/');
expect(url.isInternalUrl()).to.equal(true);
expect(url.isLocalUrl()).to.equal(false);
const urls = [
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wc.crm.dev:6101/',
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wb.crm.dev:6101/',
'https://dev.salesforce-com.shane-mclaughlin-0lrfx7zp3l121.wa.crm.dev:6101/',
].map((u) => new SfdcUrl(u));

urls.map((url) => {
expect(url.isInternalUrl()).to.equal(true);
expect(url.isLocalUrl()).to.equal(false);
});
});
});

Expand Down
Loading