From 7d30459417201fff86945f1b7e055f8b96024147 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 23 Apr 2020 10:32:17 +0200 Subject: [PATCH] test: empty auth update channel in tests --- pkg/pmapi/clientmanager_test.go | 12 ++++++++++++ pkg/pmapi/contacts_test.go | 4 ++-- pkg/pmapi/dialer_with_proxy_test.go | 14 +++++++------- pkg/pmapi/proxy_test.go | 10 +++++----- pkg/pmapi/server_test.go | 4 ++-- 5 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 pkg/pmapi/clientmanager_test.go diff --git a/pkg/pmapi/clientmanager_test.go b/pkg/pmapi/clientmanager_test.go new file mode 100644 index 00000000..2bf60373 --- /dev/null +++ b/pkg/pmapi/clientmanager_test.go @@ -0,0 +1,12 @@ +package pmapi + +func newTestClientManager(cfg *ClientConfig) *ClientManager { + cm := NewClientManager(cfg) + + go func() { + for range cm.authUpdates { + } + }() + + return cm +} diff --git a/pkg/pmapi/contacts_test.go b/pkg/pmapi/contacts_test.go index 524a400b..887103f1 100644 --- a/pkg/pmapi/contacts_test.go +++ b/pkg/pmapi/contacts_test.go @@ -654,7 +654,7 @@ var testCardsCleartext = []Card{ } func TestClient_Encrypt(t *testing.T) { - c := newTestClient(NewClientManager(testClientConfig)) + c := newTestClient(newTestClientManager(testClientConfig)) c.kr = testPrivateKeyRing cardEncrypted, err := c.EncryptAndSignCards(testCardsCleartext) @@ -668,7 +668,7 @@ func TestClient_Encrypt(t *testing.T) { } func TestClient_Decrypt(t *testing.T) { - c := newTestClient(NewClientManager(testClientConfig)) + c := newTestClient(newTestClientManager(testClientConfig)) c.kr = testPrivateKeyRing cardCleartext, err := c.DecryptAndVerifyCards(testCardsEncrypted) diff --git a/pkg/pmapi/dialer_with_proxy_test.go b/pkg/pmapi/dialer_with_proxy_test.go index 693c8c03..53f526e3 100644 --- a/pkg/pmapi/dialer_with_proxy_test.go +++ b/pkg/pmapi/dialer_with_proxy_test.go @@ -39,7 +39,7 @@ func setTestDialerWithPinning(cm *ClientManager) (*int, *DialerWithPinning) { } func TestTLSPinValid(t *testing.T) { - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) cm.host = liveAPI rootScheme = "https" called, _ := setTestDialerWithPinning(cm) @@ -52,7 +52,7 @@ func TestTLSPinValid(t *testing.T) { } func TestTLSPinBackup(t *testing.T) { - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) cm.host = liveAPI called, p := setTestDialerWithPinning(cm) p.report.KnownPins[1] = p.report.KnownPins[0] @@ -67,7 +67,7 @@ func TestTLSPinBackup(t *testing.T) { } func _TestTLSPinNoMatch(t *testing.T) { // nolint[unused] - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) cm.host = liveAPI called, p := setTestDialerWithPinning(cm) @@ -89,7 +89,7 @@ func _TestTLSPinNoMatch(t *testing.T) { // nolint[unused] } func _TestTLSPinInvalid(t *testing.T) { // nolint[unused] - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { writeJSONResponsefromFile(t, w, "/auth/info/post_response.json", 0) @@ -112,14 +112,14 @@ func _TestTLSPinInvalid(t *testing.T) { // nolint[unused] } func _TestTLSSignedCertWrongPublicKey(t *testing.T) { // nolint[unused] - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) _, dialer := setTestDialerWithPinning(cm) _, err := dialer.dialAndCheckFingerprints("tcp", "rsa4096.badssl.com:443") Assert(t, err != nil, "expected dial to fail because of wrong public key: ", err.Error()) } func _TestTLSSignedCertTrustedPublicKey(t *testing.T) { // nolint[unused] - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) _, dialer := setTestDialerWithPinning(cm) dialer.report.KnownPins = append(dialer.report.KnownPins, `pin-sha256="W8/42Z0ffufwnHIOSndT+eVzBJSC0E8uTIC8O6mEliQ="`) _, err := dialer.dialAndCheckFingerprints("tcp", "rsa4096.badssl.com:443") @@ -127,7 +127,7 @@ func _TestTLSSignedCertTrustedPublicKey(t *testing.T) { // nolint[unused] } func _TestTLSSelfSignedCertTrustedPublicKey(t *testing.T) { // nolint[unused] - cm := NewClientManager(testLiveConfig) + cm := newTestClientManager(testLiveConfig) _, dialer := setTestDialerWithPinning(cm) dialer.report.KnownPins = append(dialer.report.KnownPins, `pin-sha256="9SLklscvzMYj8f+52lp5ze/hY0CFHyLSPQzSpYYIBm8="`) _, err := dialer.dialAndCheckFingerprints("tcp", "self-signed.badssl.com:443") diff --git a/pkg/pmapi/proxy_test.go b/pkg/pmapi/proxy_test.go index e090be97..a8e709af 100644 --- a/pkg/pmapi/proxy_test.go +++ b/pkg/pmapi/proxy_test.go @@ -122,7 +122,7 @@ func TestProxyProvider_UseProxy(t *testing.T) { blockAPI() defer unblockAPI() - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) proxy := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer proxy.Close() @@ -141,7 +141,7 @@ func TestProxyProvider_UseProxy_MultipleTimes(t *testing.T) { blockAPI() defer unblockAPI() - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) proxy1 := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer proxy1.Close() @@ -182,7 +182,7 @@ func TestProxyProvider_UseProxy_RevertAfterTime(t *testing.T) { blockAPI() defer unblockAPI() - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) proxy := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer proxy.Close() @@ -205,7 +205,7 @@ func TestProxyProvider_UseProxy_RevertIfProxyStopsWorkingAndOriginalAPIIsReachab blockAPI() defer unblockAPI() - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) proxy := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer proxy.Close() @@ -235,7 +235,7 @@ func TestProxyProvider_UseProxy_FindSecondAlternativeIfFirstFailsAndAPIIsStillBl blockAPI() defer unblockAPI() - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) proxy1 := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer proxy1.Close() diff --git a/pkg/pmapi/server_test.go b/pkg/pmapi/server_test.go index 15b321c2..9ac6e419 100644 --- a/pkg/pmapi/server_test.go +++ b/pkg/pmapi/server_test.go @@ -79,7 +79,7 @@ func newTestServer(h http.Handler) (*httptest.Server, *client) { panic(err) } - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) cm.host = serverURL.Host cm.scheme = serverURL.Scheme @@ -122,7 +122,7 @@ func newTestServerCallbacks(tb testing.TB, callbacks ...func(testing.TB, http.Re } } - cm := NewClientManager(testClientConfig) + cm := newTestClientManager(testClientConfig) cm.host = serverURL.Host cm.scheme = serverURL.Scheme