53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
//go:build !integration
|
|
|
|
package uploader
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/valyala/fasthttp"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func TestFilter(t *testing.T) {
|
|
log := zap.NewNop()
|
|
|
|
t.Run("duplicate keys error", func(t *testing.T) {
|
|
req := &fasthttp.RequestHeader{}
|
|
req.DisableNormalizing()
|
|
req.Add("X-Attribute-DupKey", "first-value")
|
|
req.Add("X-Attribute-DupKey", "second-value")
|
|
_, err := filterHeaders(log, req)
|
|
require.Error(t, err)
|
|
})
|
|
|
|
t.Run("duplicate system keys error", func(t *testing.T) {
|
|
req := &fasthttp.RequestHeader{}
|
|
req.DisableNormalizing()
|
|
req.Add("X-Attribute-System-DupKey", "first-value")
|
|
req.Add("X-Attribute-System-DupKey", "second-value")
|
|
_, err := filterHeaders(log, req)
|
|
require.Error(t, err)
|
|
})
|
|
|
|
req := &fasthttp.RequestHeader{}
|
|
req.DisableNormalizing()
|
|
|
|
req.Set("X-Attribute-System-Expiration-Epoch1", "101")
|
|
req.Set("X-Attribute-SYSTEM-Expiration-Epoch2", "102")
|
|
req.Set("X-Attribute-system-Expiration-Epoch3", "103")
|
|
req.Set("X-Attribute-MyAttribute", "value")
|
|
|
|
expected := map[string]string{
|
|
"__SYSTEM__EXPIRATION_EPOCH1": "101",
|
|
"MyAttribute": "value",
|
|
"__SYSTEM__EXPIRATION_EPOCH3": "103",
|
|
"__SYSTEM__EXPIRATION_EPOCH2": "102",
|
|
}
|
|
|
|
result, err := filterHeaders(log, req)
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expected, result)
|
|
}
|