Skip to content

Commit

Permalink
refactor(#503): regex replaced in s3 uri validation to fix codacy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Juega committed Jun 24, 2022
1 parent cddd823 commit c95cfbb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/domain-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ class DomainConfig {
if (isEdgeType && hasMutualTls) {
throw new Error(`${this.endpointType} APIs do not support mutual TLS, remove tlsTruststoreUri or change to a regional API.`);
}
if (config.tlsTruststoreUri) {
this.validateS3Uri(config.tlsTruststoreUri);
}
this.tlsTruststoreUri = config.tlsTruststoreUri;
this.tlsTruststoreVersion = config.tlsTruststoreVersion;
const isS3UriRegExp = /^s3:\/\/[\w-_.]+(\/[\w-_.]+)+$/;
if (this.tlsTruststoreUri && !isS3UriRegExp.test(this.tlsTruststoreUri)) {
throw new Error(`${this.tlsTruststoreUri} is not a valid s3 uri, try something like s3://bucket-name/key-name.`);
}

const securityPolicyDefault = config.securityPolicy || Globals.tlsVersions.tls_1_2;
const tlsVersionToUse = Globals.tlsVersions[securityPolicyDefault.toLowerCase()];
Expand Down Expand Up @@ -120,6 +119,14 @@ class DomainConfig {
healthCheckId: config.route53Params?.healthCheckId
}
}

private validateS3Uri(uri: string): void {
const { protocol, pathname } = new URL(uri);

if (protocol !== "s3:" && !pathname.substring(1).includes("/")) {
throw new Error(`${uri} is not a valid s3 uri, try something like s3://bucket-name/key-name.`);
}
}
}

export = DomainConfig;

0 comments on commit c95cfbb

Please sign in to comment.