From 4916b8a362ceec5d59f60c83fc0ea9f4baee8985 Mon Sep 17 00:00:00 2001 From: Sandra Vrtikapa Date: Thu, 13 Aug 2020 13:58:33 -0400 Subject: [PATCH] chore: remove validation of optional service properties Remove validation of optional service properties Closes #335 Signed-off-by: Sandra Vrtikapa --- pkg/dochandler/didvalidator/validator.go | 8 +++--- pkg/document/validator.go | 31 +----------------------- pkg/document/validator_test.go | 17 ------------- 3 files changed, 5 insertions(+), 51 deletions(-) diff --git a/pkg/dochandler/didvalidator/validator.go b/pkg/dochandler/didvalidator/validator.go index 60672346..bca40920 100644 --- a/pkg/dochandler/didvalidator/validator.go +++ b/pkg/dochandler/didvalidator/validator.go @@ -144,10 +144,10 @@ func processServices(internal document.DIDDocument, resolutionResult *document.R externalService[document.TypeProperty] = sv.Type() externalService[document.ServiceEndpointProperty] = sv.Endpoint() - for _, prop := range document.GetOptionalServiceProperties() { - value, ok := sv[prop] - if ok { - externalService[prop] = value + for key, value := range sv { + _, ok := externalService[key] + if !ok { + externalService[key] = value } } diff --git a/pkg/document/validator.go b/pkg/document/validator.go index d9f65fc7..ee543091 100644 --- a/pkg/document/validator.go +++ b/pkg/document/validator.go @@ -103,31 +103,6 @@ var allowedKeyTypes = map[string]existenceMap{ invocation: allowedKeyTypesVerification, } -const ( - recipientKeys = "recipientKeys" - routingKeys = "routingKeys" - priority = "priority" -) - -// GetOptionalServiceProperties returns allowed optional properties -// Note that id, type and service endpoint are required properties -func GetOptionalServiceProperties() []string { - return []string{recipientKeys, routingKeys, priority} -} - -func validateServiceProperty(property string) error { - required := []string{IDProperty, TypeProperty, EndpointProperty} - optional := GetOptionalServiceProperties() - allowed := append(required, optional...) - for _, prop := range allowed { - if property == prop { - return nil - } - } - - return fmt.Errorf("property '%s' is not allowed for service", property) -} - // ValidatePublicKeys validates public keys func ValidatePublicKeys(pubKeys []PublicKey) error { ids := make(map[string]string) @@ -221,11 +196,7 @@ func validateService(service Service) error { return err } - for key := range service { - if err := validateServiceProperty(key); err != nil { - return err - } - } + // TODO: validate against configured allowed properties (issue #373) return nil } diff --git a/pkg/document/validator_test.go b/pkg/document/validator_test.go index 076739b7..f1cc88d1 100644 --- a/pkg/document/validator_test.go +++ b/pkg/document/validator_test.go @@ -175,14 +175,6 @@ func TestValidateServices(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "service endpoint is not valid URI") }) - t.Run("success - service property not allowed", func(t *testing.T) { - doc, err := DidDocumentFromBytes([]byte(serviceDocPropertyNotAllowed)) - require.NoError(t, err) - - err = ValidateServices(doc.Services()) - require.Error(t, err) - require.Contains(t, err.Error(), "property 'test' is not allowed for service") - }) t.Run("success - didcomm service", func(t *testing.T) { doc, err := DIDDocumentFromReader(reader(t, "testdata/doc.json")) require.NoError(t, err) @@ -664,12 +656,3 @@ const serviceDocOptionalProperty = `{ "endpoint": "https://example.com/vc/" }] }` - -const serviceDocPropertyNotAllowed = `{ - "service": [{ - "id": "vcs", - "test": "value", - "type": "VerifiableCredentialService", - "endpoint": "https://example.com/vc/" - }] -}`