From d205c50a4395e648a67e5c067b3cc671d4386e1b Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 22 Nov 2023 16:08:14 +0100 Subject: [PATCH] Implement generic validation on ActorID --- models/activitypub/actor.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/models/activitypub/actor.go b/models/activitypub/actor.go index e0712fa1d7..e46befc68c 100644 --- a/models/activitypub/actor.go +++ b/models/activitypub/actor.go @@ -7,6 +7,8 @@ import ( ) type Validatable interface { + validate_is_not_nil() error + validate_is_not_empty() error Validate() error } @@ -18,15 +20,24 @@ type ActorID struct { port string // optional } +func (a ActorID) validate_is_not_empty(str string, field string) error { + + if str != "" { + return fmt.Errorf("field %v was empty", field) + } + + return nil +} + // TODO: Align validation-api to example from dda-devops-build func (a ActorID) Validate() error { - if a.schema == "" { - return fmt.Errorf("the actor ID was not valid: Invalid Schema") + if err := a.validate_is_not_empty(a.schema, "schema"); err != nil { + return err } - if a.host == "" { - return fmt.Errorf("the actor ID was not valid: Invalid Host") + if err := a.validate_is_not_empty(a.host, "host"); err != nil { + return err } if !strings.Contains(a.path, "api/v1/activitypub/user-id") {