forked from TrueCloudLab/frostfs-s3-gw
[#155] Added s3 url encoder
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
288f6edce8
commit
9f57756351
3 changed files with 171 additions and 7 deletions
53
api/handler/s3encoder_test.go
Normal file
53
api/handler/s3encoder_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPathEncoder(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
key string
|
||||
expected string
|
||||
}{
|
||||
{key: "simple", expected: "simple"},
|
||||
{key: "foo/bar", expected: "foo/bar"},
|
||||
{key: "foo+1/bar", expected: "foo%2B1/bar"},
|
||||
{key: "foo ab/bar", expected: "foo%20ab/bar"},
|
||||
{key: "p-%", expected: "p-%25"},
|
||||
{key: "p/", expected: "p/"},
|
||||
{key: "p/", expected: "p/"},
|
||||
{key: "~user", expected: "%7Euser"},
|
||||
{key: "*user", expected: "*user"},
|
||||
{key: "user+password", expected: "user%2Bpassword"},
|
||||
{key: "_user", expected: "_user"},
|
||||
{key: "firstname.lastname", expected: "firstname.lastname"},
|
||||
} {
|
||||
actual := s3PathEncode(tc.key, urlEncodingType)
|
||||
require.Equal(t, tc.expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryEncoder(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
key string
|
||||
expected string
|
||||
}{
|
||||
{key: "simple", expected: "simple"},
|
||||
{key: "foo/bar", expected: "foo/bar"},
|
||||
{key: "foo+1/bar", expected: "foo%2B1/bar"},
|
||||
{key: "foo ab/bar", expected: "foo+ab/bar"},
|
||||
{key: "p-%", expected: "p-%25"},
|
||||
{key: "p/", expected: "p/"},
|
||||
{key: "p/", expected: "p/"},
|
||||
{key: "~user", expected: "%7Euser"},
|
||||
{key: "*user", expected: "*user"},
|
||||
{key: "user+password", expected: "user%2Bpassword"},
|
||||
{key: "_user", expected: "_user"},
|
||||
{key: "firstname.lastname", expected: "firstname.lastname"},
|
||||
} {
|
||||
actual := s3QueryEncode(tc.key, urlEncodingType)
|
||||
require.Equal(t, tc.expected, actual)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue