Skip to content

Commit

Permalink
[TRUST-1439] changes to domain matching
Browse files Browse the repository at this point in the history
  • Loading branch information
saksham-postman committed Sep 30, 2024
1 parent 7a73a79 commit e741e2d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/runner/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,16 @@ module.exports = {

// convert the domains to UrlMatchPattern
variable._.domainPatterns = new UrlMatchPatternList(null, domains.map((domain) => {
const url = new Url(domain);
const url = new Url(domain),

// Get the host without port
hostWithoutPort = url.getRemote().replace(/:\d+$/, ''),

// Create a pattern that matches with or without port
hostPattern = `${hostWithoutPort}(:\\d+)?`;

// @note URL path is ignored
return `${url.protocol || 'https'}://${url.getRemote()}/*`;
return `${url.protocol || 'https'}://${hostPattern}/*`;
}));
});

Expand All @@ -219,16 +225,15 @@ module.exports = {
return scope.values;
}

const urlWithoutPort = urlString.replace(/:\d+/, ''),
variables = scope.values.filter((variable) => {
const domainPatterns = variable && variable._ && variable._.domainPatterns;
const variables = scope.values.filter((variable) => {
const domainPatterns = variable && variable._ && variable._.domainPatterns;

if (!domainPatterns) {
return true;
}
if (!domainPatterns) {
return true;
}

return domainPatterns.test(urlWithoutPort);
});
return domainPatterns.test(urlString);
});

return new VariableList(null, variables.map((variable) => {
return variable.toJSON(); // clone the variable
Expand Down

0 comments on commit e741e2d

Please sign in to comment.