Skip to content

Commit 68b6aa8

Browse files
fix: re-initialize auth provider on endpoint change and logout (#698)
1 parent 0ba9106 commit 68b6aa8

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

application/config/config.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func (c *CliSettings) DefaultBinaryInstallPath() string {
153153
}
154154

155155
type Config struct {
156-
scrubbingDict frameworkLogging.ScrubbingDict
157156
scrubbingWriter zerolog.LevelWriter
158157
cliSettings *CliSettings
159158
configFile string
@@ -240,7 +239,6 @@ func NewFromExtension(engine workflow.Engine) *Config {
240239
func newConfig(engine workflow.Engine) *Config {
241240
c := &Config{}
242241
c.folderAdditionalParameters = make(map[string][]string)
243-
c.scrubbingDict = frameworkLogging.ScrubbingDict{}
244242
c.logger = getNewScrubbingLogger(c)
245243
c.cliSettings = NewCliSettings(c)
246244
c.automaticAuthentication = true
@@ -305,7 +303,7 @@ func initWorkFlowEngine(c *Config) {
305303
func getNewScrubbingLogger(c *Config) *zerolog.Logger {
306304
c.m.Lock()
307305
defer c.m.Unlock()
308-
c.scrubbingWriter = frameworkLogging.NewScrubbingWriter(logging.New(nil), c.scrubbingDict)
306+
c.scrubbingWriter = frameworkLogging.NewScrubbingWriter(logging.New(nil), make(frameworkLogging.ScrubbingDict))
309307
writer := c.getConsoleWriter(c.scrubbingWriter)
310308
logger := zerolog.New(writer).With().Timestamp().Str("separator", "-").Str("method", "").Str("ext", "").Logger()
311309
return &logger
@@ -598,7 +596,7 @@ func (c *Config) ConfigureLogging(server types.Server) {
598596
defer c.m.Unlock()
599597

600598
// overwrite a potential already existing writer, so we have the latest settings
601-
c.scrubbingWriter = frameworkLogging.NewScrubbingWriter(zerolog.MultiLevelWriter(writers...), c.scrubbingDict)
599+
c.scrubbingWriter = frameworkLogging.NewScrubbingWriter(zerolog.MultiLevelWriter(writers...), make(frameworkLogging.ScrubbingDict))
602600
writer := c.getConsoleWriter(c.scrubbingWriter)
603601
logger := zerolog.New(writer).With().Timestamp().Str("separator", "-").Str("method", "").Str("ext", "").Logger().Level(logLevel)
604602
c.logger = &logger

application/server/configuration.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ package server
1818

1919
import (
2020
"context"
21-
"github.com/snyk/snyk-ls/internal/product"
2221
"os"
2322
"reflect"
2423
"strconv"
2524
"strings"
2625

26+
"github.com/snyk/snyk-ls/internal/product"
27+
2728
"github.com/creachadair/jrpc2"
2829
"github.com/creachadair/jrpc2/handler"
2930

@@ -259,7 +260,9 @@ func updateApiEndpoints(c *config.Config, settings types.Settings, initializatio
259260
endpointsUpdated := c.UpdateApiEndpoints(snykApiUrl)
260261

261262
if endpointsUpdated && !initialization {
262-
di.AuthenticationService().Logout(context.Background())
263+
authService := di.AuthenticationService()
264+
authService.Logout(context.Background())
265+
authService.ConfigureProviders(c)
263266
workspace.Get().Clear()
264267
}
265268

application/server/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func Test_initialize_handlesUntrustedFoldersWhenAutomaticAuthentication(t *testi
653653
}
654654

655655
assert.Nil(t, err)
656-
assert.Eventually(t, func() bool { return checkTrustMessageRequest(jsonRPCRecorder) }, time.Second, time.Millisecond)
656+
assert.Eventually(t, func() bool { return checkTrustMessageRequest(jsonRPCRecorder) }, time.Second*5, time.Millisecond)
657657
}
658658

659659
func Test_initialize_handlesUntrustedFoldersWhenAuthenticated(t *testing.T) {

application/server/trust_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package server
1818

1919
import (
2020
"context"
21-
"github.com/snyk/snyk-ls/domain/snyk/scanner"
2221
"os"
2322
"testing"
2423
"time"
2524

25+
"github.com/snyk/snyk-ls/domain/snyk/scanner"
26+
2627
"github.com/creachadair/jrpc2"
2728
"github.com/stretchr/testify/assert"
2829

@@ -148,7 +149,6 @@ func Test_MultipleFoldersInRootDirWithOnlyOneTrusted(t *testing.T) {
148149

149150
c := config.CurrentConfig()
150151
c.SetTrustedFolderFeatureEnabled(true)
151-
c.SetTrustedFolderFeatureEnabled(true)
152152

153153
fakeAuthenticationProvider := di.AuthenticationService().Provider().(*authentication.FakeAuthenticationProvider)
154154
fakeAuthenticationProvider.IsAuthenticated = true
@@ -180,7 +180,7 @@ func Test_MultipleFoldersInRootDirWithOnlyOneTrusted(t *testing.T) {
180180
}
181181

182182
assert.NoError(t, err)
183-
assert.Eventually(t, func() bool { return checkTrustMessageRequest(jsonRPCRecorder) }, time.Second, time.Millisecond)
183+
assert.Eventually(t, func() bool { return checkTrustMessageRequest(jsonRPCRecorder) }, time.Second*10, time.Millisecond)
184184
}
185185

186186
func checkTrustMessageRequest(jsonRPCRecorder *testutil.JsonRPCRecorder) bool {

infrastructure/authentication/auth_service_impl.go

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (a *AuthenticationServiceImpl) Logout(ctx context.Context) {
108108
a.errorReporter.CaptureError(err)
109109
}
110110
a.UpdateCredentials("", true)
111+
a.ConfigureProviders(a.c)
111112
}
112113

113114
// IsAuthenticated returns true if the token is verified

0 commit comments

Comments
 (0)