Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Create e2e-runner service. #417

Merged
merged 5 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ cmd/add-users/add-users
cmd/adminapi/adminapi
cmd/apiserver/apiserver
cmd/cleanup/cleanup
cmd/e2e-runner/e2e-runner
cmd/get-certificate/get-certificate
cmd/get-code/get-code
cmd/get-token/get-token
cmd/migrate/migrate
cmd/server/server
tools/e2e-test/e2e-test
tools/gen-secret/gen-secret
tools/seed/seed

Expand Down
24 changes: 23 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,32 @@ steps:
'push',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/adminapi:${SHORT_SHA}',
]
- id: 'e2e-runner'
name: 'docker'
timeout: 10m
waitFor: ["-"]
args: [
'build',
'--tag',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/apiserver:${SHORT_SHA}',
'--build-arg',
'SERVICE=e2e-runner',
'.',
]
- id: 'e2e-runner:publish'
name: 'docker'
waitFor:
- e2e-runner
args: [
'push',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/apiserver:${SHORT_SHA}',
]
- id: 'deploy'
waitFor:
- 'adminapi:publish'
- 'apiserver:publish'
- 'cleanup:publish'
- 'e2e-runner:publish'
- 'server:publish'
name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:alpine'
args:
Expand All @@ -96,7 +117,7 @@ steps:
- '-c'
- |-
gcloud components install --quiet beta;
SERVICES=(adminapi apiserver cleanup server);
SERVICES=(adminapi apiserver cleanup server e2e-runner);
for s in "${SERVICES[@]}"; do
gcloud beta run deploy "${s}" \
--quiet \
Expand All @@ -112,4 +133,5 @@ images: [
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/apiserver:${SHORT_SHA}',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/cleanup:${SHORT_SHA}',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/adminapi:${SHORT_SHA}',
'gcr.io/${PROJECT_ID}/github.com/google/exposure-notifications-verification-server/cmd/e2e-runner:${SHORT_SHA}',
]
99 changes: 29 additions & 70 deletions tools/e2e-test/main.go → cmd/e2e-runner/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Command line test that exercises the verification and key server,
// simulating a mobile device uploading TEKs.
//
// E2E test code that exercises the verification and key server, simulating a
// mobile device uploading TEKs.
//
package main

import (
"context"
"encoding/base64"
"flag"
"fmt"
"net/http"
"os"
"strconv"
"time"

"github.com/google/exposure-notifications-verification-server/pkg/clients"
"github.com/google/exposure-notifications-verification-server/pkg/config"
"github.com/google/exposure-notifications-verification-server/pkg/jsonclient"

verifyapi "github.com/google/exposure-notifications-server/pkg/api/v1"
"github.com/google/exposure-notifications-server/pkg/logging"
"github.com/google/exposure-notifications-server/pkg/util"
"github.com/google/exposure-notifications-server/pkg/verification"

"github.com/sethvargo/go-envconfig"
"github.com/sethvargo/go-signalcontext"
)

type Config struct {
VerificationAdminAPIServer string `env:"VERIFICATION_ADMIN_API, default=http://localhost:8081"`
VerificationAdminAPIKey string `env:"VERIFICATION_ADMIN_API_KEY,required"`
VerificationAPIServer string `env:"VERIFICATION_SERVER_API, default=http://localhost:8082"`
VerificationAPIServerKey string `env:"VERIFICATION_SERVER_API_KEY,required"`
KeyServer string `env:"KEY_SERVER, default=http://localhost:8080"`
HealthAuthorityCode string `env:"HEALTH_AUTHORITY_CODE,required"`

// Publish config
Region string `env:"REGION,default=US"`
}

const (
timeout = 2 * time.Second
oneDay = 24 * time.Hour
Expand All @@ -63,36 +45,12 @@ func timeToInterval(t time.Time) int32 {
return int32(t.UTC().Truncate(oneDay).Unix() / int64(intervalLength.Seconds()))
}

func main() {
ctx, done := signalcontext.OnInterrupt()

debug, _ := strconv.ParseBool(os.Getenv("LOG_DEBUG"))
logger := logging.NewLogger(debug)
ctx = logging.WithLogger(ctx, logger)

err := realMain(ctx)
done()

if err != nil {
logger.Fatal(err)
}
logger.Info("successful shutdown")
}

func realMain(ctx context.Context) error {
func e2e(ctx context.Context, config config.E2ERunnerConfig) error {
logger := logging.FromContext(ctx)
var config Config
if err := envconfig.ProcessWith(ctx, &config, envconfig.OsLookuper()); err != nil {
return fmt.Errorf("unable to process environment: %w", err)
}

doRevision := flag.Bool("revise", false, "--revise means to do a likely diagnosis and then revise to confirmed. one new key is added in between.")
verbose := flag.Bool("v", false, "ALL THE MESSAGES!")
flag.Parse()

testType := "confirmed"
iterations := 1
if *doRevision {
if config.DoRevise {
testType = "likely"
iterations++
}
Expand Down Expand Up @@ -122,10 +80,11 @@ func realMain(ctx context.Context) error {
} else if code.Error != "" {
return fmt.Errorf("issue API Error: %+v", code)
}
if *verbose {
logger.Infof("Code Request: %+v", codeRequest)
logger.Infof("Code Response: %+v", code)
}

logger.Debugw("Issue Code",
"request", codeRequest,
"response", code,
)

// Get the verification token
logger.Infof("Verifying code and getting token")
Expand All @@ -135,10 +94,10 @@ func realMain(ctx context.Context) error {
} else if token.Error != "" {
return fmt.Errorf("verification API Error %+v", token)
}
if *verbose {
logger.Infof("Token Request: %+v", tokenRequest)
logger.Infof("Token Response: %+v", token)
}
logger.Debugw("getting token",
"request", tokenRequest,
"response", token,
)

logger.Infof("Check code status")
statusReq, codeStatus, err := clients.CheckCodeStatus(ctx, config.VerificationAdminAPIServer, config.VerificationAdminAPIKey, code.UUID, timeout)
Expand All @@ -147,10 +106,10 @@ func realMain(ctx context.Context) error {
} else if codeStatus.Error != "" {
return fmt.Errorf("check code status Error: %+v", codeStatus)
}
if *verbose {
logger.Infof("Code Status Request: %+v", statusReq)
logger.Infof("Code Status Response: %+v", codeStatus)
}
logger.Debugw("check code status",
"request", statusReq,
"response", codeStatus,
)
if !codeStatus.Claimed {
return fmt.Errorf("expected claimed OTP code for %s", statusReq.UUID)
}
Expand All @@ -169,10 +128,10 @@ func realMain(ctx context.Context) error {
} else if certificate.Error != "" {
return fmt.Errorf("certificate API Error: %+v", certificate)
}
if *verbose {
logger.Infof("Certificate Request: %+v", certRequest)
logger.Infof("Certificate Response: %+v", certificate)
}
logger.Debugw("get certificate",
"request", certRequest,
"response", certificate,
)

// Upload the TEKs
publish := verifyapi.Publish{
Expand All @@ -189,20 +148,20 @@ func realMain(ctx context.Context) error {
client := &http.Client{
Timeout: timeout,
}
if *verbose {
logger.Infof("Publish request: %+v", publish)
}
logger.Debugw("publish",
"request", publish,
)
if err := jsonclient.MakeRequest(ctx, client, config.KeyServer, http.Header{}, &publish, &response); err != nil {
return fmt.Errorf("error publishing teks: %w", err)
} else if response.ErrorMessage != "" {
return fmt.Errorf("publish API error: %+v", response)
}
logger.Infof("Inserted %v exposures", response.InsertedExposures)
if *verbose {
logger.Infof("Publish response: %+v", response)
}
logger.Debugw("publish",
"response", response,
)

if *doRevision {
if config.DoRevise {
testType = "confirmed"
revisionToken = response.RevisionToken

Expand Down
Loading