github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/utils/aws/fuzz_test.go (about) 1 /* 2 Copyright 2022 Gravitational, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package aws 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 ) 24 25 func FuzzParseRDSEndpoint(f *testing.F) { 26 f.Add("") 27 f.Add(":123") 28 f.Add("foo:123") 29 f.Add("foo" + AWSCNEndpointSuffix) 30 f.Add("a.cluster-custom-b.c." + RDSServiceName + AWSEndpointSuffix) 31 f.Add("a.cluster-b.c." + RDSServiceName + AWSEndpointSuffix) 32 f.Add("a.proxy-b.c." + RDSServiceName + AWSEndpointSuffix) 33 f.Add("a.b.c." + RDSServiceName + AWSEndpointSuffix) 34 f.Add("a.endpoint.proxy-c.d." + RDSServiceName + AWSEndpointSuffix) 35 f.Add("a.cluster-custom-b." + RDSServiceName + ".c" + AWSCNEndpointSuffix) 36 f.Add("a.cluster-b." + RDSServiceName + ".c" + AWSCNEndpointSuffix) 37 f.Add("a.proxy-b." + RDSServiceName + ".c" + AWSCNEndpointSuffix) 38 f.Add("a.b." + RDSServiceName + ".c" + AWSCNEndpointSuffix) 39 f.Add("a.endpoint.proxy-c." + RDSServiceName + ".d" + AWSCNEndpointSuffix) 40 41 f.Fuzz(func(t *testing.T, endpoint string) { 42 require.NotPanics(t, func() { 43 _, _ = ParseRDSEndpoint(endpoint) 44 }) 45 }) 46 } 47 48 func FuzzParseRedshiftEndpoint(f *testing.F) { 49 f.Add("") 50 f.Add(":123") 51 f.Add("foo:123") 52 f.Add("foo" + AWSCNEndpointSuffix) 53 f.Add("redshift-cluster-1.abcdefghijklmnop.us-east-1.redshift.amazonaws.com") 54 f.Add("redshift-cluster-2.abcdefghijklmnop.redshift.cn-north-1.amazonaws.com.cn") 55 56 f.Fuzz(func(t *testing.T, endpoint string) { 57 require.NotPanics(t, func() { 58 _, _, _ = ParseRedshiftEndpoint(endpoint) 59 }) 60 }) 61 } 62 63 func FuzzParseElastiCacheEndpoint(f *testing.F) { 64 f.Add("") 65 f.Add(":123") 66 f.Add("foo:123") 67 f.Add("foo" + AWSEndpointSuffix) 68 f.Add("foo" + AWSCNEndpointSuffix) 69 f.Add("clustercfg.b.c.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 70 f.Add("clustercfg.my-redis-shards.xxxxxx.use1.cache.foo:6379") 71 f.Add("a.b.clustercfg.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 72 f.Add("my-redis-shards.xxxxxx.clustercfg.use1.cache.foo:6379") 73 f.Add("a.b.0001.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 74 f.Add("my-redis-cluster-001.xxxxxx.0001.use0.cache.foo:6379") 75 f.Add("my-redis-shards-0001-001.xxxxxx.0001.use0.cache.foo:6379") 76 f.Add("master.b.c.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 77 f.Add("master.my-redis-cluster.xxxxxx.use1.cache.foo:6379") 78 f.Add("replica.b.c.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 79 f.Add("replica.my-redis-cluster.xxxxxx.use1.cache.foo:6379") 80 f.Add("a.b.c.usnw1." + ElastiCacheServiceName + AWSEndpointSuffix) 81 f.Add("a.b.c.usne1." + ElastiCacheServiceName + AWSEndpointSuffix) 82 f.Add("a.b.c.usse1." + ElastiCacheServiceName + AWSEndpointSuffix) 83 f.Add("a.b.c.ussw1." + ElastiCacheServiceName + AWSEndpointSuffix) 84 f.Add("my-redis-cluster.xxxxxx.ng.0001.use1.cache.foo:6379") 85 f.Add("my-redis-cluster-ro.xxxxxx.ng.0001.use1.cache.foo:6379") 86 87 f.Fuzz(func(t *testing.T, endpoint string) { 88 require.NotPanics(t, func() { 89 _, _ = ParseElastiCacheEndpoint(endpoint) 90 }) 91 }) 92 } 93 94 func FuzzParseDynamoDBEndpoint(f *testing.F) { 95 f.Add("") 96 f.Add(":123") 97 f.Add("foo:123") 98 f.Add(DynamoDBServiceName + ".foo" + AWSEndpointSuffix) 99 f.Add(DynamoDBServiceName + ".foo" + AWSEndpointSuffix + ":1234") 100 f.Add(DynamoDBFipsServiceName + ".foo" + AWSCNEndpointSuffix) 101 102 f.Fuzz(func(t *testing.T, endpoint string) { 103 require.NotPanics(t, func() { 104 _, _ = ParseDynamoDBEndpoint(endpoint) 105 }) 106 }) 107 } 108 109 func FuzzParseOpensearchEndpoint(f *testing.F) { 110 f.Add("") 111 f.Add(":123") 112 f.Add("foo:123") 113 f.Add("a.b." + OpenSearchServiceName + AWSEndpointSuffix) 114 f.Add("a.b." + OpenSearchServiceName + AWSEndpointSuffix + ":1234") 115 f.Add("a.b." + OpenSearchServiceName + AWSCNEndpointSuffix) 116 117 f.Fuzz(func(t *testing.T, endpoint string) { 118 require.NotPanics(t, func() { 119 _, _ = ParseOpensearchEndpoint(endpoint) 120 }) 121 }) 122 }