Skip to content

Commit

Permalink
fix: use pointers for claims
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Apr 3, 2024
1 parent fcccdac commit 04e334e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
22 changes: 20 additions & 2 deletions integration_tests/internal_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,30 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() {
assert.Equal(suite.T(), responses.ReceiveExceededError.Message, resp.Message)

// remove volume and receive config and check if it works
suite.service.Config.MaxReceiveAmount = 0
suite.service.Config.MaxReceiveAmount = -1
invoiceResponse = suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken)
err = suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
assert.NoError(suite.T(), err)

// add max account
// check if setting zero as receive amount stops
suite.service.Config.MaxReceiveAmount = 0
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedAddInvoiceRequestBody{
Amount: aliceFundingSats,
Memo: "memo",
}))
req = httptest.NewRequest(http.MethodPost, "/addinvoice", &buf)
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.aliceToken))
suite.echo.ServeHTTP(rec, req)
//should fail because max receive amount check
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
resp = &responses.ErrorResponse{}
err = json.NewDecoder(rec.Body).Decode(resp)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), responses.ReceiveExceededError.Message, resp.Message)

// remove max receive and add max account
suite.service.Config.MaxReceiveAmount = -1
suite.service.Config.MaxAccountBalance = 500
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedAddInvoiceRequestBody{
Amount: aliceFundingSats,
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *servi
JWTSecret: []byte("SECRET"),
JWTAccessTokenExpiry: 3600,
JWTRefreshTokenExpiry: 3600,
MaxSendAmount: -1,
MaxSendVolume: -1,
MaxReceiveAmount: -1,
MaxReceiveVolume: -1,
}

rabbitmqUri, ok := os.LookupEnv("RABBITMQ_URI")
Expand Down
16 changes: 8 additions & 8 deletions lib/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,17 @@ func (svc *LndhubService) GetLimits(c echo.Context) (limits *Limits) {
MaxReceiveAmount: svc.Config.MaxReceiveAmount,
MaxAccountBalance: svc.Config.MaxAccountBalance,
}
if val, ok := c.Get("MaxSendVolume").(int64); ok && val >= -1 {
limits.MaxSendVolume = val
if val, ok := c.Get("MaxSendVolume").(*int64); ok && val != nil {
limits.MaxSendVolume = *val
}
if val, ok := c.Get("MaxSendAmount").(int64); ok && val >= -1 {
limits.MaxSendAmount = val
if val, ok := c.Get("MaxSendAmount").(*int64); ok && val != nil {
limits.MaxSendAmount = *val
}
if val, ok := c.Get("MaxReceiveVolume").(int64); ok && val >= -1 {
limits.MaxReceiveVolume = val
if val, ok := c.Get("MaxReceiveVolume").(*int64); ok && val != nil {
limits.MaxReceiveVolume = *val
}
if val, ok := c.Get("MaxReceiveAmount").(int64); ok && val >= -1 {
limits.MaxReceiveAmount = val
if val, ok := c.Get("MaxReceiveAmount").(*int64); ok && val != nil {
limits.MaxReceiveAmount = *val
}
if val, ok := c.Get("MaxAccountBalance").(int64); ok && val > 0 {
limits.MaxAccountBalance = val
Expand Down
14 changes: 7 additions & 7 deletions lib/tokens/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
)

type jwtCustomClaims struct {
ID int64 `json:"id"`
IsRefresh bool `json:"isRefresh"`
MaxSendVolume int64 `json:"maxSendVolume"`
MaxSendAmount int64 `json:"maxSendAmount"`
MaxReceiveVolume int64 `json:"maxReceiveVolume"`
MaxReceiveAmount int64 `json:"maxReceiveAmount"`
MaxAccountBalance int64 `json:"maxAccountBalance"`
ID int64 `json:"id"`
IsRefresh bool `json:"isRefresh"`
MaxSendVolume *int64 `json:"maxSendVolume,omitempty"`
MaxSendAmount *int64 `json:"maxSendAmount,omitempty"`
MaxReceiveVolume *int64 `json:"maxReceiveVolume,omitempty"`
MaxReceiveAmount *int64 `json:"maxReceiveAmount,omitempty"`
MaxAccountBalance int64 `json:"maxAccountBalance"`
jwt.StandardClaims
}

Expand Down

0 comments on commit 04e334e

Please sign in to comment.