From d9c3c0a4421d9baf8a9a51485a627bb7c8274379 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Thu, 16 Nov 2023 14:42:17 +0100 Subject: [PATCH] Ensure the operator token is set during load Signed-off-by: R.I.Pienaar --- providers/nsc/nsc.go | 2 +- tests/operator_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/providers/nsc/nsc.go b/providers/nsc/nsc.go index 6d81b7f..a477486 100644 --- a/providers/nsc/nsc.go +++ b/providers/nsc/nsc.go @@ -83,7 +83,7 @@ func (a *NscProvider) loadOperator(si store.IStore) (*authb.OperatorData, error) if err != nil { return nil, err } - od := &authb.OperatorData{BaseData: authb.BaseData{EntityName: si.GetName(), Loaded: oc.IssuedAt}, Claim: oc} + od := &authb.OperatorData{BaseData: authb.BaseData{EntityName: si.GetName(), Loaded: oc.IssuedAt, Token: string(token)}, Claim: oc} ks := store.NewKeyStore(od.EntityName) kp, err := ks.GetKeyPair(oc.Issuer) if err != nil { diff --git a/tests/operator_test.go b/tests/operator_test.go index ccb8a9b..c323175 100644 --- a/tests/operator_test.go +++ b/tests/operator_test.go @@ -1,6 +1,8 @@ package tests import ( + "fmt" + "github.com/nats-io/jwt/v2" "github.com/nats-io/nkeys" "github.com/stretchr/testify/require" @@ -212,6 +214,27 @@ func (suite *ProviderSuite) Test_OperatorSystemAccount() { require.NoError(t, o.Accounts().Delete("SYS")) } +func (suite *ProviderSuite) Test_MemResolver() { + t := suite.T() + auth, err := authb.NewAuth(suite.Provider) + require.NoError(t, err) + + _, err = auth.Operators().Add("O") + require.NoError(t, err) + + require.NoError(t, auth.Commit()) + + auth, err = authb.NewAuth(suite.Provider) + require.NoError(t, err) + + o := auth.Operators().Get("O") + + out, err := o.MemResolver() + require.NoError(t, err) + + require.Contains(t, string(out), fmt.Sprintf("operator: %v", o.)) +} + func (suite *ProviderSuite) Test_OperatorImport() { t := suite.T() auth, err := authb.NewAuth(suite.Provider)