mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-04 01:38:12 +08:00
test: add tests for supplementary Unicode and Proxy-Authorization
- Add TestRenderAsciiJSONSupplementaryUnicode to verify emoji (U+1F600) is encoded as UTF-16 surrogate pair (\uD83D\uDE00) - Add Proxy-Authorization test case to TestSecureRequestDump to verify credentials are sanitized in recovery panic logs
This commit is contained in:
parent
08e51b48be
commit
4ce483f0f4
@ -293,6 +293,16 @@ func TestSecureRequestDump(t *testing.T) {
|
|||||||
wantContains: "Authorization: *",
|
wantContains: "Authorization: *",
|
||||||
wantNotContain: "token123",
|
wantNotContain: "token123",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Proxy-Authorization header",
|
||||||
|
req: func() *http.Request {
|
||||||
|
r, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||||
|
r.Header.Set("Proxy-Authorization", "Basic cHJveHk6c2VjcmV0")
|
||||||
|
return r
|
||||||
|
}(),
|
||||||
|
wantContains: "Proxy-Authorization: *",
|
||||||
|
wantNotContain: "Basic cHJveHk6c2VjcmV0",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "No Authorization header",
|
name: "No Authorization header",
|
||||||
req: func() *http.Request {
|
req: func() *http.Request {
|
||||||
|
|||||||
@ -261,6 +261,16 @@ func TestRenderAsciiJSON(t *testing.T) {
|
|||||||
assert.Equal(t, "3.1415926", w2.Body.String())
|
assert.Equal(t, "3.1415926", w2.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderAsciiJSONSupplementaryUnicode(t *testing.T) {
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
data := map[string]string{"emoji": "😀"}
|
||||||
|
|
||||||
|
err := (AsciiJSON{data}).Render(w)
|
||||||
|
require.NoError(t, err)
|
||||||
|
// U+1F600 must be encoded as UTF-16 surrogate pair per RFC 8259
|
||||||
|
assert.Equal(t, "{\"emoji\":\"\\ud83d\\ude00\"}", w.Body.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestRenderAsciiJSONFail(t *testing.T) {
|
func TestRenderAsciiJSONFail(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
data := make(chan int)
|
data := make(chan int)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user