1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00
This commit is contained in:
Michael Jerger 2024-01-14 13:03:51 +01:00
parent f25eab35fc
commit 1b35bd2911
4 changed files with 11 additions and 6 deletions

View file

@ -166,7 +166,7 @@ func Test_PersonMarshalJSON(t *testing.T) {
sut.PreferredUsername = ap.NaturalLanguageValuesNew()
sut.PreferredUsername.Set("en", ap.Content("MaxMuster"))
result, _ := sut.MarshalJSON()
if "{\"type\":\"Person\",\"preferredUsername\":\"MaxMuster\"}" != string(result) {
if string(result) != "{\"type\":\"Person\",\"preferredUsername\":\"MaxMuster\"}" {
t.Errorf("MarshalJSON() was = %q", result)
}
}

View file

@ -63,26 +63,26 @@ func Test_NodeInfoWellKnownValidate(t *testing.T) {
}
func Test_NewNodeInfoWellKnown(t *testing.T) {
sut, err := NewNodeInfoWellKnown([]byte(`{"links":[{"href":"https://federated-repo.prod.meissa.de/api/v1/nodeinfo","rel":"http://nodeinfo.diaspora.software/ns/schema/2.1"}]}`))
sut, _ := NewNodeInfoWellKnown([]byte(`{"links":[{"href":"https://federated-repo.prod.meissa.de/api/v1/nodeinfo","rel":"http://nodeinfo.diaspora.software/ns/schema/2.1"}]}`))
expected := NodeInfoWellKnown{Href: "https://federated-repo.prod.meissa.de/api/v1/nodeinfo"}
if sut != expected {
t.Errorf("expected was: %v but was: %v", expected, sut)
}
sut, err = NewNodeInfoWellKnown([]byte(`invalid`))
_, err := NewNodeInfoWellKnown([]byte(`invalid`))
if err == nil {
t.Errorf("error was expected here")
}
}
func Test_NewNodeInfo(t *testing.T) {
sut, err := NewNodeInfo([]byte(`{"version":"2.1","software":{"name":"gitea","version":"1.20.0+dev-2539-g5840cc6d3","repository":"https://github.com/go-gitea/gitea.git","homepage":"https://gitea.io/"},"protocols":["activitypub"],"services":{"inbound":[],"outbound":["rss2.0"]},"openRegistrations":true,"usage":{"users":{"total":13,"activeHalfyear":1,"activeMonth":1}},"metadata":{}}`))
sut, _ := NewNodeInfo([]byte(`{"version":"2.1","software":{"name":"gitea","version":"1.20.0+dev-2539-g5840cc6d3","repository":"https://github.com/go-gitea/gitea.git","homepage":"https://gitea.io/"},"protocols":["activitypub"],"services":{"inbound":[],"outbound":["rss2.0"]},"openRegistrations":true,"usage":{"users":{"total":13,"activeHalfyear":1,"activeMonth":1}},"metadata":{}}`))
expected := NodeInfo{Source: "gitea"}
if sut != expected {
t.Errorf("expected was: %v but was: %v", expected, sut)
}
sut, err = NewNodeInfo([]byte(`invalid`))
_, err := NewNodeInfo([]byte(`invalid`))
if err == nil {
t.Errorf("error was expected here")
}

View file

@ -87,7 +87,7 @@ func NewClient(ctx context.Context, user *user_model.User, pubID string) (c *Cli
Transport: &http.Transport{
Proxy: proxy.Proxy(),
},
Timeout: time.Duration(5 * time.Second),
Timeout: 5 * time.Second,
},
algs: setting.HttpsigAlgs,
digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm),

View file

@ -91,6 +91,11 @@ func RepositoryInbox(ctx *context.APIContext) {
// parse actorID (person)
actorURI := activity.Actor.GetID().String()
rawActorID, err := forgefed.NewActorID(actorURI)
if err != nil {
ctx.Error(http.StatusInternalServerError,
"RepositoryInbox: Validating ActorID", err)
return
}
federationInfo, err := forgefed.FindFederationInfoByHostFqdn(ctx, rawActorID.Host)
if err != nil {
ctx.Error(http.StatusInternalServerError,