Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed Oct 21, 2024
1 parent 95e5709 commit 92f79e8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 75 deletions.
3 changes: 1 addition & 2 deletions crypto/storage/external/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/crypto/storage/spi"
"github.com/nuts-foundation/nuts-node/crypto/util"
safeHttp "github.com/nuts-foundation/nuts-node/http/client"
)

// StorageType is the name of this storage type, used in health check reports and configuration.
Expand Down Expand Up @@ -83,7 +82,7 @@ func NewAPIClient(config Config) (spi.Storage, error) {
if _, err := url.ParseRequestURI(config.Address); err != nil {
return nil, err
}
client, _ := NewClientWithResponses(config.Address, WithHTTPClient(safeHttp.New(config.Timeout)))
client, _ := NewClientWithResponses(config.Address, WithHTTPClient(&http.Client{Timeout: config.Timeout}))
return &APIClient{httpClient: client}, nil
}

Expand Down
73 changes: 0 additions & 73 deletions vcr/test/openid4vci_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ import (
"encoding/json"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/network/log"
"github.com/nuts-foundation/nuts-node/vcr/issuer"
"github.com/nuts-foundation/nuts-node/vcr/openid4vci"
"github.com/nuts-foundation/nuts-node/vdr/didsubject"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"github.com/stretchr/testify/assert"
"io"
"net/http"
"net/http/httptrace"
"net/url"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -80,76 +77,6 @@ func TestOpenID4VCIHappyFlow(t *testing.T) {
}, 5*time.Second, "credential not retrieved by holder")
}

func TestOpenID4VCIConnectionReuse(t *testing.T) {
// Our safe http Transport has MaxConnsPerHost = 5
// for 2 http.Transport instance (one for issuer, one for wallet),
// so we expect max 10 connections in total.
const maxExpectedConnCount = 10

ctx := audit.TestContext()
_, baseURL, system := node.StartServer(t)
vcrService := system.FindEngineByName("vcr").(vcr.VCR)

issuerDID := registerDID(t, system)
registerBaseURL(t, baseURL, system, issuerDID)
holderDID := registerDID(t, system)
registerBaseURL(t, baseURL, system, holderDID)

credential := testCredential()
credential.Issuer = issuerDID.URI()
credential.ID, _ = ssi.ParseURI(issuerDID.URI().String() + "#1")
credential.CredentialSubject = append(credential.CredentialSubject, map[string]interface{}{
"id": holderDID.URI().String(),
"purposeOfUse": "test",
})

newConns := map[string]int{}
mux := sync.Mutex{}
openid4vci.HttpClientTrace = &httptrace.ClientTrace{
ConnectStart: func(network, addr string) {
log.Logger().Infof("Conn: %s/%s", network, addr)
mux.Lock()
defer mux.Unlock()
newConns[network+"/"+addr]++
},
}

const numCreds = 12
errChan := make(chan error, numCreds)
wg := sync.WaitGroup{}
for i := 0; i < numCreds; i++ {
wg.Add(1)
go func() {
defer wg.Done()
_, err := vcrService.Issuer().Issue(ctx, credential, issuer.CredentialOptions{
Publish: true,
Public: false,
})
if err != nil {
errChan <- err
return
}
}()
}

wg.Wait()
// Drain errs channel, non-blocking
close(errChan)
var errs []string
for {
err := <-errChan
if err == nil {
break

}
errs = append(errs, err.Error())
}
assert.Empty(t, errs, "error issuing credential")
for host, v := range newConns {
assert.LessOrEqualf(t, v, maxExpectedConnCount, "number of created HTTP connections should be at most %d for host %s", 5, host)
}
}

// TestOpenID4VCIDisabled tests the issuer won't try to issue over OpenID4VCI when it's disabled.
func TestOpenID4VCIDisabled(t *testing.T) {
_, baseURL, system := node.StartServer(t, func(_, _ string) {
Expand Down

0 comments on commit 92f79e8

Please sign in to comment.