core/ui: fix cycle in profile data (#5168)

This commit is contained in:
Caleb Doxsey 2024-07-09 17:05:12 -06:00 committed by GitHub
parent 968e3358a3
commit fd086bd06b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 5 deletions

View file

@ -59,11 +59,7 @@ func (data UserInfoData) profileJSON() map[string]any {
}
m := map[string]any{}
claims := make(map[string]any)
for k, v := range data.Profile.GetClaims().AsMap() {
claims[k] = v
}
m["claims"] = m
m["claims"] = data.Profile.GetClaims().AsMap()
return m
}

View file

@ -0,0 +1,37 @@
package handlers_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/types/known/structpb"
"github.com/pomerium/pomerium/internal/handlers"
"github.com/pomerium/pomerium/pkg/grpc/identity"
)
func TestUserInfoData(t *testing.T) {
t.Parallel()
claims, _ := structpb.NewStruct(map[string]any{
"TEST": "VALUE",
})
data := handlers.UserInfoData{Profile: &identity.Profile{Claims: claims}}
m := data.ToJSON()
bs, err := json.Marshal(m)
assert.NoError(t, err)
assert.JSONEq(t, `{
"csrfToken": "",
"isEnterprise": false,
"isImpersonated": false,
"profile": {
"claims": {"TEST":"VALUE"}
},
"session": null,
"user": null,
"webAuthnCreationOptions": null,
"webAuthnRequestOptions": null,
"webAuthnUrl": ""
}`, string(bs))
}