2023-09-08 11:17:14 +00:00
|
|
|
package main
|
2023-03-02 14:54:33 +00:00
|
|
|
|
|
|
|
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 {
|
2023-09-08 11:17:14 +00:00
|
|
|
settings *appSettings
|
2023-03-02 14:54:33 +00:00
|
|
|
input string
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: false,
|
|
|
|
},
|
|
|
|
input: xmlBodyWithNamespace,
|
|
|
|
err: false,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: false,
|
|
|
|
},
|
|
|
|
input: xmlBody,
|
|
|
|
err: true,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: false,
|
|
|
|
},
|
|
|
|
input: xmlBodyWithInvalidNamespace,
|
|
|
|
err: true,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: true,
|
|
|
|
},
|
|
|
|
input: xmlBodyWithNamespace,
|
|
|
|
err: false,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: true,
|
|
|
|
},
|
|
|
|
input: xmlBody,
|
|
|
|
err: false,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 11:17:14 +00:00
|
|
|
settings: &appSettings{
|
|
|
|
defaultXMLNSForCompleteMultipart: true,
|
|
|
|
},
|
|
|
|
input: xmlBodyWithInvalidNamespace,
|
|
|
|
err: true,
|
2023-03-02 14:54:33 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
model := new(handler.CompleteMultipartUpload)
|
2023-09-08 11:17:14 +00:00
|
|
|
err := tc.settings.NewCompleteMultipartDecoder(bytes.NewBufferString(tc.input)).Decode(model)
|
2023-03-02 14:54:33 +00:00
|
|
|
if tc.err {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|