Mark unused&immature activitypub as "not implemented" (#36789)
After many years, "activitypub" is still "in progress" and no real progress for end users. So it is not mature. Temporarily mark the endpoints as "501 not implemented", and wait until the whole design is stable and usable.
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"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/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
ap "github.com/go-ap/activitypub"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestActivityPubPerson(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
t.Run("ExistingPerson", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
userID := 2
|
||||
username := "user2"
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/activitypub/user-id/%v", userID))
|
||||
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-id/%v$", userID), keyID)
|
||||
assert.Regexp(t, fmt.Sprintf("activitypub/user-id/%v/outbox$", userID), person.Outbox.GetID().String())
|
||||
assert.Regexp(t, fmt.Sprintf("activitypub/user-id/%v/inbox$", userID), 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)
|
||||
})
|
||||
t.Run("MissingPerson", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
req := NewRequest(t, "GET", "/api/v1/activitypub/user-id/999999999")
|
||||
resp := MakeRequest(t, req, http.StatusNotFound)
|
||||
assert.Contains(t, resp.Body.String(), "user does not exist")
|
||||
})
|
||||
t.Run("MissingPersonInbox", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
srv := httptest.NewServer(testWebRoutes)
|
||||
defer srv.Close()
|
||||
defer test.MockVariableValue(&setting.AppURL, srv.URL+"/")()
|
||||
|
||||
username1 := "user1"
|
||||
ctx := t.Context()
|
||||
user1, err := user_model.GetUserByName(ctx, username1)
|
||||
assert.NoError(t, err)
|
||||
user1url := srv.URL + "/api/v1/activitypub/user-id/1#main-key"
|
||||
c, err := activitypub.NewClient(t.Context(), user1, user1url)
|
||||
assert.NoError(t, err)
|
||||
user2inboxurl := srv.URL + "/api/v1/activitypub/user-id/2/inbox"
|
||||
|
||||
// Signed request succeeds
|
||||
resp, err := c.Post([]byte{}, user2inboxurl)
|
||||
defer resp.Body.Close()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
|
||||
|
||||
// Unsigned request fails
|
||||
req := NewRequest(t, "POST", user2inboxurl)
|
||||
MakeRequest(t, req, http.StatusInternalServerError)
|
||||
})
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeinfo(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
req := NewRequest(t, "GET", "/api/v1/nodeinfo")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
VerifyJSONSchema(t, resp, "nodeinfo_2.1.json")
|
||||
|
||||
var nodeinfo api.NodeInfo
|
||||
DecodeJSON(t, resp, &nodeinfo)
|
||||
assert.True(t, nodeinfo.OpenRegistrations)
|
||||
assert.Equal(t, "gitea", nodeinfo.Software.Name)
|
||||
assert.Equal(t, 29, nodeinfo.Usage.Users.Total)
|
||||
assert.Equal(t, 22, nodeinfo.Usage.LocalPosts)
|
||||
assert.Equal(t, 3, nodeinfo.Usage.LocalComments)
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"id": "http://nodeinfo.diaspora.software/ns/schema/2.1#",
|
||||
"description": "NodeInfo schema version 2.1.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"version",
|
||||
"software",
|
||||
"protocols",
|
||||
"services",
|
||||
"openRegistrations",
|
||||
"usage",
|
||||
"metadata"
|
||||
],
|
||||
"properties": {
|
||||
"version": {
|
||||
"description": "The schema version, must be 2.1.",
|
||||
"enum": [
|
||||
"2.1"
|
||||
]
|
||||
},
|
||||
"software": {
|
||||
"description": "Metadata about server software in use.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"name",
|
||||
"version"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "The canonical name of this server software.",
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9-]+$"
|
||||
},
|
||||
"version": {
|
||||
"description": "The version of this server software.",
|
||||
"type": "string"
|
||||
},
|
||||
"repository": {
|
||||
"description": "The url of the source code repository of this server software.",
|
||||
"type": "string"
|
||||
},
|
||||
"homepage": {
|
||||
"description": "The url of the homepage of this server software.",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"protocols": {
|
||||
"description": "The protocols supported on this server.",
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"enum": [
|
||||
"activitypub",
|
||||
"buddycloud",
|
||||
"dfrn",
|
||||
"diaspora",
|
||||
"libertree",
|
||||
"ostatus",
|
||||
"pumpio",
|
||||
"tent",
|
||||
"xmpp",
|
||||
"zot"
|
||||
]
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"description": "The third party sites this server can connect to via their application API.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"inbound",
|
||||
"outbound"
|
||||
],
|
||||
"properties": {
|
||||
"inbound": {
|
||||
"description": "The third party sites this server can retrieve messages from for combined display with regular traffic.",
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"items": {
|
||||
"enum": [
|
||||
"atom1.0",
|
||||
"gnusocial",
|
||||
"imap",
|
||||
"pnut",
|
||||
"pop3",
|
||||
"pumpio",
|
||||
"rss2.0",
|
||||
"twitter"
|
||||
]
|
||||
}
|
||||
},
|
||||
"outbound": {
|
||||
"description": "The third party sites this server can publish messages to on the behalf of a user.",
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"items": {
|
||||
"enum": [
|
||||
"atom1.0",
|
||||
"blogger",
|
||||
"buddycloud",
|
||||
"diaspora",
|
||||
"dreamwidth",
|
||||
"drupal",
|
||||
"facebook",
|
||||
"friendica",
|
||||
"gnusocial",
|
||||
"google",
|
||||
"insanejournal",
|
||||
"libertree",
|
||||
"linkedin",
|
||||
"livejournal",
|
||||
"mediagoblin",
|
||||
"myspace",
|
||||
"pinterest",
|
||||
"pnut",
|
||||
"posterous",
|
||||
"pumpio",
|
||||
"redmatrix",
|
||||
"rss2.0",
|
||||
"smtp",
|
||||
"tent",
|
||||
"tumblr",
|
||||
"twitter",
|
||||
"wordpress",
|
||||
"xmpp"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"openRegistrations": {
|
||||
"description": "Whether this server allows open self-registration.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"usage": {
|
||||
"description": "Usage statistics for this server.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"users"
|
||||
],
|
||||
"properties": {
|
||||
"users": {
|
||||
"description": "statistics about the users of this server.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"total": {
|
||||
"description": "The total amount of on this server registered users.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"activeHalfyear": {
|
||||
"description": "The amount of users that signed in at least once in the last 180 days.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"activeMonth": {
|
||||
"description": "The amount of users that signed in at least once in the last 30 days.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"localPosts": {
|
||||
"description": "The amount of posts that were made by users that are registered on this server.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"localComments": {
|
||||
"description": "The amount of comments that were made by users that are registered on this server.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"description": "Free form key value pairs for software specific values. Clients should not rely on any specific key present.",
|
||||
"type": "object",
|
||||
"minProperties": 0,
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWebfinger(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Federation.Enabled, true)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
appURL, _ := url.Parse(setting.AppURL)
|
||||
|
||||
type webfingerLink struct {
|
||||
Rel string `json:"rel,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Href string `json:"href,omitempty"`
|
||||
Titles map[string]string `json:"titles,omitempty"`
|
||||
Properties map[string]any `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
type webfingerJRD struct {
|
||||
Subject string `json:"subject,omitempty"`
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
Properties map[string]any `json:"properties,omitempty"`
|
||||
Links []*webfingerLink `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, appURL.Host))
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var jrd webfingerJRD
|
||||
DecodeJSON(t, resp, &jrd)
|
||||
assert.Equal(t, "acct:user2@"+appURL.Host, jrd.Subject)
|
||||
assert.ElementsMatch(t, []string{user.HTMLURL(t.Context()), appURL.String() + "api/v1/activitypub/user-id/" + strconv.FormatInt(user.ID, 10)}, jrd.Aliases)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, "unknown.host"))
|
||||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", "user31", appURL.Host))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", "user31", appURL.Host))
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
req = NewRequest(t, "GET", "/.well-known/webfinger?resource=mailto:"+user.Email)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
Reference in New Issue
Block a user