Denis Kirillov
0af06c3bd9
This parameter enables parsing xml body without xmlns="http://s3.amazonaws.com/doc/2006-03-01/" attribute for CompleteMultipartUpload requests Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
83 lines
1.7 KiB
Go
83 lines
1.7 KiB
Go
package xml
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/handler"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDefaultNamespace(t *testing.T) {
|
|
xmlBodyWithNamespace := `
|
|
<CompleteMultipartUpload xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
xmlBodyWithInvalidNamespace := `
|
|
<CompleteMultipartUpload xmlns="http://bla.bla.bla/">
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
xmlBody := `
|
|
<CompleteMultipartUpload>
|
|
<Part>
|
|
<ETag>string</ETag>
|
|
<PartNumber>1</PartNumber>
|
|
</Part>
|
|
</CompleteMultipartUpload>
|
|
`
|
|
|
|
for _, tc := range []struct {
|
|
provider *DecoderProvider
|
|
input string
|
|
err bool
|
|
}{
|
|
{
|
|
provider: NewDecoderProvider(false),
|
|
input: xmlBodyWithNamespace,
|
|
err: false,
|
|
},
|
|
{
|
|
provider: NewDecoderProvider(false),
|
|
input: xmlBody,
|
|
err: true,
|
|
},
|
|
{
|
|
provider: NewDecoderProvider(false),
|
|
input: xmlBodyWithInvalidNamespace,
|
|
err: true,
|
|
},
|
|
{
|
|
provider: NewDecoderProvider(true),
|
|
input: xmlBodyWithNamespace,
|
|
err: false,
|
|
},
|
|
{
|
|
provider: NewDecoderProvider(true),
|
|
input: xmlBody,
|
|
err: false,
|
|
},
|
|
{
|
|
provider: NewDecoderProvider(true),
|
|
input: xmlBodyWithInvalidNamespace,
|
|
err: true,
|
|
},
|
|
} {
|
|
t.Run("", func(t *testing.T) {
|
|
model := new(handler.CompleteMultipartUpload)
|
|
err := tc.provider.NewCompleteMultipartDecoder(bytes.NewBufferString(tc.input)).Decode(model)
|
|
if tc.err {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|