forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Catch the error before the response is processed by goth. (go-gitea#20000) Adjust transaction handling via db.Context (go-gitea#20031) Add more linters to improve code readability (go-gitea#19989) [skip ci] Updated translations via Crowdin Disable federation by default (go-gitea#20045) Respond with a 401 on git push when password isn't changed yet (go-gitea#20026) Alter hook_task TEXT fields to LONGTEXT (go-gitea#20038) Simplify and fix migration 216 (go-gitea#20035) use quoted regexp instead of git fixed-value (go-gitea#20029) fix delete pull head ref for DeleteIssue (go-gitea#20032) User keypairs and HTTP signatures for ActivityPub federation using go-ap (go-gitea#19133) Backtick table name in generic orphan check (go-gitea#20019) Update document to clarify that ALLOWED_DOMAINS/BLOCKED_DOMAINS support wildcard (go-gitea#20016) Return 404 when tag is broken (go-gitea#20017) Dump should only copy regular files and symlink regular files (go-gitea#20015)
- Loading branch information
Showing
197 changed files
with
1,286 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/activitypub" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/routers" | ||
|
||
ap "github.com/go-ap/activitypub" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestActivityPubPerson(t *testing.T) { | ||
setting.Federation.Enabled = true | ||
c = routers.NormalRoutes() | ||
defer func() { | ||
setting.Federation.Enabled = false | ||
c = routers.NormalRoutes() | ||
}() | ||
|
||
onGiteaRun(t, func(*testing.T, *url.URL) { | ||
username := "user2" | ||
req := NewRequestf(t, "GET", fmt.Sprintf("/api/v1/activitypub/user/%s", username)) | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
body := resp.Body.Bytes() | ||
assert.Contains(t, string(body), "@context") | ||
|
||
var person ap.Person | ||
err := person.UnmarshalJSON(body) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, ap.PersonType, person.Type) | ||
assert.Equal(t, username, person.PreferredUsername.String()) | ||
keyID := person.GetID().String() | ||
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) | ||
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String()) | ||
assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.Inbox.GetID().String()) | ||
|
||
pubKey := person.PublicKey | ||
assert.NotNil(t, pubKey) | ||
publicKeyID := keyID + "#main-key" | ||
assert.Equal(t, pubKey.ID.String(), publicKeyID) | ||
|
||
pubKeyPem := pubKey.PublicKeyPem | ||
assert.NotNil(t, pubKeyPem) | ||
assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem) | ||
}) | ||
} | ||
|
||
func TestActivityPubMissingPerson(t *testing.T) { | ||
setting.Federation.Enabled = true | ||
c = routers.NormalRoutes() | ||
defer func() { | ||
setting.Federation.Enabled = false | ||
c = routers.NormalRoutes() | ||
}() | ||
|
||
onGiteaRun(t, func(*testing.T, *url.URL) { | ||
req := NewRequestf(t, "GET", "/api/v1/activitypub/user/nonexistentuser") | ||
resp := MakeRequest(t, req, http.StatusNotFound) | ||
assert.Contains(t, resp.Body.String(), "user redirect does not exist") | ||
}) | ||
} | ||
|
||
func TestActivityPubPersonInbox(t *testing.T) { | ||
setting.Federation.Enabled = true | ||
c = routers.NormalRoutes() | ||
defer func() { | ||
setting.Federation.Enabled = false | ||
c = routers.NormalRoutes() | ||
}() | ||
|
||
srv := httptest.NewServer(c) | ||
defer srv.Close() | ||
|
||
onGiteaRun(t, func(*testing.T, *url.URL) { | ||
appURL := setting.AppURL | ||
setting.AppURL = srv.URL | ||
defer func() { | ||
setting.Database.LogSQL = false | ||
setting.AppURL = appURL | ||
}() | ||
username1 := "user1" | ||
ctx := context.Background() | ||
user1, err := user_model.GetUserByName(ctx, username1) | ||
assert.NoError(t, err) | ||
user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1) | ||
c, err := activitypub.NewClient(user1, user1url) | ||
assert.NoError(t, err) | ||
username2 := "user2" | ||
user2inboxurl := fmt.Sprintf("%s/api/v1/activitypub/user/%s/inbox", srv.URL, username2) | ||
|
||
// Signed request succeeds | ||
resp, err := c.Post([]byte{}, user2inboxurl) | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusNoContent, resp.StatusCode) | ||
|
||
// Unsigned request fails | ||
req := NewRequest(t, "POST", user2inboxurl) | ||
MakeRequest(t, req, http.StatusInternalServerError) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.