test: fix test w/curl error, bucket creation/location tests

This commit is contained in:
Luke McCrone
2025-10-08 18:36:00 -03:00
parent 13810e227c
commit 9c8e14d406
48 changed files with 654 additions and 265 deletions

View File

@@ -0,0 +1,45 @@
package command
import (
"encoding/xml"
"errors"
"fmt"
)
type CreateBucketCommandXML struct {
XMLName xml.Name `xml:"CreateBucketConfiguration"`
XMLNamespace string `xml:"xmlns,attr"`
LocationConstraint string `xml:"LocationConstraint"`
}
type CreateBucketCommand struct {
*S3Command
Config *CreateBucketCommandXML
}
func NewCreateBucketCommand(s3Command *S3Command, locationConstraint string, constraintSet bool) (*CreateBucketCommand, error) {
if s3Command.BucketName == "" {
return nil, errors.New("CreateBucket must have bucket name")
}
s3Command.Method = "PUT"
s3Command.Query = ""
var config *CreateBucketCommandXML = nil
if constraintSet {
config = &CreateBucketCommandXML{
XMLNamespace: "http://s3.amazonaws.com/doc/2006-03-01/",
LocationConstraint: locationConstraint,
}
}
command := &CreateBucketCommand{
S3Command: s3Command,
Config: config,
}
if constraintSet {
xmlData, err := xml.Marshal(command.Config)
if err != nil {
return nil, fmt.Errorf("error marshalling XML: %w", err)
}
command.Payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + string(xmlData)
}
return command, nil
}

View File

@@ -38,11 +38,15 @@ func GetBase64ChecksumLength(checksumType string) (int64, error) {
func (p *Payload) GetDataSize() (int64, error) {
if !p.dataSizeCalculated {
dataSize, err := p.dataSource.SourceDataByteSize()
if err != nil {
return 0, fmt.Errorf("error getting payload data size: %w", err)
if p.dataSource != nil {
dataSize, err := p.dataSource.SourceDataByteSize()
if err != nil {
return 0, fmt.Errorf("error getting payload data size: %w", err)
}
p.dataSize = dataSize
} else {
p.dataSize = 0
}
p.dataSize = dataSize
p.dataSizeCalculated = true
}
return p.dataSize, nil

View File

@@ -6,7 +6,6 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
logger "github.com/versity/versitygw/tests/rest_scripts/logger"
"os"
@@ -112,9 +111,6 @@ type S3Command struct {
}
func (s *S3Command) OpenSSLCommand() error {
if s.FilePath == "" {
return errors.New("for openssl command, filePath must be set")
}
if err := s.prepareForBuild(); err != nil {
return fmt.Errorf("error preparing for command building: %w", err)
}
@@ -162,9 +158,6 @@ func (s *S3Command) prepareForBuild() error {
}
func (s *S3Command) preparePayload() error {
if s.PayloadFile != "" && s.Payload != "" {
return fmt.Errorf("cannot have both payload and payloadFile parameters set")
}
if s.PayloadFile != "" {
s.dataSource = NewFileDataSource(s.PayloadFile)
} else if s.Payload != "" {
@@ -198,6 +191,8 @@ func (s *S3Command) initializeOpenSSLPayloadAndGetContentLength() error {
streamingUnsignedPayloadTrailerImpl := NewStreamingUnsignedPayloadWithTrailer(s.dataSource, int64(s.ChunkSize), s.ChecksumType)
streamingUnsignedPayloadTrailerImpl.OmitTrailerOrKey(s.OmitPayloadTrailer, s.OmitPayloadTrailerKey)
s.payloadOpenSSL = streamingUnsignedPayloadTrailerImpl
case UnsignedPayload, "":
s.payloadOpenSSL = NewWholePayload(s.dataSource)
default:
return fmt.Errorf("unsupported OpenSSL payload type: '%s'", s.PayloadType)
}
@@ -407,6 +402,9 @@ func (s *S3Command) buildOpenSSLCommand() error {
if _, err = file.Write(openSSLCommandBytes); err != nil {
return fmt.Errorf("error writing to file: %w", err)
}
if _, err := file.Write([]byte{'\r', '\n', '\r', '\n'}); err != nil {
return fmt.Errorf("error writing to file: %w", err)
}
if s.PayloadFile != "" || s.Payload != "" {
if err = s.writeOpenSSLPayload(file); err != nil {
return fmt.Errorf("error writing openssl payload: %w", err)
@@ -416,9 +414,6 @@ func (s *S3Command) buildOpenSSLCommand() error {
}
func (s *S3Command) writeOpenSSLPayload(file *os.File) error {
if _, err := file.Write([]byte{'\r', '\n', '\r', '\n'}); err != nil {
return fmt.Errorf("error writing to file: %w", err)
}
if awsPayload, ok := s.payloadOpenSSL.(*PayloadStreamingAWS4HMACSHA256); ok {
awsPayload.AddInitialSignatureAndSigningKey(s.signature, s.signingKey)
}

View File

@@ -30,6 +30,9 @@ func (w *WholePayload) GetContentLength() (int64, error) {
}
func (w *WholePayload) WritePayload(filePath string) error {
if w.dataSource == nil {
return nil
}
sourceFile, err := w.dataSource.GetReader()
if err != nil {
return fmt.Errorf("error creating tee reader: %w", err)