1
1
package eks
2
2
3
3
import (
4
- "crypto/tls"
5
- "crypto/x509"
6
- "fmt"
7
- "net"
8
4
"net/http"
9
5
"net/http/httptest"
10
- "net/url"
11
6
"testing"
12
7
13
8
"github.com/aws/aws-sdk-go/aws"
@@ -53,7 +48,7 @@ func TestOIDCReconcile(t *testing.T) {
53
48
}, nil )
54
49
m .CreateOpenIDConnectProvider (& iam.CreateOpenIDConnectProviderInput {
55
50
ClientIDList : aws .StringSlice ([]string {"sts.amazonaws.com" }),
56
- ThumbprintList : aws .StringSlice ([]string {"c7a33e1de97f8bf5413ef9a833da98507c95416c " }),
51
+ ThumbprintList : aws .StringSlice ([]string {"15dbd260c7465ecca6de2c0b2181187f66ee0d1a " }),
57
52
Url : & url ,
58
53
}).Return (& iam.CreateOpenIDConnectProviderOutput {
59
54
OpenIDConnectProviderArn : aws .String ("arn::oidc" ),
@@ -87,7 +82,7 @@ func TestOIDCReconcile(t *testing.T) {
87
82
OpenIDConnectProviderArn : aws .String ("arn::oidc" ),
88
83
}).Return (& iam.GetOpenIDConnectProviderOutput {
89
84
ClientIDList : aws .StringSlice ([]string {"sts.amazonaws.com" }),
90
- ThumbprintList : aws .StringSlice ([]string {"c7a33e1de97f8bf5413ef9a833da98507c95416c " }),
85
+ ThumbprintList : aws .StringSlice ([]string {"15dbd260c7465ecca6de2c0b2181187f66ee0d1a " }),
91
86
Url : & url ,
92
87
}, nil )
93
88
},
@@ -106,8 +101,11 @@ func TestOIDCReconcile(t *testing.T) {
106
101
_ = ekscontrolplanev1 .AddToScheme (scheme )
107
102
_ = corev1 .AddToScheme (scheme )
108
103
109
- ts , url , err := testServer ()
110
- g .Expect (err ).To (Succeed ())
104
+ ts := httptest .NewTLSServer (http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) {
105
+ // Send response to be tested
106
+ rw .WriteHeader (http .StatusOK )
107
+ rw .Write ([]byte (`OK` ))
108
+ }))
111
109
defer ts .Close ()
112
110
113
111
controlPlane := & ekscontrolplanev1.AWSManagedControlPlane {
@@ -143,98 +141,19 @@ func TestOIDCReconcile(t *testing.T) {
143
141
})
144
142
145
143
iamMock := mock_iamauth .NewMockIAMAPI (mockControl )
146
- tc .expect (iamMock .EXPECT (), url . String () )
147
- s := NewService (scope )
144
+ tc .expect (iamMock .EXPECT (), ts . URL )
145
+ s := NewService (scope , WithIAMClient ( ts . Client ()) )
148
146
s .IAMClient = iamMock
149
147
150
- cluster := tc .cluster (url . String () )
151
- err = s .reconcileOIDCProvider (& cluster )
148
+ cluster := tc .cluster (ts . URL )
149
+ err : = s .reconcileOIDCProvider (& cluster )
152
150
// We reached the trusted policy reconcile which will fail because it tries to connect to the server.
153
151
// But at this point, we already know that the critical area has been covered.
154
- g .Expect (err ).To (MatchError (ContainSubstring ("dial tcp: lookup test-cluster-api.nodomain.example.com: no such host " )))
152
+ g .Expect (err ).To (MatchError (ContainSubstring ("dial tcp: lookup test-cluster-api.nodomain.example.com" )))
155
153
})
156
154
}
157
155
}
158
156
159
- func testServer () (* httptest.Server , * url.URL , error ) {
160
- rootCAs := x509 .NewCertPool ()
161
-
162
- cert , err := tls .X509KeyPair (serverCert , serverKey )
163
- if err != nil {
164
- return nil , nil , fmt .Errorf ("failed to init x509 cert/key pair: %w" , err )
165
- }
166
- tlsConfig := & tls.Config {
167
- Certificates : []tls.Certificate {cert },
168
- RootCAs : rootCAs ,
169
- MinVersion : tls .VersionTLS12 ,
170
- }
171
-
172
- tlsServer := httptest .NewUnstartedServer (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
173
- w .WriteHeader (http .StatusOK )
174
- w .Write ([]byte ("ok" ))
175
- }))
176
-
177
- tlsServer .TLS = tlsConfig
178
- tlsServer .StartTLS ()
179
-
180
- serverURL , err := url .Parse (tlsServer .URL )
181
- if err != nil {
182
- tlsServer .Close ()
183
- return nil , nil , fmt .Errorf ("failed to parse the testserver URL: %w" , err )
184
- }
185
- serverURL .Host = net .JoinHostPort ("localhost" , serverURL .Port ())
186
-
187
- return tlsServer , serverURL , nil
188
- }
189
-
190
- // generated with `mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1`.
191
- var serverCert = []byte (`-----BEGIN CERTIFICATE-----
192
- MIIC3DCCAcQCCQDKSKIAwGGsezANBgkqhkiG9w0BAQUFADAwMQswCQYDVQQGEwJV
193
- UzENMAsGA1UECAwEVXRhaDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIyMDkzMDA1
194
- MDk0NVoXDTMyMDkyNzA1MDk0NVowMDELMAkGA1UEBhMCVVMxDTALBgNVBAgMBFV0
195
- YWgxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
196
- AQoCggEBAJet5JFSOFRh4McYs/V7ZWE4NfGwOYrjwExocwuxf+3rZp2LsAHefN01
197
- rps8fDBk57PbolC5WAutGZBS06asT6/j7XGi1SSIr+C1Sr5X5lnrQWlqimYyVK+k
198
- cPqRkgEVVmYdgESIi0UV1ulEIqfeqgo49S/2u46lt1S/Cvb3dV9oX+aP/CBihPal
199
- z00QtqPdgM3ebG0K/V+JKF5VGkduHfCwIR710pbSvrscPhuQBW+FtGkVGgGsT53w
200
- +m+bpUo8w6FIqp6oQ1gqXIZTDWNtqF7RmuzgohSuo0xfuqkazWMKOsucKJirS0Z2
201
- 6wbFG1O/e/GrQ/T1Yp3u8dvSG0KPZy8CAwEAATANBgkqhkiG9w0BAQUFAAOCAQEA
202
- JJFduoko6CTlcgJo4bUJUb/nBDvGZ4e52YJlbsKnqT9bWCgEtaiekw08PBFwjIWK
203
- GXNVUHVhCyFk+hFwCx9TkFfpDNTeiv/xoRBi24Nl60x0kv9SfOyaPaeC3g9cN4HU
204
- JEg72P4A47Owj94RVkqZmwmRcZQ/fh8qTuvSmgoJaMfqXLRGFJbWyPUa3wYzHyjY
205
- CGzMRQTnwJ8Ky4xHoVClbcBTXXTm2tdmojzJP1hwt1zBraq/3tBRBYrKvV4Eqsg4
206
- j3OcbtBxfcVpm/tHlS1JkPznTryVNZhoxf/a4LXSwBGsAHTb14FfNbguuoyl0vZZ
207
- qE56RZINYB2h11pH/1sC0g==
208
- -----END CERTIFICATE-----` )
209
- var serverKey = []byte (`-----BEGIN PRIVATE KEY-----
210
- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXreSRUjhUYeDH
211
- GLP1e2VhODXxsDmK48BMaHMLsX/t62adi7AB3nzdNa6bPHwwZOez26JQuVgLrRmQ
212
- UtOmrE+v4+1xotUkiK/gtUq+V+ZZ60FpaopmMlSvpHD6kZIBFVZmHYBEiItFFdbp
213
- RCKn3qoKOPUv9ruOpbdUvwr293VfaF/mj/wgYoT2pc9NELaj3YDN3mxtCv1fiShe
214
- VRpHbh3wsCEe9dKW0r67HD4bkAVvhbRpFRoBrE+d8Ppvm6VKPMOhSKqeqENYKlyG
215
- Uw1jbahe0Zrs4KIUrqNMX7qpGs1jCjrLnCiYq0tGdusGxRtTv3vxq0P09WKd7vHb
216
- 0htCj2cvAgMBAAECggEADv66/P7i4Ly4axZvHBKx6BWVh6pDVg7EAQnGbd6DZjMC
217
- dwrLQLQNJhVbiK9HG8Wt/mL1PgPEx4q6X0FA+VZJnnrrC3PsnGsC8DUcCYtJE5Sl
218
- Z9WHjyjkpGSeYrcndwH0A65g8uWI1zCciX0Z6/ygVNhirPY4fpa1dCRa4iV+rgrN
219
- jyZ7+drI3yiiQYds1mF9qBlvDEvomoWlPQ74BMzjQs7BlgRTATwdIztRCiKNUK4G
220
- 4PvnNGjDVZsGUeSAaR/+FOE/mCElDE8QR+5eD9iLYUyO0aTXKoMKFZCJMjzqaUlW
221
- XjOE3d6jNzP4qM1vZVc0ozloXsRVuakJduyh/tmL6QKBgQDJ2gmOgTMfj1jKlIOo
222
- T2fa4iAW9PMMErn/x4wTgF+BItuwf8rCVAZYtzMt022CajwHODDpIAiQQZsOOCyE
223
- nd0poYH+IU0PVNvUJRcH7SYSvVlzD9nkM64BLnaX1Fnf4We83GmUhweVqUXTszDn
224
- U0bJcRAxM9kovABkkrHeDQr4mwKBgQDAXlBUtzfSslqsXXLEDfTqaW2u+Z3QaKfQ
225
- VI3z3D1GKmgKzr6Z+oaa6JboKLL9if757GK9xRLTnay775F9x2xlNzz+iq6lZSyb
226
- n1yUaLP1LXa6hmOunP5lo6KduSFP4kqreIHWWuoyKbrB3tEBMqr1Lp2ydL6kP/Dg
227
- 0Oz+rnuC/QKBgA55BrRkCSFbKtejnGkGAIFOM1TSDVcxRIrVaPLBApgEwtG95/DV
228
- C3ty70V64mA2c8VkvwUIGfUV7yMu3epIU2I3xVVOV/Mgd36XhjY4R8GSOAaq/UmC
229
- dxh4l2I9hJAr3j9JYnyWzfFqKKqML5Z2fx3UcH/Gouxrxm9voTc1ojK/AoGATPWu
230
- d6XxLFb0VZ7xKiRXRmy1V9o/W8By2rLpM5V54hdXFnPN5zZGIbVJokmeCjbqDjyW
231
- 6ErulECxeWKHt2VQJVIrEb6TzlGivgPMewdEb6Mnq8nWGWZvlGQZy7Xj8NyceOs2
232
- Lnai2Ty+nY8x2KPXp01mA54XIwj9qkOLfPx7J1UCgYA7zJ3auVehaKIphx/gLpzL
233
- mWdrQHrrvlS04jy6IfQfKcRo9lGFXgWiPSQomWKbvA2WJik0EP9CQO28oAYKZWP/
234
- jhckhSOsc4+cMSi5b3OqlNiFiL164COTy8I5OLLG1nhIqWAUVYOjQDLlWRCG69xS
235
- VSuwY/kUqjW6vpvWP5j1kg==
236
- -----END PRIVATE KEY-----` )
237
-
238
157
var kubeConfig = []byte (`apiVersion: v1
239
158
clusters:
240
159
- cluster:
0 commit comments