From 9047058c4374b6492b8a802062effbe7bfcfa8b9 Mon Sep 17 00:00:00 2001 From: Sergey Kostrukov Date: Mon, 2 May 2022 04:08:20 -0700 Subject: [PATCH] Auth Proxy: non-ASCII headers encoding tests (#47110) --- pkg/util/encoding_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/util/encoding_test.go b/pkg/util/encoding_test.go index 83598e64ff8..4bb5f345ca3 100644 --- a/pkg/util/encoding_test.go +++ b/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) + }) }