Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/aws.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 27 additions & 0 deletions src/test/aws.test.js
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions src/test/data/aws-s3-bucket-names.js
Original file line number Diff line number Diff line change
@@ -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'])