Skip to content

Commit a7775b7

Browse files
Miciahsmarterclayton
authored andcommitted
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 #4417). Close the mock F5 server when TestInitializeF5Plugin finishes. Fix a potential nil pointer dereference in TestF5RouterPartition. Fix a potential double-close in TestF5RouterPartition. #8908
1 parent 061e6d4 commit a7775b7

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

pkg/router/f5/plugin_test.go

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package f5
22

33
import (
4-
"crypto/tls"
54
"encoding/json"
65
"flag"
76
"fmt"
@@ -182,6 +181,10 @@ func newF5Routes(mockF5State mockF5State) *mux.Router {
182181
return mockF5
183182
}
184183

184+
// newTestRouterWithState creates a new F5 plugin with a mock F5 BIG-IP server
185+
// initialized from the given mock F5 state and returns pointers to the plugin
186+
// and mock server. Note that these pointers will be nil if an error is
187+
// returned.
185188
func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin, *mockF5, error) {
186189
routerLogLevel := util.Env("TEST_ROUTER_LOGLEVEL", "")
187190
if routerLogLevel != "" {
@@ -190,18 +193,7 @@ func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin,
190193

191194
execCommand = mockExecCommand
192195

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()
196+
server := httptest.NewTLSServer(newF5Routes(state))
205197

206198
url, err := url.Parse(server.URL)
207199
if err != nil {
@@ -230,6 +222,9 @@ func newTestRouterWithState(state mockF5State, partitionPath string) (*F5Plugin,
230222
return router, mockF5, nil
231223
}
232224

225+
// newTestRouter creates a new F5 plugin with a mock F5 BIG-IP server and
226+
// returns pointers to the plugin and mock server. Note that these pointers
227+
// will be nil if an error is returned.
233228
func newTestRouter(partitionPath string) (*F5Plugin, *mockF5, error) {
234229
pathKey := strings.Replace(partitionPath, "/", "~", -1)
235230
state := mockF5State{
@@ -1264,6 +1259,7 @@ func TestInitializeF5Plugin(t *testing.T) {
12641259
if err != nil {
12651260
t.Fatalf("Failed to initialize test router: %v", err)
12661261
}
1262+
defer mockF5.close()
12671263

12681264
// The policy for secure routes and the policy for insecure routes should
12691265
// exist.
@@ -1405,7 +1401,6 @@ func TestF5RouterPartition(t *testing.T) {
14051401

14061402
for _, tc := range testCases {
14071403
_, mockF5, err := newTestRouter(tc.partition)
1408-
mockF5.close()
14091404
if err != nil {
14101405
t.Fatalf("Test case %q failed to initialize test router: %v", tc.name, err)
14111406
}
@@ -1415,7 +1410,7 @@ func TestF5RouterPartition(t *testing.T) {
14151410
if !ok {
14161411
t.Fatalf("Test case %q missing partition key %s", tc.name, name)
14171412
}
1418-
defer mockF5.close()
1413+
mockF5.close()
14191414
}
14201415
}
14211416

0 commit comments

Comments
 (0)