diff --git a/src/aws.js b/src/aws.js new file mode 100644 index 0000000..7e865a0 --- /dev/null +++ b/src/aws.js @@ -0,0 +1,25 @@ +/* +Copyright 2023 Liquid Labs LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// credit to: https://stackoverflow.com/a/50484916/929494 +export const awsS3TABucketNameString = '(?!(^xn--|.+-s3alias$))^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$' +// AWS: Matches S3 Transfer Acceleration compatible S3 bucket name. Note `awsS3TABucketNameString` cannot be used for partial matches. +export const awsS3TABucketName = new RegExp(awsS3TABucketNameString) + +// credit to: https://stackoverflow.com/a/50484916/929494 +export const awsS3BucketNameString = '(?!(^((2(5[0-5]|[0-4][0-9])|[01]?[0-9]{1,2})\\.){3}(2(5[0-5]|[0-4][0-9])|[01]?[0-9]{1,2})$|^xn--|.+-s3alias$))^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$' +// AWS: Matcehs valid S3 bucket name. Note `awsS3BucketNameString` cannot be used for partial matches. +export const awsS3BucketName = new RegExp(awsS3BucketNameString) diff --git a/src/index.js b/src/index.js index 252a5cf..4576dfc 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +export * from './aws' export * from './contacts' export * from './css' export * from './ids' diff --git a/src/test/aws.test.js b/src/test/aws.test.js new file mode 100644 index 0000000..e3e5fda --- /dev/null +++ b/src/test/aws.test.js @@ -0,0 +1,27 @@ +/* +Copyright 2023 Liquid Labs LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { groupTest } from './lib/test-lib' +import * as regex from '../aws' +import { + goodAWSS3TABuckenNames, + badAWSS3TABuckenNames, + goodAWSS3BuckenNames, + badAWSS3BuckenNames +} from './data/aws-s3-bucket-names' + +groupTest(regex.awsS3TABucketName, goodAWSS3TABuckenNames, badAWSS3TABuckenNames) +groupTest(regex.awsS3BucketName, goodAWSS3BuckenNames, badAWSS3BuckenNames) diff --git a/src/test/data/aws-s3-bucket-names.js b/src/test/data/aws-s3-bucket-names.js new file mode 100644 index 0000000..53438c0 --- /dev/null +++ b/src/test/data/aws-s3-bucket-names.js @@ -0,0 +1,28 @@ +/* +Copyright 2023 Liquid Labs LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export const goodAWSS3TABuckenNames = ['foobar', 'foo-bar', 'a-very-long-bucket-name-less-than-63-characters'] + +export const badAWSS3BuckenNames = [ + 'ab', + '192.168.8.20', + 'foo_bar', + // 10 20 30 40 50 60 + '1234567890123456789012345678901234567890123456789012345678901234' +] + +export const badAWSS3TABuckenNames = badAWSS3BuckenNames.concat(['foo.bar']) +export const goodAWSS3BuckenNames = goodAWSS3TABuckenNames.concat(['foo.bar'])