From 62a60d7d5104db110f3d33a1281b72f7d317d1a6 Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Wed, 13 Sep 2023 14:08:43 -0700 Subject: [PATCH 1/4] make allowed-source-account optional --- exp/services/recoverysigner/internal/serve/serve.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exp/services/recoverysigner/internal/serve/serve.go b/exp/services/recoverysigner/internal/serve/serve.go index 88a4200377..8b5b856bfe 100644 --- a/exp/services/recoverysigner/internal/serve/serve.go +++ b/exp/services/recoverysigner/internal/serve/serve.go @@ -145,12 +145,14 @@ func getHandlerDeps(opts Options) (handlerDeps, error) { } allowedSourceAccounts := []*keypair.FromAddress{} - for _, addressStr := range strings.Split(opts.AllowedSourceAccounts, ",") { - accountAddress, err := keypair.ParseAddress(addressStr) - if err != nil { - return handlerDeps{}, errors.Wrap(err, "parsing allowed source accounts") + if opts.AllowedSourceAccounts != "" { + for _, addressStr := range strings.Split(opts.AllowedSourceAccounts, ",") { + accountAddress, err := keypair.ParseAddress(addressStr) + if err != nil { + return handlerDeps{}, errors.Wrap(err, "parsing allowed source accounts") + } + allowedSourceAccounts = append(allowedSourceAccounts, accountAddress) } - allowedSourceAccounts = append(allowedSourceAccounts, accountAddress) } deps := handlerDeps{ From d3f8522aa0e130e2d8e1a77dcf68964ab2e6aaf1 Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Wed, 13 Sep 2023 16:52:26 -0700 Subject: [PATCH 2/4] add a test --- .../internal/serve/serve_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 exp/services/recoverysigner/internal/serve/serve_test.go diff --git a/exp/services/recoverysigner/internal/serve/serve_test.go b/exp/services/recoverysigner/internal/serve/serve_test.go new file mode 100644 index 0000000000..db40d80390 --- /dev/null +++ b/exp/services/recoverysigner/internal/serve/serve_test.go @@ -0,0 +1,35 @@ +package serve + +import ( + "encoding/json" + "testing" + + "github.com/stellar/go/keypair" + supportlog "github.com/stellar/go/support/log" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/square/go-jose.v2" +) + +func TestGetHandlerDeps(t *testing.T) { + signingKey := "SBWLXUTJR2CGVPGCZDIGGLQDPX7ZGGBHBFXBJ555MNIQ2PZCCLM643Z3" + signingKeyFull := keypair.MustParseFull(signingKey) + + opts := Options{ + Logger: supportlog.DefaultLogger, + SigningKeys: signingKey, + SEP10JWKS: `{"keys":[{"kty":"EC","crv":"P-256","alg":"ES256","x":"i8chX_7Slm4VQ_Y6XBWVBnxIO5-XSWH1GJsXWNkal3E","y":"G22r0OgrcQnkfCAqsS6wvtHgR0SbfvXNJy6-jJfvc94"}]}`, + } + + sep10JWKS := jose.JSONWebKeySet{} + err := json.Unmarshal([]byte(opts.SEP10JWKS), &sep10JWKS) + require.NoError(t, err) + + got, err := getHandlerDeps(opts) + assert.NoError(t, err) + + assert.Equal(t, []*keypair.Full{signingKeyFull}, got.SigningKeys) + assert.Equal(t, []*keypair.FromAddress{signingKeyFull.FromAddress()}, got.SigningAddresses) + assert.Equal(t, sep10JWKS, got.SEP10JWKS) + assert.Equal(t, []*keypair.FromAddress{}, got.AllowedSourceAccounts) +} From 4814a84dc0ebde8c242b786ec848ece3a053f0b2 Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Wed, 13 Sep 2023 17:08:56 -0700 Subject: [PATCH 3/4] break the line down --- exp/services/recoverysigner/internal/serve/serve_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exp/services/recoverysigner/internal/serve/serve_test.go b/exp/services/recoverysigner/internal/serve/serve_test.go index db40d80390..237fc047d5 100644 --- a/exp/services/recoverysigner/internal/serve/serve_test.go +++ b/exp/services/recoverysigner/internal/serve/serve_test.go @@ -18,7 +18,8 @@ func TestGetHandlerDeps(t *testing.T) { opts := Options{ Logger: supportlog.DefaultLogger, SigningKeys: signingKey, - SEP10JWKS: `{"keys":[{"kty":"EC","crv":"P-256","alg":"ES256","x":"i8chX_7Slm4VQ_Y6XBWVBnxIO5-XSWH1GJsXWNkal3E","y":"G22r0OgrcQnkfCAqsS6wvtHgR0SbfvXNJy6-jJfvc94"}]}`, + SEP10JWKS: `{"keys":[{"kty":"EC","crv":"P-256","alg":"ES256",` + + `"x":"i8chX_7Slm4VQ_Y6XBWVBnxIO5-XSWH1GJsXWNkal3E","y":"G22r0OgrcQnkfCAqsS6wvtHgR0SbfvXNJy6-jJfvc94"}]}`, } sep10JWKS := jose.JSONWebKeySet{} From f96d62fd26d8ae9ef2c96e0c92e9c77d2f8b329d Mon Sep 17 00:00:00 2001 From: Howard Chen Date: Wed, 13 Sep 2023 17:10:31 -0700 Subject: [PATCH 4/4] Revert "break the line down" This reverts commit 4814a84dc0ebde8c242b786ec848ece3a053f0b2. --- exp/services/recoverysigner/internal/serve/serve_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exp/services/recoverysigner/internal/serve/serve_test.go b/exp/services/recoverysigner/internal/serve/serve_test.go index 237fc047d5..db40d80390 100644 --- a/exp/services/recoverysigner/internal/serve/serve_test.go +++ b/exp/services/recoverysigner/internal/serve/serve_test.go @@ -18,8 +18,7 @@ func TestGetHandlerDeps(t *testing.T) { opts := Options{ Logger: supportlog.DefaultLogger, SigningKeys: signingKey, - SEP10JWKS: `{"keys":[{"kty":"EC","crv":"P-256","alg":"ES256",` + - `"x":"i8chX_7Slm4VQ_Y6XBWVBnxIO5-XSWH1GJsXWNkal3E","y":"G22r0OgrcQnkfCAqsS6wvtHgR0SbfvXNJy6-jJfvc94"}]}`, + SEP10JWKS: `{"keys":[{"kty":"EC","crv":"P-256","alg":"ES256","x":"i8chX_7Slm4VQ_Y6XBWVBnxIO5-XSWH1GJsXWNkal3E","y":"G22r0OgrcQnkfCAqsS6wvtHgR0SbfvXNJy6-jJfvc94"}]}`, } sep10JWKS := jose.JSONWebKeySet{}