mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-29 14:43:57 +01:00
webhook: matrix use v3 endpoint and drop headers
This commit is contained in:
parent
99830a40a1
commit
94dd22a784
3 changed files with 5 additions and 6 deletions
|
@ -152,7 +152,6 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
|||
|
||||
case "/webhook/6db5dc1e282529a8c162c7fe93dd2667494eeb51":
|
||||
// Version 2
|
||||
assert.Equal(t, "push", r.Header.Get("X-GitHub-Event"))
|
||||
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
|
||||
body, err := io.ReadAll(r.Body)
|
||||
assert.NoError(t, err)
|
||||
|
|
|
@ -47,9 +47,10 @@ func (matrixHandler) UnmarshalForm(bind func(any)) forms.WebhookForm {
|
|||
bind(&form)
|
||||
form.AuthorizationHeader = "Bearer " + strings.TrimSpace(form.AccessToken)
|
||||
|
||||
// https://spec.matrix.org/v1.10/client-server-api/#sending-events-to-a-room
|
||||
return forms.WebhookForm{
|
||||
WebhookCoreForm: form.WebhookCoreForm,
|
||||
URL: fmt.Sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message", form.HomeserverURL, url.PathEscape(form.RoomID)),
|
||||
URL: fmt.Sprintf("%s/_matrix/client/v3/rooms/%s/send/m.room.message", form.HomeserverURL, url.PathEscape(form.RoomID)),
|
||||
ContentType: webhook_model.ContentTypeJSON,
|
||||
Secret: "",
|
||||
HTTPMethod: http.MethodPut,
|
||||
|
@ -89,7 +90,7 @@ func (matrixHandler) NewRequest(ctx context.Context, w *webhook_model.Webhook, t
|
|||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
return req, body, shared.AddDefaultHeaders(req, []byte(w.Secret), t, body) // likely useless, but has always been sent historially
|
||||
return req, body, nil
|
||||
}
|
||||
|
||||
const matrixPayloadSizeLimit = 1024 * 64
|
||||
|
|
|
@ -201,7 +201,7 @@ func TestMatrixJSONPayload(t *testing.T) {
|
|||
RepoID: 3,
|
||||
IsActive: true,
|
||||
Type: webhook_module.MATRIX,
|
||||
URL: "https://matrix.example.com/_matrix/client/r0/rooms/ROOM_ID/send/m.room.message",
|
||||
URL: "https://matrix.example.com/_matrix/client/v3/rooms/ROOM_ID/send/m.room.message",
|
||||
Meta: `{"message_type":0}`, // text
|
||||
}
|
||||
task := &webhook_model.HookTask{
|
||||
|
@ -217,8 +217,7 @@ func TestMatrixJSONPayload(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "PUT", req.Method)
|
||||
assert.Equal(t, "/_matrix/client/r0/rooms/ROOM_ID/send/m.room.message/6db5dc1e282529a8c162c7fe93dd2667494eeb51", req.URL.Path)
|
||||
assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256"))
|
||||
assert.Equal(t, "/_matrix/client/v3/rooms/ROOM_ID/send/m.room.message/6db5dc1e282529a8c162c7fe93dd2667494eeb51", req.URL.Path)
|
||||
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
|
||||
var body MatrixPayload
|
||||
err = json.NewDecoder(req.Body).Decode(&body)
|
||||
|
|
Loading…
Reference in a new issue