mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-25 00:07:36 +02:00
Return HTTP 500 on Matrix discovery GET if base-url not configured; log entire HTTP request when TRACE enabled
This commit is contained in:
parent
e578f01e5b
commit
25a4b29ffc
5 changed files with 108 additions and 1 deletions
server
|
@ -1,8 +1,12 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/require"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -27,3 +31,47 @@ func TestReadBoolParam(t *testing.T) {
|
|||
require.Equal(t, false, up)
|
||||
require.Equal(t, true, firebase)
|
||||
}
|
||||
|
||||
func TestRenderHTTPRequest_ValidShort(t *testing.T) {
|
||||
r, _ := http.NewRequest("POST", "http://ntfy.sh/mytopic?p=2", strings.NewReader("some message"))
|
||||
r.Header.Set("Title", "A title")
|
||||
expected := `POST /mytopic?p=2 HTTP/1.1
|
||||
Title: A title
|
||||
|
||||
some message`
|
||||
require.Equal(t, expected, renderHTTPRequest(r))
|
||||
}
|
||||
|
||||
func TestRenderHTTPRequest_ValidLong(t *testing.T) {
|
||||
body := strings.Repeat("a", 5000)
|
||||
r, _ := http.NewRequest("POST", "http://ntfy.sh/mytopic?p=2", strings.NewReader(body))
|
||||
r.Header.Set("Accept", "*/*")
|
||||
expected := `POST /mytopic?p=2 HTTP/1.1
|
||||
Accept: */*
|
||||
|
||||
` + strings.Repeat("a", 4096) + " ... (peeked 4096 bytes)"
|
||||
require.Equal(t, expected, renderHTTPRequest(r))
|
||||
}
|
||||
|
||||
func TestRenderHTTPRequest_InvalidShort(t *testing.T) {
|
||||
body := []byte{0xc3, 0x28}
|
||||
r, _ := http.NewRequest("GET", "http://ntfy.sh/mytopic/json?since=all", bytes.NewReader(body))
|
||||
r.Header.Set("Accept", "*/*")
|
||||
expected := `GET /mytopic/json?since=all HTTP/1.1
|
||||
Accept: */*
|
||||
|
||||
(peeked bytes not UTF-8, 2 bytes, hex: c328)`
|
||||
require.Equal(t, expected, renderHTTPRequest(r))
|
||||
}
|
||||
|
||||
func TestRenderHTTPRequest_InvalidLong(t *testing.T) {
|
||||
body := make([]byte, 5000)
|
||||
rand.Read(body)
|
||||
r, _ := http.NewRequest("GET", "http://ntfy.sh/mytopic/json?since=all", bytes.NewReader(body))
|
||||
r.Header.Set("Accept", "*/*")
|
||||
expected := `GET /mytopic/json?since=all HTTP/1.1
|
||||
Accept: */*
|
||||
|
||||
(peeked bytes not UTF-8, peek limit of 4096 bytes reached, hex: ` + fmt.Sprintf("%x", body[:4096]) + ` ...)`
|
||||
require.Equal(t, expected, renderHTTPRequest(r))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue