From a132016df35890b75ffbea07b7ce3b106176cec3 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 17 Feb 2021 14:18:22 -0500 Subject: [PATCH] Move sms setup to docs, fix test --- internal/envstest/integration.go | 45 +++++++++++++++++++++++++++++ pkg/integration/integration_test.go | 3 ++ 2 files changed, 48 insertions(+) diff --git a/internal/envstest/integration.go b/internal/envstest/integration.go index 9ddf043cc..47adee69b 100644 --- a/internal/envstest/integration.go +++ b/internal/envstest/integration.go @@ -15,6 +15,7 @@ package envstest import ( + "os" "testing" "github.com/google/exposure-notifications-verification-server/internal/clients" @@ -56,6 +57,50 @@ func NewIntegrationSuite(tb testing.TB, testDatabaseInstance *database.TestInsta } }) + // Configure SMS + if !project.SkipE2ESMS { + realm := resp.Realm + twilioAccountSid := os.Getenv("TWILIO_ACCOUNT_SID") + twilioAuthToken := os.Getenv("TWILIO_AUTH_TOKEN") + if twilioAccountSid == "" { + tb.Fatalf("missing TWILIO_ACCOUNT_SID or set E2E_SKIP_SMS to skip") + } + if twilioAuthToken == "" { + tb.Fatalf("missing TWILIO_AUTH_TOKEN or set E2E_SKIP_SMS to skip") + } + + has, err := resp.Realm.HasSMSConfig(db) + if err != nil { + tb.Fatalf("failed to check if realm has sms config: %s", err) + } + if !has { + smsConfig := &database.SMSConfig{ + RealmID: realm.ID, + ProviderType: "TWILIO", + TwilioAccountSid: twilioAccountSid, + TwilioAuthToken: twilioAuthToken, + TwilioFromNumber: "+15005550006", + } + if err := db.SaveSMSConfig(smsConfig); err != nil { + tb.Fatalf("failed to save sms config: %v", err) + } + } + + if _, err := realm.CurrentSMSSigningKey(db); err != nil { + if !database.IsNotFound(err) { + tb.Fatalf("failed to find current sms signing key: %s", err) + } + + if _, err := realm.CreateSMSSigningKeyVersion(ctx, db, database.SystemTest); err != nil { + tb.Fatalf("failed to create signing key: %s", err) + } + + if _, err = realm.CurrentSMSSigningKey(db); err != nil { + tb.Fatalf("failed to find current sms signing key after creation: %v", err) + } + } + } + adminAPIServer := adminAPIServerConfig.NewServer(tb) apiServer := apiServerConfig.NewServer(tb) diff --git a/pkg/integration/integration_test.go b/pkg/integration/integration_test.go index ff7d136d3..7ad75864c 100644 --- a/pkg/integration/integration_test.go +++ b/pkg/integration/integration_test.go @@ -73,6 +73,9 @@ func TestIntegration(t *testing.T) { TestType: testType, SymptomDate: symptomDate, } + if !project.SkipE2ESMS { + issueReq.Phone = project.TestPhoneNumber + } issueResp, err := adminAPIClient.IssueCode(ctx, issueReq) if err != nil { t.Fatalf("failed to issue code: %#v\n req: %#v\n resp: %#v", err, issueReq, issueResp)