wix the invalid test

This commit is contained in:
Michael Jerger 2024-05-01 15:46:15 +02:00
parent 534d692d68
commit ded7b60d0c

View file

@ -59,7 +59,7 @@ func TestActivityPubMissingRepository(t *testing.T) {
})
}
func TestActivityPubRepositoryInbox(t *testing.T) {
func TestActivityPubRepositoryInboxValid(t *testing.T) {
setting.Federation.Enabled = true
testWebRoutes = routers.NormalRoutes()
defer func() {
@ -84,16 +84,42 @@ func TestActivityPubRepositoryInbox(t *testing.T) {
repoInboxUrl := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%v/inbox",
srv.URL, repositoryID)
// valid activity request succeeds
activity := []byte(fmt.Sprintf(`{"type":"Like","startTime":"2024-03-27T00:00:00Z","actor":"%s/api/v1/activitypub/user-id/2","object":"%s/api/v1/activitypub/repository-id/%v"}`,
srv.URL, srv.URL, repositoryID))
resp, err := c.Post(activity, repoInboxUrl)
assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
// invalid activity request succeeds
activity = []byte(fmt.Sprintf(`{"type":"Wrong"}`))
resp, err = c.Post(activity, repoInboxUrl)
assert.Error(t, err)
})
}
func TestActivityPubRepositoryInboxInvalid(t *testing.T) {
setting.Federation.Enabled = true
testWebRoutes = routers.NormalRoutes()
defer func() {
setting.Federation.Enabled = false
testWebRoutes = routers.NormalRoutes()
}()
srv := httptest.NewServer(testWebRoutes)
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
}()
actionsUser := user.NewActionsUser()
repositoryID := 2
c, err := activitypub.NewClient(db.DefaultContext, actionsUser, "not used")
assert.NoError(t, err)
repoInboxUrl := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%v/inbox",
srv.URL, repositoryID)
activity := []byte(fmt.Sprintf(`{"type":"Wrong"}`))
resp, err := c.Post(activity, repoInboxUrl)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode)
})
}