Auth Proxy: non-ASCII headers encoding tests (#47110)

pull/48590/head
Sergey Kostrukov 3 years ago committed by GitHub
parent 69ee917c89
commit 9047058c43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      pkg/util/encoding_test.go

@ -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)
})
}

Loading…
Cancel
Save