test: empty auth update channel in tests

This commit is contained in:
James Houlahan 2020-04-23 10:32:17 +02:00 committed by Michal Horejsek
parent 8f15041d8f
commit 7d30459417
5 changed files with 28 additions and 16 deletions

View File

@ -0,0 +1,12 @@
package pmapi
func newTestClientManager(cfg *ClientConfig) *ClientManager {
cm := NewClientManager(cfg)
go func() {
for range cm.authUpdates {
}
}()
return cm
}

View File

@ -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)

View File

@ -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")

View File

@ -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()

View File

@ -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