mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 04:42:35 +08:00
Auth Proxy: non-ASCII headers encoding tests (#47110)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -40,7 +41,6 @@ func TestDecodeQuotedPrintable(t *testing.T) {
|
||||
out string
|
||||
}{
|
||||
{"", ""},
|
||||
{" ", ""},
|
||||
{"munich", "munich"},
|
||||
{" munich", " munich"},
|
||||
{"munich gothenburg", "munich gothenburg"},
|
||||
@ -70,6 +70,26 @@ func TestDecodeQuotedPrintable(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should preserve meaningful whitespace", func(t *testing.T) {
|
||||
testStrings := []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{" ", ""},
|
||||
{" =", " "},
|
||||
{" munich gothenburg", " munich gothenburg"},
|
||||
{" munich gothenburg ", " munich gothenburg"},
|
||||
{" munich gothenburg =", " munich gothenburg "},
|
||||
{" munich\tgothenburg\t \t", " munich\tgothenburg"},
|
||||
{" munich\t gothenburg\t \t=", " munich\t gothenburg\t \t"},
|
||||
}
|
||||
|
||||
for _, str := range testStrings {
|
||||
val := DecodeQuotedPrintable(str.in)
|
||||
assert.Equal(t, str.out, val)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should gracefully ignore invalid encoding sequences", func(t *testing.T) {
|
||||
testStrings := []struct {
|
||||
in string
|
||||
@ -101,4 +121,12 @@ func TestDecodeQuotedPrintable(t *testing.T) {
|
||||
assert.Equal(t, str.out, val)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should support long strings", func(t *testing.T) {
|
||||
str_in := strings.Repeat(" M=C3=BCnchen", 128)
|
||||
str_out := strings.Repeat(" München", 128)
|
||||
|
||||
val := DecodeQuotedPrintable(str_in)
|
||||
assert.Equal(t, str_out, val)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user