Skip to content

Commit

Permalink
fix configure for discovery service (#3460)
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst authored Oct 8, 2024
1 parent a738631 commit b5c5c2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 13 additions & 6 deletions discovery/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion discovery/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion policy/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b5c5c2d

Please sign in to comment.