Skip to content

Commit

Permalink
add validation image size in mm7 (go-delve#20)
Browse files Browse the repository at this point in the history
* add validation image size in mm7

* remove size image hardcoded
  • Loading branch information
pjserol authored Nov 26, 2020
1 parent c235abb commit 17b458f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/mm7/rpc/mm7.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func getProviderDetail(providerKey string) (ProviderDetail, error) {
return ProviderDetail{
Rate: 1.0,
Burst: 20,
ImageSizeMaxKB: 400,
ImageSizeMaxKB: 450,
QueueNameSubmit: worker.QueueNameSubmitOptus,
}, nil
case worker.MgageProviderKey:
Expand Down
16 changes: 16 additions & 0 deletions backend/mm7/worker/fake_mm7_submit/fake_mm7_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

type mm7RPCClient interface {
UpdateStatus(p mm7RPC.MM7UpdateStatusParams) error
ProviderSpec(p mm7RPC.MM7ProviderSpecParams) (r *mm7RPC.MM7ProviderSpecReply, err error)
CheckRateLimit(p mm7RPC.MM7CheckRateLimitParams) (r *mm7RPC.MM7CheckRateLimitReply, err error)
GetCachedContent(p mm7RPC.MM7GetCachedContentParams) (r *mm7RPC.MM7GetCachedContentReply, err error)
}
Expand Down Expand Up @@ -66,6 +67,14 @@ func (h *FakeMM7SubmitHandler) Handle(body []byte, headers map[string]interface{
return rabbit.NewErrRetryWorkerMessage(fmt.Sprintf("Failed sending message id: %s Error: rate limit reached", msg.ID))
}

psReply, err := h.mm7RPC.ProviderSpec(mm7RPC.MM7ProviderSpecParams{
ProviderKey: worker.FakeProviderKey,
})
if err != nil {
h.logError(msg, "", err.Error(), "Unexpected mm7RPC.ProviderSpec response")
return err
}

var images [][]byte
for _, url := range msg.ContentURLs {
r, err := h.mm7RPC.GetCachedContent(mm7RPC.MM7GetCachedContentParams{
Expand All @@ -76,6 +85,13 @@ func (h *FakeMM7SubmitHandler) Handle(body []byte, headers map[string]interface{
return err
}

// validation image size
if len(r.Content) > psReply.ImageSizeMaxKB*1000 {
description := fmt.Sprintf("Total image size > %dkb", psReply.ImageSizeMaxKB)
h.logError(msg, MMSStatusFailed, description, "Validation error")
return h.updateStatus(msg.ID, "", MMSStatusFailed, description)
}

images = append(images, r.Content)
}

Expand Down
8 changes: 7 additions & 1 deletion backend/mm7/worker/fake_mm7_submit/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import (
)

type mockRPCClient struct {
providerSpecReply mm7RPC.MM7ProviderSpecReply
rateLimitReply mm7RPC.MM7CheckRateLimitReply
cachedContentReply mm7RPC.MM7GetCachedContentReply
err error

err error
}

func (m mockRPCClient) UpdateStatus(p mm7RPC.MM7UpdateStatusParams) error {
return m.err
}

func (m mockRPCClient) ProviderSpec(p mm7RPC.MM7ProviderSpecParams) (r *mm7RPC.MM7ProviderSpecReply, err error) {
return &m.providerSpecReply, m.err
}

func (m mockRPCClient) CheckRateLimit(p mm7RPC.MM7CheckRateLimitParams) (r *mm7RPC.MM7CheckRateLimitReply, err error) {
return &m.rateLimitReply, m.err
}
Expand Down

0 comments on commit 17b458f

Please sign in to comment.