Skip to content
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

Production 2024-07-18_01 #2604

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/grant/cmd/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func GrantServer(
srv := http.Server{
Addr: ":3333",
Handler: chi.ServerBaseContext(ctx, r),
ReadTimeout: 3 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 20 * time.Second,
}
err = srv.ListenAndServe()
Expand Down
16 changes: 10 additions & 6 deletions services/skus/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Router(

// For now, this endpoint is placed directly under /credentials.
// It would make sense to put it under /items/item_id, had the caller known the item id.
// However, the caller of this endpoit does not posses that knowledge, and it would have to call the order endpoint to get it.
// However, the caller of this endpoint does not possess that knowledge, and it would have to call the order endpoint to get it.
// This extra round-trip currently does not make sense.
// So until Bundles came along we can benefit from the fact that there is one item per order.
// By the time Bundles arrive, the caller would either have to fetch order anyway, or this can be communicated in another way.
Expand Down Expand Up @@ -623,15 +623,19 @@ type createItemCredsRequest struct {
// createItemCreds handles requests for creating credentials for an item.
func createItemCreds(svc *Service) handlers.AppHandler {
return func(w http.ResponseWriter, r *http.Request) *handlers.AppError {
ctx := r.Context()
lg := logging.Logger(ctx, "skus.createItemCreds")
b, err := io.ReadAll(io.LimitReader(r.Body, reqBodyLimit10MB))
if err != nil {
return handlers.WrapError(err, "error reading body", http.StatusBadRequest)
}

req := &createItemCredsRequest{}
if err := requestutils.ReadJSON(ctx, r.Body, req); err != nil {
lg.Error().Err(err).Msg("failed to read body payload")
return handlers.WrapError(err, "Error in request body", http.StatusBadRequest)
if err := json.Unmarshal(b, req); err != nil {
return handlers.WrapError(err, "error decoding body", http.StatusBadRequest)
}

ctx := r.Context()
lg := logging.Logger(ctx, "skus.createItemCreds")

if _, err := govalidator.ValidateStruct(req); err != nil {
lg.Error().Err(err).Msg("failed to validate struct")
return handlers.WrapValidationError(err)
Expand Down
4 changes: 2 additions & 2 deletions services/skus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ func (s *Service) processAppStoreNotificationTx(ctx context.Context, dbi sqlx.Ex

switch {
case ntf.shouldRenew():
expt := time.UnixMilli(txn.ExpiresDate).UTC()
expt := time.UnixMilli(txn.ExpiresDate).UTC().Add(24 * time.Hour)
paidt := time.Now()

return s.renewOrderWithExpPaidTime(ctx, dbi, ord.ID, expt, paidt)
Expand Down Expand Up @@ -1748,7 +1748,7 @@ func (s *Service) processPlayStoreNotificationTx(ctx context.Context, dbi sqlx.E
return err
}

expt := time.UnixMilli(sub.ExpiryTimeMillis).UTC()
expt := time.UnixMilli(sub.ExpiryTimeMillis).UTC().Add(24 * time.Hour)
paidt := time.Now()

return s.renewOrderWithExpPaidTime(ctx, dbi, ord.ID, expt, paidt)
Expand Down
33 changes: 29 additions & 4 deletions services/skus/service_nonint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,26 @@ func TestService_processPlayStoreNotificationTx(t *testing.T) {
SubID: "nightly.bravevpn.monthly",
},
},
orepo: &repository.MockOrder{},
orepo: &repository.MockOrder{
FnSetExpiresAt: func(ctx context.Context, dbi sqlx.ExecerContext, id uuid.UUID, when time.Time) error {
if when.Equal(time.Date(2024, time.July, 2, 0, 0, 0, 0, time.UTC)) {
return nil
}

return model.Error("unexpected")
},
},
prepo: &repository.MockOrderPayHistory{},
pscl: &mockPSClient{},
pscl: &mockPSClient{
fnVerifySubscription: func(ctx context.Context, pkgName, subID, token string) (*androidpublisher.SubscriptionPurchase, error) {
result := &androidpublisher.SubscriptionPurchase{
PaymentState: ptrTo[int64](1),
ExpiryTimeMillis: time.Date(2024, time.July, 1, 0, 0, 0, 0, time.UTC).UnixMilli(),
}

return result, nil
},
},
},
},

Expand Down Expand Up @@ -558,10 +575,18 @@ func TestService_processAppStoreNotificationTx(t *testing.T) {
},
txn: &appstore.JWSTransactionDecodedPayload{
OriginalTransactionId: "123456789000001",
ExpiresDate: 1704067201000,
ExpiresDate: 1704067200000,
},

orepo: &repository.MockOrder{},
orepo: &repository.MockOrder{
FnSetExpiresAt: func(ctx context.Context, dbi sqlx.ExecerContext, id uuid.UUID, when time.Time) error {
if when.Equal(time.Date(2024, time.January, 2, 0, 0, 0, 0, time.UTC)) {
return nil
}

return model.Error("unexpected")
},
},
prepo: &repository.MockOrderPayHistory{},
},
},
Expand Down
Loading