mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-29 05:06:11 +01:00
relax validation
This commit is contained in:
parent
26612aa75b
commit
dadfb29ae9
|
@ -8,7 +8,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
|
||||||
"code.gitea.io/gitea/modules/validation"
|
"code.gitea.io/gitea/modules/validation"
|
||||||
|
|
||||||
ap "github.com/go-ap/activitypub"
|
ap "github.com/go-ap/activitypub"
|
||||||
|
@ -71,10 +70,7 @@ type PersonID struct {
|
||||||
|
|
||||||
// Factory function for PersonID. Created struct is asserted to be valid
|
// Factory function for PersonID. Created struct is asserted to be valid
|
||||||
func NewPersonID(uri, source string) (PersonID, error) {
|
func NewPersonID(uri, source string) (PersonID, error) {
|
||||||
// TODO: remove after test
|
|
||||||
//if !validation.IsValidExternalURL(uri) {
|
|
||||||
// return PersonId{}, fmt.Errorf("uri %s is not a valid external url", uri)
|
|
||||||
//}
|
|
||||||
result, err := newActorID(uri)
|
result, err := newActorID(uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PersonID{}, err
|
return PersonID{}, err
|
||||||
|
@ -125,18 +121,7 @@ type RepositoryID struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory function for RepositoryID. Created struct is asserted to be valid.
|
// Factory function for RepositoryID. Created struct is asserted to be valid.
|
||||||
// ToDo: Add a NewForeignRepositoryID
|
func NewRepositoryID(uri, source string) (RepositoryID, error) {
|
||||||
func NewRepositoryID(uri, source string, isFollowing bool) (RepositoryID, error) {
|
|
||||||
|
|
||||||
if isFollowing {
|
|
||||||
if !validation.IsValidURL(uri) {
|
|
||||||
return RepositoryID{}, fmt.Errorf("uri %s is not a valid url on their host: %s", uri, setting.AppURL+"api")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !validation.IsAPIURL(uri) {
|
|
||||||
return RepositoryID{}, fmt.Errorf("uri %s is not a valid repo url on our host: %s", uri, setting.AppURL+"api")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := newActorID(uri)
|
result, err := newActorID(uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,7 +129,7 @@ func NewRepositoryID(uri, source string, isFollowing bool) (RepositoryID, error)
|
||||||
}
|
}
|
||||||
result.Source = source
|
result.Source = source
|
||||||
|
|
||||||
// validate Person specific path
|
// validate Person specific
|
||||||
repoID := RepositoryID{result}
|
repoID := RepositoryID{result}
|
||||||
if valid, err := validation.IsValid(repoID); !valid {
|
if valid, err := validation.IsValid(repoID); !valid {
|
||||||
return RepositoryID{}, err
|
return RepositoryID{}, err
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestNewRepositoryId(t *testing.T) {
|
||||||
expected.Host = "localhost"
|
expected.Host = "localhost"
|
||||||
expected.Port = "3000"
|
expected.Port = "3000"
|
||||||
expected.UnvalidatedInput = "http://localhost:3000/api/activitypub/repository-id/1"
|
expected.UnvalidatedInput = "http://localhost:3000/api/activitypub/repository-id/1"
|
||||||
sut, _ := NewRepositoryID("http://localhost:3000/api/activitypub/repository-id/1", "forgejo", false)
|
sut, _ := NewRepositoryID("http://localhost:3000/api/activitypub/repository-id/1", "forgejo")
|
||||||
if sut != expected {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ func ProcessLikeActivity(ctx context.Context, form any, repositoryID int64) (int
|
||||||
log.Info("Actor accepted:%v", actorID)
|
log.Info("Actor accepted:%v", actorID)
|
||||||
|
|
||||||
// parse objectID (repository)
|
// parse objectID (repository)
|
||||||
objectID, err := fm.NewRepositoryID(activity.Object.GetID().String(), string(forgefed.ForgejoSourceType), false)
|
objectID, err := fm.NewRepositoryID(activity.Object.GetID().String(), string(forgefed.ForgejoSourceType))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusNotAcceptable, "Invalid objectId", err
|
return http.StatusNotAcceptable, "Invalid objectId", err
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ func StoreFollowingRepoList(ctx context.Context, localRepoID int64, followingRep
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, "Wrong FederationHost", err
|
return http.StatusInternalServerError, "Wrong FederationHost", err
|
||||||
}
|
}
|
||||||
followingRepoID, err := fm.NewRepositoryID(uri, string(federationHost.NodeInfo.SoftwareName), true)
|
followingRepoID, err := fm.NewRepositoryID(uri, string(federationHost.NodeInfo.SoftwareName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusNotAcceptable, "Invalid federated repo", err
|
return http.StatusNotAcceptable, "Invalid federated repo", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue