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

Commit

Permalink
Move sms setup to docs, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Feb 17, 2021
1 parent a349c26 commit a132016
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/envstest/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package envstest

import (
"os"
"testing"

"github.com/google/exposure-notifications-verification-server/internal/clients"
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pkg/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a132016

Please sign in to comment.