From b5c5c2dafe72f51912c0c838318027fc5eef5ebf Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Tue, 8 Oct 2024 11:02:22 +0200 Subject: [PATCH] fix configure for discovery service (#3460) --- discovery/module.go | 19 +++++++++++++------ discovery/module_test.go | 11 ++++++++++- policy/local.go | 1 - 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/discovery/module.go b/discovery/module.go index aec286b93..c39cc75d8 100644 --- a/discovery/module.go +++ b/discovery/module.go @@ -97,6 +97,19 @@ type Module struct { } func (m *Module) Configure(serverConfig core.ServerConfig) error { + var err error + m.publicURL, err = serverConfig.ServerURL() + if err != nil { + return err + } + + m.httpClient = client.New(serverConfig.Strictmode, serverConfig.HTTPClient.Timeout, nil) + + return m.loadDefinitions() + +} + +func (m *Module) loadDefinitions() error { if m.config.Definitions.Directory == "" { return nil } @@ -110,11 +123,6 @@ func (m *Module) Configure(serverConfig core.ServerConfig) error { return fmt.Errorf("failed to load discovery defintions: %w", err) } - m.publicURL, err = serverConfig.ServerURL() - if err != nil { - return err - } - m.allDefinitions, err = loadDefinitions(m.config.Definitions.Directory) if err != nil { return err @@ -131,7 +139,6 @@ func (m *Module) Configure(serverConfig core.ServerConfig) error { } m.serverDefinitions = serverDefinitions } - m.httpClient = client.New(serverConfig.Strictmode, serverConfig.HTTPClient.Timeout, nil) return nil } diff --git a/discovery/module_test.go b/discovery/module_test.go index 1005bbb8e..4e781ef78 100644 --- a/discovery/module_test.go +++ b/discovery/module_test.go @@ -405,6 +405,15 @@ func TestModule_Configure(t *testing.T) { _, err := loadDefinitions(config.Definitions.Directory) assert.ErrorContains(t, err, "unable to read definitions directory 'test/non_existent'") }) + t.Run("missing definitions directory", func(t *testing.T) { + config := Config{} + m := &Module{config: config} + err := m.Configure(serverConfig) + + require.NoError(t, err) + assert.NotNil(t, m.publicURL) + assert.NotNil(t, m.httpClient) + }) } func TestModule_Search(t *testing.T) { @@ -513,7 +522,7 @@ func TestModule_ActivateServiceForSubject(t *testing.T) { subject := make([]credential.DiscoveryRegistrationCredentialSubject, 0) _ = credentials[1].UnmarshalCredentialSubject(&subject) assert.Equal(t, "value", subject[0]["test"]) - assert.Equal(t, "https://example.com/oauth2/alice", subject[0]["authServerURL"]) + assert.Equal(t, "https://nuts.nl/oauth2/alice", subject[0]["authServerURL"]) return &vpAlice, nil }) testContext.subjectManager.EXPECT().ListDIDs(gomock.Any(), aliceSubject).Return([]did.DID{aliceDID}, nil) diff --git a/policy/local.go b/policy/local.go index eb18c7399..81719eb7d 100644 --- a/policy/local.go +++ b/policy/local.go @@ -51,7 +51,6 @@ func (b *LocalPDP) Name() string { } func (b *LocalPDP) Configure(_ core.ServerConfig) error { - // check if directory exists if b.config.Directory != "" { _, err := os.Stat(b.config.Directory) if err != nil {