diff --git a/agent/proxycfg/manager_test.go b/agent/proxycfg/manager_test.go index 658bad43ba..eab91afb3c 100644 --- a/agent/proxycfg/manager_test.go +++ b/agent/proxycfg/manager_test.go @@ -557,3 +557,48 @@ func testGenCacheKey(req cache.Request) string { info := req.CacheInfo() return path.Join(info.Key, info.Datacenter) } + +func TestManager_SyncState_DefaultToken(t *testing.T) { + types := NewTestCacheTypes(t) + c := TestCacheWithTypes(t, types) + logger := testutil.Logger(t) + tokens := new(token.Store) + tokens.UpdateUserToken("default-token", token.TokenSourceConfig) + + state := local.NewState(local.Config{}, logger, tokens) + state.TriggerSyncChanges = func() {} + + m, err := NewManager(ManagerConfig{ + Cache: c, + Health: &health.Client{Cache: c, CacheName: cachetype.HealthServicesName}, + State: state, + // TODO: Tokens: tokens, + Source: &structs.QuerySource{Datacenter: "dc1"}, + Logger: logger, + }) + require.NoError(t, err) + defer m.Close() + + srv := &structs.NodeService{ + Kind: structs.ServiceKindConnectProxy, + ID: "web-sidecar-proxy", + Service: "web-sidecar-proxy", + Port: 9999, + Meta: map[string]string{}, + Proxy: structs.ConnectProxyConfig{ + DestinationServiceID: "web", + DestinationServiceName: "web", + LocalServiceAddress: "127.0.0.1", + LocalServicePort: 8080, + Config: map[string]interface{}{ + "foo": "bar", + }, + }, + } + + err = state.AddServiceWithChecks(srv, nil, "") + require.NoError(t, err) + m.syncState() + + require.Equal(t, "default-token", m.proxies[srv.CompoundServiceID()].serviceInstance.token) +}