mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 03:06:10 +01:00
fixed tests
part1, one test still failing
This commit is contained in:
parent
d624ebb712
commit
1ad7bdf983
|
@ -110,7 +110,7 @@ func Test_StarUnmarshalJSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAcivityValidation(t *testing.T) {
|
||||
func TestActivityValidation(t *testing.T) {
|
||||
sut := new(ForgeLike)
|
||||
sut.UnmarshalJSON([]byte(`{"type":"Like",
|
||||
"actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||
|
@ -123,16 +123,16 @@ func TestAcivityValidation(t *testing.T) {
|
|||
sut.UnmarshalJSON([]byte(`{"actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||
"object":"https://codeberg.org/api/activitypub/repository-id/1",
|
||||
"startTime": "2014-12-31T23:00:00-08:00"}`))
|
||||
if sut.Validate()[0] != "Field type may not be empty" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
if sut.Validate()[0] != "Field type should not be empty" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate()[0])
|
||||
}
|
||||
|
||||
sut.UnmarshalJSON([]byte(`{"type":"bad-type",
|
||||
"actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||
"object":"https://codeberg.org/api/activitypub/repository-id/1",
|
||||
"startTime": "2014-12-31T23:00:00-08:00"}`))
|
||||
if sut.Validate()[0] != "Value bad-type is not contained in allowed values [[Like]]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
if sut.Validate()[0] != "Value bad-type is not contained in allowed values [Like]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate()[0])
|
||||
}
|
||||
|
||||
sut.UnmarshalJSON([]byte(`{"type":"Like",
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestActorIdValidation(t *testing.T) {
|
|||
sut.Host = "an.other.host"
|
||||
sut.Port = ""
|
||||
sut.UnvalidatedInput = "https://an.other.host/api/v1/activitypub/user-id/"
|
||||
if sut.Validate()[0] != "Field userId may not be empty" {
|
||||
if sut.Validate()[0] != "Field userId should not be empty" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ func TestActorIdValidation(t *testing.T) {
|
|||
sut.Host = "an.other.host"
|
||||
sut.Port = ""
|
||||
sut.UnvalidatedInput = "https://an.other.host/api/v1/activitypub/user-id/1?illegal=action"
|
||||
if sut.Validate()[0] != "not all input: \"https://an.other.host/api/v1/activitypub/user-id/1?illegal=action\" was parsed: \"https://an.other.host/api/v1/activitypub/user-id/1\"" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
if sut.Validate()[0] != "not all input was parsed, \nUnvalidated Input:\"https://an.other.host/api/v1/activitypub/user-id/1?illegal=action\" \nParsed URI: \"https://an.other.host/api/v1/activitypub/user-id/1\"" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate()[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,8 +104,8 @@ func TestPersonIdValidation(t *testing.T) {
|
|||
sut.Host = "an.other.host"
|
||||
sut.Port = ""
|
||||
sut.UnvalidatedInput = "https://an.other.host/api/v1/activitypub/user-id/1"
|
||||
if sut.Validate()[0] != "Value forgejox is not contained in allowed values [[forgejo gitea]]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate())
|
||||
if sut.Validate()[0] != "Value forgejox is not contained in allowed values [forgejo gitea]" {
|
||||
t.Errorf("validation error expected but was: %v\n", sut.Validate()[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ func Test_NodeInfoWellKnownValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
sut = NodeInfoWellKnown{Href: "./federated-repo.prod.meissa.de/api/v1/nodeinfo"}
|
||||
if _, err := validation.IsValid(sut); err.Error() != "Href has to be absolute\nValue is not contained in allowed values [[http https]]" {
|
||||
if _, err := validation.IsValid(sut); err.Error() != "Href has to be absolute\nValue is not contained in allowed values [http https]" {
|
||||
t.Errorf("validation error expected but was: %v\n", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -217,3 +217,12 @@ func TestComposeSSHCloneURL(t *testing.T) {
|
|||
setting.SSH.Port = 123
|
||||
assert.Equal(t, "ssh://git@[::1]:123/user/repo.git", repo_model.ComposeSSHCloneURL("user", "repo"))
|
||||
}
|
||||
|
||||
func TestAPAPIURL(t *testing.T) {
|
||||
repo := repo_model.Repository{ID: 1}
|
||||
url := repo.APAPIURL()
|
||||
expected := "https://try.gitea.io/api/v1/activitypub/repository-id/1"
|
||||
if url != expected {
|
||||
t.Errorf("unexpected APAPIURL, expected: %q, actual: %q", expected, url)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/forgefed"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/activitypub"
|
||||
|
||||
//"code.gitea.io/gitea/modules/activitypub"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
@ -94,10 +95,10 @@ func sendLikeActivities(ctx context.Context, doer user_model.User, repoID int64)
|
|||
return err
|
||||
}
|
||||
|
||||
apclient, err := activitypub.NewClient(ctx, &doer, doer.APAPIURL())
|
||||
/*apclient, err := activitypub.NewClient(ctx, &doer, doer.APAPIURL())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
|
||||
for _, federatedRepo := range federatedRepos {
|
||||
target := federatedRepo.Uri + "/inbox/" // A like goes to the inbox of the federated repo
|
||||
|
@ -107,16 +108,16 @@ func sendLikeActivities(ctx context.Context, doer user_model.User, repoID int64)
|
|||
return err
|
||||
}
|
||||
log.Info("Like Activity: %v", likeActivity)
|
||||
json, err := likeActivity.MarshalJSON()
|
||||
/*json, err := likeActivity.MarshalJSON()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}*/
|
||||
|
||||
// TODO: decouple loading & creating activities from sending them - use two loops.
|
||||
// TODO: set timeouts for outgoing request in oder to mitigate DOS by slow lories
|
||||
// TODO: Check if we need to respect rate limits
|
||||
// ToDo: Change this to the standalone table of FederatedRepos
|
||||
apclient.Post([]byte(json), target)
|
||||
//apclient.Post([]byte(json), target)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -303,7 +303,7 @@ func (u *User) HTMLURL() string {
|
|||
|
||||
// APAPIURL returns the IRI to the api endpoint of the user
|
||||
func (u *User) APAPIURL() string {
|
||||
return setting.AppURL + url.PathEscape("api/v1/activitypub/user-id/") + url.PathEscape(string(u.ID))
|
||||
return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID)))
|
||||
}
|
||||
|
||||
// OrganisationLink returns the organization sub page link.
|
||||
|
|
|
@ -60,6 +60,15 @@ func TestCanCreateOrganization(t *testing.T) {
|
|||
assert.False(t, user.CanCreateOrganization())
|
||||
}
|
||||
|
||||
func TestAPAPIURL(t *testing.T) {
|
||||
user := user_model.User{ID: 1}
|
||||
url := user.APAPIURL()
|
||||
expected := "https://try.gitea.io/api/v1/activitypub/user-id/1"
|
||||
if url != expected {
|
||||
t.Errorf("unexpected APAPIURL, expected: %q, actual: %q", expected, url)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchUsers(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testSuccess := func(opts *user_model.SearchUserOptions, expectedUserOrOrgIDs []int64) {
|
||||
|
|
|
@ -82,7 +82,7 @@ func LikeActivity(ctx context.Context, form any, repositoryID int64) (int, strin
|
|||
// execute the activity if the repo was not stared already
|
||||
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
|
||||
if !alreadyStared {
|
||||
err = repo.StarRepo(ctx, user, repositoryID, true)
|
||||
err = repo.StarRepo(ctx, *user, repositoryID, true)
|
||||
if err != nil {
|
||||
return http.StatusNotAcceptable, "Error staring", err
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func ValidateOneOf(value any, allowed []any) []string {
|
|||
return []string{}
|
||||
}
|
||||
}
|
||||
return []string{fmt.Sprintf("Value %v is not contained in allowed values [%v]", value, allowed)}
|
||||
return []string{fmt.Sprintf("Value %v is not contained in allowed values %v", value, allowed)}
|
||||
}
|
||||
|
||||
func ValidateSuffix(str, suffix string) bool {
|
||||
|
|
|
@ -157,7 +157,7 @@ func Star(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/notFound"
|
||||
|
||||
// TODO: why is this *context.APIContext passed, where a context.Context is expected?
|
||||
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository.ID, true)
|
||||
err := repo_model.StarRepo(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
|
@ -188,7 +188,7 @@ func Unstar(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
err := repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err := repo_model.StarRepo(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
|
|
|
@ -316,9 +316,9 @@ func Action(ctx *context.Context) {
|
|||
case "unwatch":
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
case "star":
|
||||
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err = repo_model.StarRepo(ctx, *ctx.Doer, ctx.Repo.Repository.ID, true)
|
||||
case "unstar":
|
||||
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err = repo_model.StarRepo(ctx, *ctx.Doer, ctx.Repo.Repository.ID, false)
|
||||
case "accept_transfer":
|
||||
err = acceptOrRejectRepoTransfer(ctx, true)
|
||||
case "reject_transfer":
|
||||
|
|
Loading…
Reference in a new issue