Browse code

F5: Cleanup mockF5.close() calls in tests

Comment newTestRouterWithState and newTestRouter.

Delete workaround for slow ECDHE performance now that that issue has been
resolved (per https://github.com/openshift/origin/issues/4417).

Close the mock F5 server when TestInitializeF5Plugin finishes.

Fix a potential nil pointer dereference in TestF5RouterPartition.

Fix a potential double-close in TestF5RouterPartition.

https://github.com/openshift/origin/issues/8908

Miciah Masters authored on 2016/05/19 01:08:29
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package f5
2 2
 
3 3
 import (
4
-	"crypto/tls"
5 4
 	"encoding/json"
6 5
 	"flag"
7 6
 	"fmt"
... ...
@@ -182,6 +181,10 @@ func newF5Routes(mockF5State mockF5State) *mux.Router {
182 182
 	return mockF5
183 183
 }
184 184
 
185
+// newTestRouterWithState creates a new F5 plugin with a mock F5 BIG-IP server
186
+// initialized from the given mock F5 state and returns pointers to the plugin
187
+// and mock server.  Note that these pointers will be nil if an error is
188
+// returned.
185 189
 func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin, *mockF5, error) {
186 190
 	routerLogLevel := util.Env("TEST_ROUTER_LOGLEVEL", "")
187 191
 	if routerLogLevel != "" {
... ...
@@ -190,18 +193,7 @@ func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin,
190 190
 
191 191
 	execCommand = mockExecCommand
192 192
 
193
-	server := httptest.NewUnstartedServer(newF5Routes(state))
194
-	// Work around performance issues with Golang's ECDHE implementation.
195
-	// See <https://github.com/openshift/origin/issues/4407>.
196
-	server.Config.TLSConfig = new(tls.Config)
197
-	server.Config.TLSConfig.CipherSuites = []uint16{
198
-		tls.TLS_RSA_WITH_RC4_128_SHA,
199
-		tls.TLS_RSA_WITH_AES_128_CBC_SHA,
200
-		tls.TLS_RSA_WITH_AES_256_CBC_SHA,
201
-		tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
202
-	}
203
-	server.TLS = server.Config.TLSConfig
204
-	server.StartTLS()
193
+	server := httptest.NewTLSServer(newF5Routes(state))
205 194
 
206 195
 	url, err := url.Parse(server.URL)
207 196
 	if err != nil {
... ...
@@ -230,6 +222,9 @@ func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin,
230 230
 	return router, mockF5, nil
231 231
 }
232 232
 
233
+// newTestRouter creates a new F5 plugin with a mock F5 BIG-IP server and
234
+// returns pointers to the plugin and mock server.  Note that these pointers
235
+// will be nil if an error is returned.
233 236
 func newTestRouter(partitionPath string) (*F5Plugin, *mockF5, error) {
234 237
 	pathKey := strings.Replace(partitionPath, "/", "~", -1)
235 238
 	state := mockF5State{
... ...
@@ -1264,6 +1259,7 @@ func TestInitializeF5Plugin(t *testing.T) {
1264 1264
 	if err != nil {
1265 1265
 		t.Fatalf("Failed to initialize test router: %v", err)
1266 1266
 	}
1267
+	defer mockF5.close()
1267 1268
 
1268 1269
 	// The policy for secure routes and the policy for insecure routes should
1269 1270
 	// exist.
... ...
@@ -1405,7 +1401,6 @@ func TestF5RouterPartition(t *testing.T) {
1405 1405
 
1406 1406
 	for _, tc := range testCases {
1407 1407
 		_, mockF5, err := newTestRouter(tc.partition)
1408
-		mockF5.close()
1409 1408
 		if err != nil {
1410 1409
 			t.Fatalf("Test case %q failed to initialize test router: %v", tc.name, err)
1411 1410
 		}
... ...
@@ -1415,7 +1410,7 @@ func TestF5RouterPartition(t *testing.T) {
1415 1415
 		if !ok {
1416 1416
 			t.Fatalf("Test case %q missing partition key %s", tc.name, name)
1417 1417
 		}
1418
-		defer mockF5.close()
1418
+		mockF5.close()
1419 1419
 	}
1420 1420
 }
1421 1421