Skip to content

Commit 2f1d874

Browse files
committed
fix: auth login failed in address mode. (#728)
1 parent 389f6b6 commit 2f1d874

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

common/nacos_server/nacos_server.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ func NewNacosServer(ctx context.Context, serverList []constant.ServerConfig, cli
9292
ns.initRefreshSrvIfNeed(ctx)
9393
}
9494

95-
_, err := securityLogin.Login()
95+
_, err := ns.securityLogin.Login()
9696

9797
if err != nil {
9898
logger.Errorf("login in err:%v", err)
9999
}
100100

101-
securityLogin.AutoRefresh(ctx)
101+
ns.securityLogin.AutoRefresh(ctx)
102102
return &ns, nil
103103
}
104104

@@ -344,6 +344,7 @@ func (server *NacosServer) refreshServerSrvIfNeed(urlString string, header map[s
344344
server.ServerSrcChangeSignal <- struct{}{}
345345
}
346346
server.lastSrvRefTime = util.CurrentMillis()
347+
server.securityLogin.UpdateServerList(servers)
347348
server.Unlock()
348349
}
349350

common/nacos_server/nacos_server_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,27 @@ func TestNacosServer_InjectSignForNamingHttp_WithoutServiceNameAndGroup(t *testi
156156
_, has := param["signature"]
157157
assert.True(t, has)
158158
}
159+
160+
func TestNacosServer_UpdateServerListForSecurityLogin(t *testing.T) {
161+
endpoint := "console.nacos.io:80"
162+
clientConfig := constant.ClientConfig{
163+
Username: "nacos",
164+
Password: "nacos",
165+
NamespaceId: "namespace_1",
166+
Endpoint: endpoint,
167+
EndpointContextPath: "nacos",
168+
ClusterName: "serverlist",
169+
AppendToStdout: true,
170+
}
171+
server, err := NewNacosServer(context.Background(),
172+
nil,
173+
clientConfig,
174+
&http_agent.HttpAgent{},
175+
1000,
176+
endpoint,
177+
nil)
178+
if err != nil {
179+
t.FailNow()
180+
}
181+
assert.Equal(t, server.GetServerList(), server.securityLogin.GetServerList())
182+
}

common/security/security_proxy.go

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func (ac *AuthClient) Login() (bool, error) {
112112
return false, throwable
113113
}
114114

115+
func (ac *AuthClient) UpdateServerList(serverList []constant.ServerConfig) {
116+
ac.serverCfgs = serverList
117+
}
118+
119+
func (ac *AuthClient) GetServerList() []constant.ServerConfig {
120+
return ac.serverCfgs
121+
}
122+
115123
func (ac *AuthClient) login(server constant.ServerConfig) (bool, error) {
116124
if ac.username != "" {
117125
contextPath := server.ContextPath

0 commit comments

Comments
 (0)