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

fix: use order id and item id in submission report #2644

Merged
merged 1 commit into from
Aug 22, 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/skus/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (s *Service) doTLV2ExistTxTime(ctx context.Context, dbi sqlx.QueryerContext
}

// Check TLV2 to see if we have credentials signed that match incoming blinded tokens.
report, err := s.tlv2Repo.GetCredSubmissionReport(ctx, dbi, reqID, bcreds...)
report, err := s.tlv2Repo.GetCredSubmissionReport(ctx, dbi, item.OrderID, item.ID, reqID, bcreds...)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion services/skus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type orderStoreSvc interface {
}

type tlv2Store interface {
GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error)
GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error)
UniqBatches(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID uuid.UUID, from, to time.Time) (int, error)
DeleteLegacy(ctx context.Context, dbi sqlx.ExecerContext, orderID uuid.UUID) error
}
Expand Down
6 changes: 3 additions & 3 deletions services/skus/service_nonint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ func TestService_doTLV2ExistTxTime(t *testing.T) {
from: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
to: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
repo: &repository.MockTLV2{
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
return model.TLV2CredSubmissionReport{}, model.Error("something_went_wrong")
},
},
Expand All @@ -1904,7 +1904,7 @@ func TestService_doTLV2ExistTxTime(t *testing.T) {
from: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
to: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
repo: &repository.MockTLV2{
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
return model.TLV2CredSubmissionReport{Submitted: true}, nil
},
},
Expand All @@ -1925,7 +1925,7 @@ func TestService_doTLV2ExistTxTime(t *testing.T) {
from: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
to: time.Date(2024, time.January, 1, 0, 0, 1, 0, time.UTC),
repo: &repository.MockTLV2{
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
FnGetCredSubmissionReport: func(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
return model.TLV2CredSubmissionReport{ReqIDMismatch: true}, nil
},
},
Expand Down
6 changes: 3 additions & 3 deletions services/skus/storage/repository/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ func (r *MockOrderPayHistory) Insert(ctx context.Context, dbi sqlx.ExecerContext
}

type MockTLV2 struct {
FnGetCredSubmissionReport func(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error)
FnGetCredSubmissionReport func(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error)
FnUniqBatches func(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID uuid.UUID, from, to time.Time) (int, error)
FnDeleteLegacy func(ctx context.Context, dbi sqlx.ExecerContext, orderID uuid.UUID) error
}

func (r *MockTLV2) GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
func (r *MockTLV2) GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
if r.FnGetCredSubmissionReport == nil {
return model.TLV2CredSubmissionReport{}, nil
}

return r.FnGetCredSubmissionReport(ctx, dbi, reqID, creds...)
return r.FnGetCredSubmissionReport(ctx, dbi, orderID, itemID, reqID, creds...)
}

func (r *MockTLV2) UniqBatches(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID uuid.UUID, from, to time.Time) (int, error) {
Expand Down
8 changes: 4 additions & 4 deletions services/skus/storage/repository/tlv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type TLV2 struct{}

func NewTLV2() *TLV2 { return &TLV2{} }

func (r *TLV2) GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
func (r *TLV2) GetCredSubmissionReport(ctx context.Context, dbi sqlx.QueryerContext, orderID, itemID, reqID uuid.UUID, creds ...string) (model.TLV2CredSubmissionReport, error) {
if len(creds) == 0 {
return model.TLV2CredSubmissionReport{}, model.ErrTLV2InvalidCredNum
}

const q = `SELECT EXISTS(
SELECT 1 FROM time_limited_v2_order_creds WHERE blinded_creds->>0 = $2
SELECT 1 FROM time_limited_v2_order_creds WHERE order_id=$1 AND item_id=$2 AND blinded_creds->>0 = $4
) AS submitted, EXISTS(
SELECT 1 FROM time_limited_v2_order_creds WHERE blinded_creds->>0 != $2 AND request_id = $1
SELECT 1 FROM time_limited_v2_order_creds WHERE order_id=$1 AND item_id=$2 AND request_id = $3 AND blinded_creds->>0 != $4
) AS req_id_mismatch`

result := model.TLV2CredSubmissionReport{}
if err := sqlx.GetContext(ctx, dbi, &result, q, reqID, creds[0]); err != nil {
if err := sqlx.GetContext(ctx, dbi, &result, q, orderID, itemID, reqID, creds[0]); err != nil {
return model.TLV2CredSubmissionReport{}, err
}

Expand Down
22 changes: 15 additions & 7 deletions services/skus/storage/repository/tlv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func TestTLV2_GetCredSubmissionReport(t *testing.T) {
}()

type tcGiven struct {
reqID uuid.UUID
creds []string
orderID uuid.UUID
itemID uuid.UUID
reqID uuid.UUID
creds []string

fnBefore func(ctx context.Context, dbi sqlx.ExtContext) error
}
Expand All @@ -47,6 +49,8 @@ func TestTLV2_GetCredSubmissionReport(t *testing.T) {
{
name: "invalid_param",
given: tcGiven{
orderID: uuid.Must(uuid.FromString("facade00-0000-4000-a000-000000000000")),
itemID: uuid.Must(uuid.FromString("decade00-0000-4000-a000-000000000000")),
reqID: uuid.Must(uuid.FromString("f100ded0-0000-4000-a000-000000000000")),
fnBefore: func(ctx context.Context, dbi sqlx.ExtContext) error { return nil },
},
Expand All @@ -56,8 +60,10 @@ func TestTLV2_GetCredSubmissionReport(t *testing.T) {
{
name: "submitted",
given: tcGiven{
reqID: uuid.Must(uuid.FromString("f100ded0-0000-4000-a000-000000000000")),
creds: []string{"cred_01", "cred_02", "cred_03"},
orderID: uuid.Must(uuid.FromString("c0c0a000-0000-4000-a000-000000000000")),
itemID: uuid.Must(uuid.FromString("ad0be000-0000-4000-a000-000000000000")),
reqID: uuid.Must(uuid.FromString("f100ded0-0000-4000-a000-000000000000")),
creds: []string{"cred_01", "cred_02", "cred_03"},

fnBefore: func(ctx context.Context, dbi sqlx.ExtContext) error {
qs := []string{
Expand Down Expand Up @@ -91,8 +97,10 @@ func TestTLV2_GetCredSubmissionReport(t *testing.T) {
{
name: "mismatch",
given: tcGiven{
reqID: uuid.Must(uuid.FromString("f100ded0-0000-4000-a000-000000000000")),
creds: []string{"cred_01", "cred_02", "cred_03"},
orderID: uuid.Must(uuid.FromString("c0c0a000-0000-4000-a000-000000000000")),
itemID: uuid.Must(uuid.FromString("ad0be000-0000-4000-a000-000000000000")),
reqID: uuid.Must(uuid.FromString("f100ded0-0000-4000-a000-000000000000")),
creds: []string{"cred_01", "cred_02", "cred_03"},

fnBefore: func(ctx context.Context, dbi sqlx.ExtContext) error {
qs := []string{
Expand Down Expand Up @@ -143,7 +151,7 @@ func TestTLV2_GetCredSubmissionReport(t *testing.T) {
must.Equal(t, nil, err)
}

actual, err := repo.GetCredSubmissionReport(ctx, tx, tc.given.reqID, tc.given.creds...)
actual, err := repo.GetCredSubmissionReport(ctx, tx, tc.given.orderID, tc.given.itemID, tc.given.reqID, tc.given.creds...)
must.Equal(t, tc.exp.err, err)

if tc.exp.err != nil {
Expand Down
Loading