Skip to content

Commit

Permalink
fix: change gock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joel authored and joel committed Mar 8, 2024
1 parent 4f87068 commit 17e8e42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
11 changes: 7 additions & 4 deletions internal/api/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand All @@ -23,6 +24,8 @@ import (
"github.com/supabase/auth/internal/storage"
)

const SymmetricSignaturePrefix = "v1,"

func (a *API) runPostgresHook(ctx context.Context, tx *storage.Connection, name string, input, output any) ([]byte, error) {
db := a.db.WithContext(ctx)

Expand Down Expand Up @@ -157,10 +160,11 @@ func (a *API) runHTTPHook(hookConfig conf.ExtensibilityPointConfiguration, input
}

func generateSignatures(secrets []string, msgID uuid.UUID, currentTime time.Time, inputPayload []byte) ([]string, error) {
// TODO(joel): Handle asymmetric case once library has been upgraded
var signatureList []string
for _, secret := range secrets {
if strings.HasPrefix(secret, "v1,") {
trimmedSecret := strings.TrimPrefix(secret, "v1,")
if strings.HasPrefix(secret, SymmetricSignaturePrefix) {
trimmedSecret := strings.TrimPrefix(secret, SymmetricSignaturePrefix)
wh, err := standardwebhooks.NewWebhook(trimmedSecret)
if err != nil {
return nil, err
Expand All @@ -171,8 +175,7 @@ func generateSignatures(secrets []string, msgID uuid.UUID, currentTime time.Time
}
signatureList = append(signatureList, signature)
} else {
// TODO(joel): Handle asymmetric case once library has been upgraded
return nil, nil
return nil, errors.New("invalid signature format")
}
}
return signatureList, nil
Expand Down
32 changes: 13 additions & 19 deletions internal/api/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,20 @@ func TestHooks(t *testing.T) {

func (ts *HooksTestSuite) TestRunHTTPHook() {
defer gock.Off()
// mock hook url
// response := gock.New(twilioProvider.APIPath).Post("").
// body := CustomSMSProviderInput{}
//
// Test Case 1:
// testUrl := "http://localhost:54321/functions/v1/custom-sms-sender"
// response := gock.New(testUrl).Post("").
// MatchType("url").BodyString(body.Encode()).
// Reply(200).JSON(SmsStatus{
// // Add whether the API succeeded
// To: "+" + phone,
// From: twilioProvider.Config.MessageServiceSid,
// Status: "sent",
// Body: message,
// })

// for _, c := range cases {
// ts.Run(c.Desc, func() {
// // ts.a
// // _, err = twilioProvider.runHTTPHook(phone, message, SMSProvider, c.OTP)
// require.Equal(ts.T(), c.ExpectedError, err)
// })
// }
}
// Reply(200).JSON(CustomSMSProviderOutput{})

// Test Case 2: Too many requests MatchHeaders with retry-after header

// Test Case 3: too many requests w/o retry header should not retry

func TestGenerateSignature(t *testing.T) {
//_, err = ts.API.runHTTPHook(a.config.Hooks.CustomSMSProvider, input, output)
// require.NoError(ts.T(), err)

// Test the retry behaviour
}

0 comments on commit 17e8e42

Please sign in to comment.