From 0e8385a5a7d1689e53ab8749a6eaebb323574a61 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Mon, 8 Jan 2024 11:44:56 +0100 Subject: [PATCH] fix(chromium): missing webp validation --- pkg/modules/chromium/routes.go | 2 +- pkg/modules/chromium/routes_test.go | 36 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/modules/chromium/routes.go b/pkg/modules/chromium/routes.go index 88708326..ac4d5d23 100644 --- a/pkg/modules/chromium/routes.go +++ b/pkg/modules/chromium/routes.go @@ -171,7 +171,7 @@ func FormDataChromiumScreenshotOptions(ctx *api.Context) (*api.FormData, Screens return nil } - if value != "png" && value != "jpeg" && value != "" { + if value != "png" && value != "jpeg" && value != "webp" { return fmt.Errorf("wrong value, expected either 'png', 'jpeg' or 'webp'") } diff --git a/pkg/modules/chromium/routes_test.go b/pkg/modules/chromium/routes_test.go index 05470e29..b46440c1 100644 --- a/pkg/modules/chromium/routes_test.go +++ b/pkg/modules/chromium/routes_test.go @@ -209,7 +209,24 @@ func TestFormDataChromiumScreenshotOptions(t *testing.T) { }(), }, { - scenario: "valid format form field", + scenario: "valid png format form field", + ctx: func() *api.ContextMock { + ctx := &api.ContextMock{Context: new(api.Context)} + ctx.SetValues(map[string][]string{ + "format": { + "png", + }, + }) + return ctx + }(), + expectedOptions: func() ScreenshotOptions { + options := DefaultScreenshotOptions() + options.Format = "png" + return options + }(), + }, + { + scenario: "valid jpeg format form field", ctx: func() *api.ContextMock { ctx := &api.ContextMock{Context: new(api.Context)} ctx.SetValues(map[string][]string{ @@ -225,6 +242,23 @@ func TestFormDataChromiumScreenshotOptions(t *testing.T) { return options }(), }, + { + scenario: "valid webp format form field", + ctx: func() *api.ContextMock { + ctx := &api.ContextMock{Context: new(api.Context)} + ctx.SetValues(map[string][]string{ + "format": { + "webp", + }, + }) + return ctx + }(), + expectedOptions: func() ScreenshotOptions { + options := DefaultScreenshotOptions() + options.Format = "webp" + return options + }(), + }, { scenario: "invalid quality form field (not an integer)", ctx: func() *api.ContextMock {