Skip to content

Commit

Permalink
xyzabc fix linking payload (#1881)
Browse files Browse the repository at this point in the history
* remove deposit id from linking for xyzabc, fix json for linkingInfo in payload

typo

* Fix tests (#1882)

---------

Co-authored-by: Pavel Brm <[email protected]>
  • Loading branch information
husobee and pavelbrm authored Jul 6, 2023
1 parent f78ecbe commit edc7b85
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion services/wallet/controllers_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func LinkXyzAbcDepositAccountV3(s *Service) func(w http.ResponseWriter, r *http.
return HandleErrorsXyzAbc(err)
}

if err := s.LinkXyzAbcWallet(ctx, *id.UUID(), xalr.VerificationToken, xalr.DepositID); err != nil {
if err := s.LinkXyzAbcWallet(ctx, *id.UUID(), xalr.VerificationToken); err != nil {
if errors.Is(err, errorutils.ErrInvalidCountry) {
return handlers.WrapError(err, "region not supported", http.StatusBadRequest)
}
Expand Down
11 changes: 5 additions & 6 deletions services/wallet/controllers_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func TestLinkXyzAbcWalletV3(t *testing.T) {
ctx = context.WithValue(ctx, appctx.XyzAbcLinkingKeyCTXKey, base64.StdEncoding.EncodeToString(secret))

linkingInfo, err := jwt.Signed(sig).Claims(map[string]interface{}{
"accountId": accountID, "deposit_id": idTo,
"accountId": accountID, "depositId": idTo,
}).CompactSerialize()
if err != nil {
panic(err)
Expand All @@ -750,11 +750,10 @@ func TestLinkXyzAbcWalletV3(t *testing.T) {
r := httptest.NewRequest(
"POST",
fmt.Sprintf("/v3/wallet/xyzabc/%s/claim", idFrom),
bytes.NewBufferString(fmt.Sprintf(`
{
"linking_info": "%s",
"deposit_id": "%s"
}`, linkingInfo, idTo)),
bytes.NewBufferString(fmt.Sprintf(
`{"linkingInfo": "%s"}`,
linkingInfo,
)),
)

mockReputationClient.EXPECT().IsLinkingReputable(
Expand Down
3 changes: 1 addition & 2 deletions services/wallet/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ func (lbdar *LinkBraveDepositAccountRequest) HandleErrors(err error) *handlers.A

// XyzAbcLinkingRequest holds info needed to link xyzabc account.
type XyzAbcLinkingRequest struct {
VerificationToken string `json:"linking_info"`
DepositID string `json:"deposit_id"`
VerificationToken string `json:"linkingInfo"`
}

// Validate implements DecodeValidate interface.
Expand Down
9 changes: 5 additions & 4 deletions services/wallet/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func (service *Service) LinkBitFlyerWallet(ctx context.Context, walletID uuid.UU
}

// LinkXyzAbcWallet links a wallet and transfers funds to newly linked wallet.
func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID, verificationToken, depositID string) error {
func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID, verificationToken string) error {
// Get xyzabc linking_info signing key.
linkingKeyB64, ok := ctx.Value(appctx.XyzAbcLinkingKeyCTXKey).(string)
if !ok {
Expand Down Expand Up @@ -439,8 +439,9 @@ func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID
return handlers.WrapError(appctx.ErrNotInContext, msg, http.StatusBadRequest)
}

// Make sure deposit id matches claims.
if dID, ok := claims["depositId"].(string); ok && dID != depositID {
// Make sure deposit id exists
depositID, ok := claims["depositId"].(string)
if !ok || depositID == "" {
const msg = "xyzabc deposit id does not match token"
return handlers.WrapError(appctx.ErrNotInContext, msg, http.StatusBadRequest)
}
Expand All @@ -455,7 +456,7 @@ func (service *Service) LinkXyzAbcWallet(ctx context.Context, walletID uuid.UUID
providerLinkingID := uuid.NewV5(ClaimNamespace, accountID)

// tx.Destination will be stored as UserDepositDestination in the wallet info upon linking.
// FIXME
// FIXME - correct country
if err := service.Datastore.LinkWallet(ctx, walletID.String(), depositID, providerLinkingID, nil, "xyzabc", "US"); err != nil {
if errors.Is(err, ErrUnusualActivity) {
return handlers.WrapError(err, "unable to link - unusual activity", http.StatusBadRequest)
Expand Down

0 comments on commit edc7b85

Please sign in to comment.