Skip to content

Commit c83f673

Browse files
replaced hostname in domainvalidation
1 parent 6dcd5c6 commit c83f673

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

packages/client/src/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ export class PercyClient {
810810
}
811811

812812
// Validates a domain with the Cloudflare worker endpoint
813-
async validateDomain(hostname, url, options = {}) {
813+
async validateDomain(hostname, options = {}) {
814814
const endpoint = 'https://winter-morning-fa32.shobhit-k.workers.dev/validate-domain';
815815
const timeout = 5000;
816816

@@ -820,7 +820,7 @@ export class PercyClient {
820820
const response = await request(endpoint, {
821821
method: 'POST',
822822
headers: { 'Content-Type': 'application/json' },
823-
body: JSON.stringify({ domain: hostname, url }),
823+
body: JSON.stringify({ domain: hostname }),
824824
timeout
825825
});
826826

packages/client/test/helpers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ export const api = {
146146
'/discovery/device-details': () => [201, {
147147
data: []
148148
}],
149+
'/projects/domain-config': () => [200, {
150+
data: {
151+
id: 'domain-config',
152+
type: 'projects',
153+
attributes: {
154+
'domain-config': {
155+
allowed: [],
156+
blocked: []
157+
}
158+
}
159+
}
160+
}],
149161
'/logs': () => [200, 'random_sha']
150162
},
151163

packages/core/src/network.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ async function validateDomainForAllowlist(network, hostname, url) {
489489
stats.apiCalls++;
490490
network.log.debug(`Domain validation: Validating ${hostname} via external service`, network.meta);
491491

492-
const result = await client.validateDomain(hostname, url, { validationEndpoint, timeout });
492+
const result = await client.validateDomain(hostname, { validationEndpoint, timeout });
493493

494494
// Worker returns 'accessible' field, not 'allowed'
495495
if (result?.accessible) {

packages/core/src/percy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export class Percy {
738738
this.log.debug(`Domain validation: Loaded ${domainConfig['blocked-domains'].length} pre-blocked domains`);
739739
}
740740

741-
this.log.info(`Domain validation: Initialized with ${this.domainValidation.preApproved.size} allowed and ${this.domainValidation.preBlocked.size} blocked domains`);
741+
this.log.debug(`Domain validation: Initialized with ${this.domainValidation.preApproved.size} allowed and ${this.domainValidation.preBlocked.size} blocked domains`);
742742
} else {
743743
this.log.debug('Domain validation: No existing domain config found for project');
744744
}

packages/core/test/discovery.test.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ describe('Discovery', () => {
5151
return [201, { data: { id: '4567' } }];
5252
});
5353

54+
// Mock domain config endpoint - return empty config by default
55+
api.reply('/projects/domain-config', () => [200, {
56+
data: {
57+
type: 'projects',
58+
id: '123',
59+
attributes: {}
60+
}
61+
}]);
62+
5463
const dynamicImageRoutes = {};
5564
for (let i = 0; i < 800; i++) {
5665
dynamicImageRoutes[`/dynamic/image-${i}.png`] = () => [200, 'image/png', pixel];
@@ -2896,6 +2905,9 @@ describe('Discovery', () => {
28962905
it('loads domain config early from API before discovery starts', async () => {
28972906
await percy.stop();
28982907

2908+
// Clear previous mocks and set up new one
2909+
api.replies['/projects/domain-config'] = [];
2910+
28992911
// Mock API response for domain config endpoint
29002912
api.reply('/projects/domain-config', () => [200, {
29012913
data: {
@@ -2904,7 +2916,6 @@ describe('Discovery', () => {
29042916
'domain-config': {
29052917
'allowed-domains': ['cdn.example.com', 'images.example.com'],
29062918
'blocked-domains': ['evil.example.com'],
2907-
'auto-allow-enabled': true,
29082919
'updated-at': '2024-01-01T00:00:00Z',
29092920
'last-build-id': '123'
29102921
}
@@ -2927,6 +2938,9 @@ describe('Discovery', () => {
29272938
it('handles missing domain config gracefully during early load', async () => {
29282939
await percy.stop();
29292940

2941+
// Clear previous mocks and set up empty config
2942+
api.replies['/projects/domain-config'] = [];
2943+
29302944
// Mock API response with no domain config
29312945
api.reply('/projects/domain-config', () => [200, {
29322946
data: {
@@ -2947,6 +2961,9 @@ describe('Discovery', () => {
29472961
it('continues without domain config if API call fails during early load', async () => {
29482962
await percy.stop();
29492963

2964+
// Clear previous mocks and set up error response
2965+
api.replies['/projects/domain-config'] = [];
2966+
29502967
// Mock API to return error
29512968
api.reply('/projects/domain-config', () => [404, 'Not Found']);
29522969

@@ -3594,9 +3611,14 @@ describe('Discovery', () => {
35943611

35953612
describe('waitForSelector/waitForTimeout at the time of discovery when Js is enabled =>', () => {
35963613
it('calls waitForTimeout, waitForSelector and page.eval when their respective arguments are given', async () => {
3597-
const page = await percy.browser.page({ intercept: { getResource: () => {} } });
3598-
spyOn(percy.browser, 'page').and.returnValue(page);
3599-
spyOn(page, 'eval').and.callThrough();
3614+
let capturedPage;
3615+
const originalPageMethod = percy.browser.page.bind(percy.browser);
3616+
spyOn(percy.browser, 'page').and.callFake(async (options) => {
3617+
capturedPage = await originalPageMethod(options);
3618+
spyOn(capturedPage, 'eval').and.callThrough();
3619+
return capturedPage;
3620+
});
3621+
36003622
percy.loglevel('debug');
36013623

36023624
await percy.snapshot({
@@ -3610,7 +3632,7 @@ describe('Discovery', () => {
36103632
});
36113633
await percy.idle();
36123634

3613-
expect(page.eval).toHaveBeenCalledWith('await waitForSelector("body", 30000)');
3635+
expect(capturedPage.eval).toHaveBeenCalledWith('await waitForSelector("body", 30000)');
36143636
expect(logger.stderr).toEqual(jasmine.arrayContaining([
36153637
'[percy:core:discovery] Wait for selector: body',
36163638
'[percy:core:discovery] Wait for 100ms timeout'

0 commit comments

Comments
 (0)