-
Notifications
You must be signed in to change notification settings - Fork 54
Adds automatic domain validation and allow-listing #2092
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| // Validate domain for auto-allowlisting feature | ||
| // Only validates domains that returned 200 status | ||
| async function validateDomainForAllowlist(network, hostname, url, statusCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too long function - try to break it down - maybe move to a helper
packages/core/src/network.js
Outdated
| // Non-200 responses should not be validated | ||
| if ( | ||
| statusCode !== 200 || | ||
| autoConfiguredHosts.has(hostname) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should this return null ?
packages/core/src/network.js
Outdated
| if (result?.error) { | ||
| newErrorHosts.add(hostname); | ||
| network.log.debug(`Domain validation: ${hostname} validated as BLOCKED - ${result?.reason}`, network.meta); | ||
| processedDomains.set(hostname, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it set true and false ? why null - using null as falsy is not a good pattern
packages/core/src/network.js
Outdated
| shouldCapture = true; | ||
| log.debug(`- Capturing auto-validated domain: ${hostname}`, meta); | ||
| } else { | ||
| const domainResult = await validateDomainForAllowlist(network, hostname, url, response.status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can get triggered in parallel for same domain across multiple requests in current page or across discovery pages, performance isnt handled for that
| captureSrcset?: boolean; | ||
| devicePixelRatio?: number; | ||
| devicePixelRatio?: number; | ||
| autoConfigureAllowedHostnames?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type tests update pending
This pull request introduces a new auto domain allow-listing feature to the Percy client and core, enabling automatic validation and management of external domains accessed during snapshot capture. This helps streamline asset handling by validating domains against project configuration and an external service, and by persisting new discoveries for future builds. The implementation includes changes to both the core logic and the client API, as well as comprehensive tests for the new functionality.
The most important changes are:
Core logic for auto domain allow-listing:
Percyclass, including sets for pre-approved, pre-blocked, session-allowed, and session-blocked domains, as well as statistics tracking. (packages/core/src/percy.js)packages/core/src/network.js) [1] [2]packages/core/src/network.js) [1] [2]Project domain configuration persistence:
Percyclass to load project domain config at startup and save newly discovered allowed/blocked domains at shutdown, integrating with the Percy client API. (packages/core/src/percy.js) [1] [2] [3]Percy client API enhancements:
patchmethod and new methodsupdateProjectDomainConfigandvalidateDomainto thePercyClientclass to support updating project domain configuration and validating domains via an external service. (packages/client/src/client.js) [1] [2]Test coverage for new features:
updateProjectDomainConfigandvalidateDomainmethods, including positive and negative scenarios and request payload validation. (packages/client/test/client.test.js,packages/client/test/helpers.js) [1] [2]Wiring and context propagation:
packages/core/src/discovery.js,packages/core/src/network.js) [1] [2]