Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aws-sdk-go test behavior #229

Merged
merged 1 commit into from
Nov 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions run/core/aws-sdk-go/quick-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -127,10 +126,29 @@ func randString(n int, src rand.Source, prefix string) string {
return prefix + string(b[0:30-len(prefix)])
}

func testPresignedPut(s3Client *s3.S3) {
func cleanup(s3Client *s3.S3, bucket string, object string, function string,
args map[string]interface{}, startTime time.Time) {

// Deleting the object, just in case it was created. Will not check for errors.
s3Client.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(object),
})

_, err := s3Client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: aws.String(bucket),
})
if err != nil {
failureLog(function, args, startTime, "", "AWS SDK Go DeleteBucket Failed", err).Fatal()
return
}

}

func testPresignedPutInvalidHash(s3Client *s3.S3) {
startTime := time.Now()
function := "PresignedPut"
bucket := randString(60, rand.NewSource(time.Now().UnixNano()), "aws-sdk-go-test")
bucket := randString(60, rand.NewSource(time.Now().UnixNano()), "aws-sdk-go-test-")
object := "presignedTest"
expiry := 1 * time.Minute
args := map[string]interface{}{
Expand All @@ -139,6 +157,15 @@ func testPresignedPut(s3Client *s3.S3) {
"expiry": expiry,
}

_, err := s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(bucket),
})
if err != nil {
failureLog(function, args, startTime, "", "AWS SDK Go CreateBucket Failed", err).Fatal()
return
}
defer cleanup(s3Client, bucket, object, function, args, startTime)

req, _ := s3Client.PutObjectRequest(&s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(object),
Expand All @@ -161,15 +188,11 @@ func testPresignedPut(s3Client *s3.S3) {
failureLog(function, args, startTime, "", "AWS SDK Go presigned put request failed", err).Fatal()
return
}
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
failureLog(function, args, startTime, "", "AWS SDK Go reading response body failed", err).Fatal()
return
}
defer resp.Body.Close()

dec := xml.NewDecoder(resp.Body)
errResp := ErrorResponse{}
err = xml.Unmarshal(body, &errResp)
err = dec.Decode(&errResp)
if err != nil {
failureLog(function, args, startTime, "", "AWS SDK Go unmarshalling xml failed", err).Fatal()
return
Expand All @@ -179,6 +202,7 @@ func testPresignedPut(s3Client *s3.S3) {
failureLog(function, args, startTime, "", fmt.Sprintf("AWS SDK Go presigned PUT expected to fail with XAmzContentSHA256Mismatch but got %v", errResp.Code), errors.New("AWS S3 error code mismatch")).Fatal()
return
}

successLogger(function, args, startTime).Info()
}

Expand All @@ -189,7 +213,7 @@ func main() {
secure := os.Getenv("ENABLE_HTTPS")
sdkEndpoint := "http://" + endpoint
if secure == "1" {
sdkEndpoint = "https://"
sdkEndpoint = "https://" + endpoint
}

creds := credentials.NewStaticCredentials(accessKey, secretKey, "")
Expand All @@ -201,8 +225,6 @@ func main() {
S3ForcePathStyle: aws.Bool(true),
}

s3Config = s3Config.WithLogLevel(aws.LogDebug)

// Create an S3 service object in the default region.
s3Client := s3.New(newSession, s3Config)

Expand All @@ -215,5 +237,5 @@ func main() {
// log Info or above -- success cases are Info level, failures are Fatal level
log.SetLevel(log.InfoLevel)
// execute tests
testPresignedPut(s3Client)
testPresignedPutInvalidHash(s3Client)
}