Skip to content

Commit

Permalink
chore: remove validation of optional service properties
Browse files Browse the repository at this point in the history
Remove validation of optional service properties

Closes trustbloc#335

Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Aug 13, 2020
1 parent 2146e49 commit 4916b8a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
8 changes: 4 additions & 4 deletions pkg/dochandler/didvalidator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
31 changes: 1 addition & 30 deletions pkg/document/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/document/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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/"
}]
}`

0 comments on commit 4916b8a

Please sign in to comment.