diff --git a/models/forgefed/federationhost.go b/models/forgefed/federationhost.go index 271013fa1e..aeaaabf1f8 100644 --- a/models/forgefed/federationhost.go +++ b/models/forgefed/federationhost.go @@ -27,7 +27,7 @@ type FederationHost struct { } // Factory function for FederationHost. Created struct is asserted to be valid. -func NewFederationHost(hostFqdn string, nodeInfo NodeInfo, port string, schema string) (FederationHost, error) { +func NewFederationHost(hostFqdn string, nodeInfo NodeInfo, port, schema string) (FederationHost, error) { result := FederationHost{ HostFqdn: strings.ToLower(hostFqdn), NodeInfo: nodeInfo, diff --git a/models/forgejo_migrations/v29.go b/models/forgejo_migrations/v29.go index 89214c2762..c64fea64d6 100644 --- a/models/forgejo_migrations/v29.go +++ b/models/forgejo_migrations/v29.go @@ -10,6 +10,7 @@ import ( "forgejo.org/models/migrations/base" "forgejo.org/modules/forgefed" "forgejo.org/modules/timeutil" + "xorm.io/xorm" ) diff --git a/modules/forgefed/actor.go b/modules/forgefed/actor.go index b89a7579a0..a35cbf9292 100644 --- a/modules/forgefed/actor.go +++ b/modules/forgefed/actor.go @@ -46,19 +46,18 @@ func (id ActorID) AsURI() string { } else { result = fmt.Sprintf("%s://%s:%s/%s/%s", id.HostSchema, id.Host, id.HostPort, id.Path, id.ID) } - return result + return result } func (id ActorID) Validate() []string { var result []string result = append(result, validation.ValidateNotEmpty(id.ID, "userId")...) - result = append(result, validation.ValidateNotEmpty(id.HostSchema, "schema")...) + result = append(result, validation.ValidateNotEmpty(id.HostSchema, "HostSchema")...) result = append(result, validation.ValidateNotEmpty(id.Path, "path")...) result = append(result, validation.ValidateNotEmpty(id.Host, "host")...) result = append(result, validation.ValidateNotEmpty(id.HostPort, "HostPort")...) result = append(result, validation.ValidateNotEmpty(id.UnvalidatedInput, "unvalidatedInput")...) - //add or if id.UnvalidatedInput != id.AsURI() { result = append(result, fmt.Sprintf("not all input was parsed, \nUnvalidated Input:%q \nParsed URI: %q", id.UnvalidatedInput, id.AsURI())) } @@ -106,7 +105,6 @@ func (id PersonID) Validate() []string { result := id.ActorID.Validate() result = append(result, validation.ValidateNotEmpty(id.Source, "source")...) result = append(result, validation.ValidateOneOf(id.Source, []any{"forgejo", "gitea"}, "Source")...) - result = append(result, validation.ValidateOneOf(id.HostSchema, []any{"https", "http", "HTTPS", "HTTP"}, "Source")...) switch id.Source { case "forgejo", "gitea": @@ -114,16 +112,7 @@ func (id PersonID) Validate() []string { result = append(result, fmt.Sprintf("path: %q has to be a person specific api path", id.Path)) } } - /* - switch id.HostSchema { - case "HTTPS", "HTTP": - if strings.ToLower(id.HostSchema) == "https" { - result = append(result, fmt.Sprintf("-%s", strings.ToLower(id.HostSchema))) - } else if strings.ToLower(id.HostSchema) == "http" { - result = append(result, fmt.Sprintf("-%s", strings.ToLower(id.HostSchema))) - } - } - */ + return result } @@ -144,7 +133,6 @@ func NewRepositoryID(uri, source string) (RepositoryID, error) { // validate Person specific repoID := RepositoryID{result} if valid, err := validation.IsValid(repoID); !valid { - return RepositoryID{}, err } @@ -185,7 +173,6 @@ func removeEmptyStrings(ls []string) []string { func newActorID(uri string) (ActorID, error) { validatedURI, err := url.ParseRequestURI(uri) - if err != nil { return ActorID{}, err } @@ -216,7 +203,7 @@ func newActorID(uri string) (ActorID, error) { } result.HostPort = validatedURI.Port() - result.UnvalidatedInput = uri + result.UnvalidatedInput = fmt.Sprintf("%s://%s:%s/%s/%s", result.HostSchema, result.Host, result.HostPort, result.Path, result.ID) return result, nil } diff --git a/modules/forgefed/actor_test.go b/modules/forgefed/actor_test.go index 68c2ea9317..053d4c067c 100644 --- a/modules/forgefed/actor_test.go +++ b/modules/forgefed/actor_test.go @@ -29,7 +29,7 @@ func TestNewPersonId(t *testing.T) { if sut != expected { t.Errorf("expected: %v\n but was: %v\n", expected, sut) } - + expected = PersonID{} expected.ID = "1" expected.Source = "forgejo" @@ -39,12 +39,12 @@ func TestNewPersonId(t *testing.T) { expected.HostPort = "443" expected.IsPortSupplemented = false expected.UnvalidatedInput = "https://an.other.host:443/api/v1/activitypub/user-id/1" - + sut, _ = NewPersonID("https://an.other.host:443/api/v1/activitypub/user-id/1", "forgejo") if sut != expected { t.Errorf("expected: %v\n but was: %v\n", expected, sut) } - + expected = PersonID{} expected.ID = "1" expected.Source = "forgejo" @@ -57,24 +57,23 @@ func TestNewPersonId(t *testing.T) { sut, _ = NewPersonID("http://an.other.host:80/api/v1/activitypub/user-id/1", "forgejo") if sut != expected { - t.Errorf("expected: %v\n but was: %v\n", expected, sut) + t.Errorf("expected: %v\n but was: %v\n", expected, sut) } -/* + expected = PersonID{} expected.ID = "1" expected.Source = "forgejo" - expected.HostSchema = "HTTPS" + expected.HostSchema = "https" expected.Path = "api/v1/activitypub/user-id" expected.Host = "an.other.host" expected.HostPort = "443" expected.IsPortSupplemented = false expected.UnvalidatedInput = "https://an.other.host:443/api/v1/activitypub/user-id/1" - sut, _ = NewPersonID("https://an.other.host:443/api/v1/activitypub/user-id/1", "forgejo") + sut, _ = NewPersonID("HTTPS://an.other.host:443/api/v1/activitypub/user-id/1", "forgejo") if sut != expected { t.Errorf("expected: %v\n but was: %v\n", expected, sut) } -*/ } func TestNewRepositoryId(t *testing.T) {