mirror of https://github.com/Ryuno-Ki/gitea.git
Compare commits
78 Commits
8fee7c46c1
...
e91229eefb
Author | SHA1 | Date |
---|---|---|
![]() |
e91229eefb | 2 months ago |
![]() |
62104b4896 | 2 months ago |
![]() |
62cb3c8c85 | 2 months ago |
![]() |
05a74e6e22 | 2 months ago |
![]() |
cc42c6488a | 2 months ago |
![]() |
e86f18a05a | 2 months ago |
![]() |
909fb6ad20 | 2 months ago |
![]() |
e4ceaf65fb | 2 months ago |
![]() |
439ace607d | 2 months ago |
![]() |
433443ffa9 | 2 months ago |
![]() |
870d7f90e7 | 2 months ago |
![]() |
af7cfdee0e | 2 months ago |
![]() |
90f3365d93 | 2 months ago |
![]() |
7fbf002403 | 2 months ago |
![]() |
5d653cc10d | 2 months ago |
![]() |
dd1ed35f75 | 2 months ago |
![]() |
fd0d481de8 | 2 months ago |
![]() |
8eefe2af45 | 2 months ago |
![]() |
46e50bcbfc | 2 months ago |
![]() |
ae446b13f9 | 2 months ago |
![]() |
5d80feb5a6 | 2 months ago |
![]() |
1e9ad8eb21 | 2 months ago |
![]() |
ea9997a9dd | 2 months ago |
![]() |
27ba86d283 | 2 months ago |
![]() |
719eb4a879 | 2 months ago |
![]() |
a036507204 | 2 months ago |
![]() |
bdde56c95c | 2 months ago |
![]() |
1e05adfc3e | 2 months ago |
![]() |
9068c784c8 | 2 months ago |
![]() |
e3e06d13af | 2 months ago |
![]() |
89b0aac374 | 2 months ago |
![]() |
157b405753 | 2 months ago |
![]() |
70ce051f1a | 2 months ago |
![]() |
36127a3336 | 2 months ago |
![]() |
d05fb6f6c9 | 2 months ago |
![]() |
a6b7c3646a | 2 months ago |
![]() |
e399f0f5b4 | 2 months ago |
![]() |
b01dce2a6e | 2 months ago |
![]() |
7d1770cd71 | 2 months ago |
![]() |
6473bd333a | 2 months ago |
![]() |
881646520e | 2 months ago |
![]() |
f0ce5470e5 | 2 months ago |
![]() |
1f8f9c3826 | 2 months ago |
![]() |
9f87b60b46 | 2 months ago |
![]() |
97548d2722 | 2 months ago |
![]() |
d91d4db344 | 2 months ago |
![]() |
b4d420d865 | 2 months ago |
![]() |
f6e2dbaf1e | 2 months ago |
![]() |
460c03ca49 | 2 months ago |
![]() |
1fef9a2d69 | 2 months ago |
![]() |
0d7eda511f | 2 months ago |
![]() |
ff82a18315 | 2 months ago |
![]() |
3c6c150740 | 2 months ago |
![]() |
1a9821f57a | 2 months ago |
![]() |
3708ca8e28 | 2 months ago |
![]() |
5f136783d1 | 2 months ago |
![]() |
110fc57cbc | 2 months ago |
![]() |
a9dc9b06e4 | 2 months ago |
![]() |
796c4eca0b | 2 months ago |
![]() |
0097fbc2ac | 2 months ago |
![]() |
edf14202fe | 2 months ago |
![]() |
3898fc5bda | 2 months ago |
![]() |
47bb06236d | 2 months ago |
![]() |
a9cc9c0f7a | 2 months ago |
![]() |
ce3dd04c63 | 2 months ago |
![]() |
88f2e457d8 | 2 months ago |
![]() |
23422f9909 | 2 months ago |
![]() |
527e5bd1b2 | 2 months ago |
![]() |
4d8e9f3b84 | 2 months ago |
![]() |
4f1fb0f697 | 2 months ago |
![]() |
52c2e82813 | 2 months ago |
![]() |
5f618248a9 | 2 months ago |
![]() |
a0051634b9 | 2 months ago |
![]() |
e26f84a9b7 | 2 months ago |
![]() |
2ae45cebbf | 2 months ago |
![]() |
7948cb3149 | 2 months ago |
![]() |
d087554d81 | 2 months ago |
![]() |
f92b7a6331 | 2 months ago |
437 changed files with 9986 additions and 6471 deletions
@ -0,0 +1,103 @@
|
||||
// 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" |
||||
|
||||
ap "github.com/go-ap/activitypub" |
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func TestActivityPubPerson(t *testing.T) { |
||||
onGiteaRun(t, func(*testing.T, *url.URL) { |
||||
setting.Federation.Enabled = true |
||||
defer func() { |
||||
setting.Federation.Enabled = false |
||||
}() |
||||
|
||||
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) { |
||||
onGiteaRun(t, func(*testing.T, *url.URL) { |
||||
setting.Federation.Enabled = true |
||||
defer func() { |
||||
setting.Federation.Enabled = false |
||||
}() |
||||
|
||||
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) { |
||||
srv := httptest.NewServer(c) |
||||
defer srv.Close() |
||||
|
||||
onGiteaRun(t, func(*testing.T, *url.URL) { |
||||
appURL := setting.AppURL |
||||
setting.Federation.Enabled = true |
||||
setting.AppURL = srv.URL |
||||
defer func() { |
||||
setting.Federation.Enabled = false |
||||
setting.Database.LogSQL = false |
||||
setting.AppURL = appURL |
||||
}() |
||||
username1 := "user1" |
||||
ctx := context.Background() |
||||
user1, err := user_model.GetUserByName(ctx, username1) |
||||
assert.NoError(t, err) |
||||