Skip to content

Commit

Permalink
Fix conn refused related tests for win env
Browse files Browse the repository at this point in the history
  • Loading branch information
vasayxtx committed Oct 4, 2024
1 parent 0ecc08d commit da48ec5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions jwks/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/acronis/go-appkit/log"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestClient_GetRSAPublicKey(t *testing.T) {
var openIDCfgErr *jwks.GetOpenIDConfigurationError
require.True(t, errors.As(err, &openIDCfgErr))
require.Equal(t, issuerConfigServer.URL+jwks.OpenIDConfigurationPath, openIDCfgErr.URL)
require.ErrorContains(t, openIDCfgErr.Inner, "connection refused")
requireLocalhostConnRefusedError(t, openIDCfgErr.Inner)
require.Nil(t, pubKey)
})

Expand Down Expand Up @@ -99,7 +100,7 @@ func TestClient_GetRSAPublicKey(t *testing.T) {
require.True(t, errors.As(err, &jwksErr))
require.Equal(t, jwksServer.URL, jwksErr.URL)
require.Equal(t, issuerConfigServer.URL+jwks.OpenIDConfigurationPath, jwksErr.OpenIDConfigurationURL)
require.ErrorContains(t, jwksErr.Inner, "connection refused")
requireLocalhostConnRefusedError(t, jwksErr.Inner)
require.Nil(t, pubKey)
})

Expand Down Expand Up @@ -158,3 +159,10 @@ func TestClient_GetRSAPublicKey(t *testing.T) {
require.Nil(t, pubKey)
})
}

func requireLocalhostConnRefusedError(t *testing.T, err error) {
t.Helper()
require.True(t,
strings.Contains(err.Error(), "dial tcp 127.0.0.1:") && strings.Contains(err.Error(), "refused"),
`Error %q doesn't contain "dial tcp 127.0.0.1 ... refused"`, err)
}

0 comments on commit da48ec5

Please sign in to comment.