storage: ignore removed fields when deserializing the data (#3772)

This commit is contained in:
backport-actions-token[bot] 2022-11-29 17:26:51 -05:00 committed by GitHub
parent 9413123c0f
commit ebee7c7920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 9 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/pomerium/pomerium/internal/testutil"
"github.com/pomerium/pomerium/pkg/grpc/registry"
"github.com/pomerium/pomerium/pkg/protoutil"
)
type mockRegistryWatchServer struct {
@ -112,3 +113,19 @@ func TestRegistry(t *testing.T) {
return nil
}))
}
func TestUnmarshalJSONUnknownFields(t *testing.T) {
any, err := protoutil.UnmarshalAnyJSON([]byte(`
{
"@type": "type.googleapis.com/registry.Service",
"kind": "AUTHENTICATE",
"endpoint": "endpoint",
"unknown_field": true
}
`))
require.NoError(t, err)
var val registry.Service
require.NoError(t, any.UnmarshalTo(&val))
assert.Equal(t, registry.ServiceKind_AUTHENTICATE, val.Kind)
assert.Equal(t, "endpoint", val.Endpoint)
}