-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(SPV-1248) add domain check for paymail entry #828
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package admin | |||||
import ( | ||||||
"net/http" | ||||||
|
||||||
"github.com/bitcoin-sv/go-paymail" | ||||||
"github.com/bitcoin-sv/spv-wallet/actions/common" | ||||||
"github.com/bitcoin-sv/spv-wallet/engine" | ||||||
"github.com/bitcoin-sv/spv-wallet/engine/spverrors" | ||||||
|
@@ -130,6 +131,15 @@ func paymailCreateAddress(c *gin.Context, _ *reqctx.AdminContext) { | |||||
opts = append(opts, engine.WithMetadatas(requestBody.Metadata)) | ||||||
} | ||||||
|
||||||
config := reqctx.AppConfig(c) | ||||||
if config.Paymail.DomainValidationEnabled { | ||||||
_, actualDomain, _ := paymail.SanitizePaymail(requestBody.Address) | ||||||
if !checkPaymailDomain(actualDomain, config.Paymail.Domains) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could simply use
Suggested change
|
||||||
spverrors.ErrorResponse(c, spverrors.ErrInvalidDomain, logger) | ||||||
return | ||||||
} | ||||||
} | ||||||
|
||||||
var paymailAddress *engine.PaymailAddress | ||||||
paymailAddress, err := reqctx.Engine(c).NewPaymailAddress( | ||||||
c.Request.Context(), requestBody.Key, requestBody.Address, requestBody.PublicName, requestBody.Avatar, opts...) | ||||||
|
@@ -143,6 +153,15 @@ func paymailCreateAddress(c *gin.Context, _ *reqctx.AdminContext) { | |||||
c.JSON(http.StatusCreated, paymailAddressContract) | ||||||
} | ||||||
|
||||||
func checkPaymailDomain(domain string, domains []string) bool { | ||||||
for _, d := range domains { | ||||||
if d == domain { | ||||||
return true | ||||||
} | ||||||
} | ||||||
return false | ||||||
} | ||||||
|
||||||
// paymailDeleteAddress will delete a paymail address | ||||||
// Delete Paymail godoc | ||||||
// @Summary Delete paymail | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package admin | |
import ( | ||
"net/http" | ||
|
||
"github.com/bitcoin-sv/go-paymail" | ||
"github.com/bitcoin-sv/spv-wallet/engine" | ||
"github.com/bitcoin-sv/spv-wallet/engine/spverrors" | ||
"github.com/bitcoin-sv/spv-wallet/mappings" | ||
|
@@ -163,6 +164,15 @@ func paymailCreateAddressOld(c *gin.Context, _ *reqctx.AdminContext) { | |
opts = append(opts, engine.WithMetadatas(requestBody.Metadata)) | ||
} | ||
|
||
config := reqctx.AppConfig(c) | ||
if config.Paymail.DomainValidationEnabled { | ||
_, actualDomain, _ := paymail.SanitizePaymail(requestBody.Address) | ||
if !checkPaymailDomain(actualDomain, config.Paymail.Domains) { | ||
spverrors.ErrorResponse(c, spverrors.ErrInvalidDomain, logger) | ||
return | ||
} | ||
} | ||
Comment on lines
+167
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated code. |
||
|
||
var paymailAddress *engine.PaymailAddress | ||
paymailAddress, err := reqctx.Engine(c).NewPaymailAddress( | ||
c.Request.Context(), requestBody.Key, requestBody.Address, requestBody.PublicName, requestBody.Avatar, opts...) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO PR is a good opportunity to write some endpoint tests for create paymail address endpoint.