Skip to content

Commit

Permalink
Merge pull request #1049 from versity/feat/sdk-tests-https
Browse files Browse the repository at this point in the history
Integration tests over https
  • Loading branch information
benmcclelland authored Feb 3, 2025
2 parents fd4bb8f + f35cdfb commit 1c9da26
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 241 deletions.
11 changes: 11 additions & 0 deletions cmd/versitygw/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
checksumDisable bool
versioningEnabled bool
azureTests bool
tlsStatus bool
)

func testCommand() *cli.Command {
Expand Down Expand Up @@ -79,6 +80,12 @@ func initTestFlags() []cli.Flag {
Aliases: []string{"d"},
Destination: &debug,
},
&cli.BoolFlag{
Name: "allow-insecure",
Usage: "skip tls verification",
Aliases: []string{"ai"},
Destination: &tlsStatus,
},
}
}

Expand Down Expand Up @@ -211,6 +218,7 @@ func initTestCommands() []*cli.Command {
integration.WithEndpoint(endpoint),
integration.WithConcurrency(concurrency),
integration.WithPartSize(partSize),
integration.WithTLSStatus(tlsStatus),
}
if debug {
opts = append(opts, integration.WithDebug())
Expand Down Expand Up @@ -271,6 +279,7 @@ func initTestCommands() []*cli.Command {
integration.WithRegion(region),
integration.WithEndpoint(endpoint),
integration.WithConcurrency(concurrency),
integration.WithTLSStatus(tlsStatus),
}
if debug {
opts = append(opts, integration.WithDebug())
Expand All @@ -296,6 +305,7 @@ func getAction(tf testFunc) func(*cli.Context) error {
integration.WithSecret(awsSecret),
integration.WithRegion(region),
integration.WithEndpoint(endpoint),
integration.WithTLSStatus(tlsStatus),
}
if debug {
opts = append(opts, integration.WithDebug())
Expand Down Expand Up @@ -333,6 +343,7 @@ func extractIntTests() (commands []*cli.Command) {
integration.WithSecret(awsSecret),
integration.WithRegion(region),
integration.WithEndpoint(endpoint),
integration.WithTLSStatus(tlsStatus),
}
if debug {
opts = append(opts, integration.WithDebug())
Expand Down
89 changes: 84 additions & 5 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ mkdir /tmp/versioning.covdata
rm -rf /tmp/versioningdir
mkdir /tmp/versioningdir

# setup tls certificate and key
ECHO "Generating TLS certificate and key in the cert.pem and key.pem files"

openssl genpkey -algorithm RSA -out key.pem -pkeyopt rsa_keygen_bits:2048
openssl req -new -x509 -key key.pem -out cert.pem -days 365 -subj "/C=US/ST=California/L=San Francisco/O=Versity/OU=Software/CN=versity.com"


ECHO "Running the sdk test over http"
# run server in background not versioning-enabled
# port: 7070(default)
GOCOVERDIR=/tmp/covdata ./versitygw -a user -s pass --iam-dir /tmp/gw posix /tmp/gw &
GW_PID=$!

sleep 1

# check if versioning-enabled gateway process is still running
# check if gateway process is still running
if ! kill -0 $GW_PID; then
echo "server no longer running"
exit 1
Expand Down Expand Up @@ -45,9 +53,48 @@ fi

kill $GW_PID

ECHO "Running the sdk test over https"

# run server in background with TLS certificate
# port: 7071(default)
GOCOVERDIR=/tmp/https.covdata ./versitygw --cert "$PWD/cert.pem" --key "$PWD/key.pem" -p :7071 -a user -s pass --iam-dir /tmp/gw posix /tmp/gw &
GW_HTTPS_PID=$!

sleep 1

# check if https gateway process is still running
if ! kill -0 $GW_HTTPS_PID; then
echo "server no longer running"
exit 1
fi

# run tests
# full flow tests
if ! ./versitygw test --allow-insecure -a user -s pass -e https://127.0.0.1:7071 full-flow; then
echo "full flow tests failed"
kill $GW_HTTPS_PID
exit 1
fi
# posix tests
if ! ./versitygw test --allow-insecure -a user -s pass -e https://127.0.0.1:7071 posix; then
echo "posix tests failed"
kill $GW_HTTPS_PID
exit 1
fi
# iam tests
if ! ./versitygw test --allow-insecure -a user -s pass -e https://127.0.0.1:7071 iam; then
echo "iam tests failed"
kill $GW_HTTPS_PID
exit 1
fi

kill $GW_HTTPS_PID


ECHO "Running the sdk test over http against the versioning-enabled gateway"
# run server in background versioning-enabled
# port: 7071
GOCOVERDIR=/tmp/versioning.covdata ./versitygw -p :7071 -a user -s pass --iam-dir /tmp/gw posix --versioning-dir /tmp/versioningdir /tmp/gw &
# port: 7072
GOCOVERDIR=/tmp/versioning.covdata ./versitygw -p :7072 -a user -s pass --iam-dir /tmp/gw posix --versioning-dir /tmp/versioningdir /tmp/gw &
GW_VS_PID=$!

# wait a second for server to start up
Expand All @@ -61,13 +108,13 @@ fi

# run tests
# full flow tests
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7071 full-flow -vs; then
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7072 full-flow -vs; then
echo "versioning-enabled full-flow tests failed"
kill $GW_VS_PID
exit 1
fi
# posix tests
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7071 posix -vs; then
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7072 posix -vs; then
echo "versiongin-enabled posix tests failed"
kill $GW_VS_PID
exit 1
Expand All @@ -76,6 +123,38 @@ fi
# kill off server
kill $GW_VS_PID

ECHO "Running the sdk test over https against the versioning-enabled gateway"
# run server in background versioning-enabled
# port: 7073
GOCOVERDIR=/tmp/versioning.https.covdata ./versitygw --cert "$PWD/cert.pem" --key "$PWD/key.pem" -p :7073 -a user -s pass --iam-dir /tmp/gw posix --versioning-dir /tmp/versioningdir /tmp/gw &
GW_VS_HTTPS_PID=$!

# wait a second for server to start up
sleep 1

# check if versioning-enabled gateway process is still running
if ! kill -0 $GW_VS_HTTPS_PID; then
echo "versioning-enabled server no longer running"
exit 1
fi

# run tests
# full flow tests
if ! ./versitygw test --allow-insecure -a user -s pass -e https://127.0.0.1:7073 full-flow -vs; then
echo "versioning-enabled full-flow tests failed"
kill $GW_VS_HTTPS_PID
exit 1
fi
# posix tests
if ! ./versitygw test --allow-insecure -a user -s pass -e https://127.0.0.1:7073 posix -vs; then
echo "versiongin-enabled posix tests failed"
kill $GW_VS_HTTPS_PID
exit 1
fi

# kill off server
kill $GW_VS_HTTPS_PID

exit 0

# if the above binary was built with -cover enabled (make testbin),
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/s3conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package integration

import (
"context"
"crypto/tls"
"io"
"log"
"net/http"
Expand All @@ -42,6 +43,8 @@ type S3Conf struct {
debug bool
versioningEnabled bool
azureTests bool
tlsStatus bool
httpClient *http.Client
}

func NewS3Conf(opts ...Option) *S3Conf {
Expand All @@ -50,6 +53,20 @@ func NewS3Conf(opts ...Option) *S3Conf {
for _, opt := range opts {
opt(s)
}

customTransport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: s.tlsStatus,
},
}

customHTTPClient := &http.Client{
Transport: customTransport,
Timeout: shortTimeout,
}

s.httpClient = customHTTPClient

return s
}

Expand Down Expand Up @@ -88,6 +105,9 @@ func WithVersioningEnabled() Option {
func WithAzureMode() Option {
return func(s *S3Conf) { s.azureTests = true }
}
func WithTLSStatus(ts bool) Option {
return func(s *S3Conf) { s.tlsStatus = ts }
}

func (c *S3Conf) getCreds() credentials.StaticCredentialsProvider {
// TODO support token/IAM
Expand Down Expand Up @@ -118,6 +138,8 @@ func (c *S3Conf) Config() aws.Config {
config.WithRetryMaxAttempts(1),
}

opts = append(opts, config.WithHTTPClient(c.httpClient))

if c.checksumDisable {
opts = append(opts,
config.WithAPIOptions([]func(*middleware.Stack) error{v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware}))
Expand Down Expand Up @@ -168,3 +190,11 @@ func (c *S3Conf) DownloadData(w io.WriterAt, bucket, object string) (int64, erro

return downloader.Download(context.Background(), w, downinfo)
}

func (c *S3Conf) getAdminCommand(args ...string) []string {
if c.tlsStatus {
return append([]string{"admin", "--allow-insecure"}, args...)
}

return append([]string{"admin"}, args...)
}
Loading

0 comments on commit 1c9da26

Please sign in to comment.