From a431980e19864feab256a6d0df40d9bb9a2931bd Mon Sep 17 00:00:00 2001 From: Greg Tyler Date: Thu, 9 May 2024 15:30:01 +0100 Subject: [PATCH] Don't enforce validation on paper-channel LPAs We can't kick back a 400 response to the scanners because they can't change what they send, so log and accept the validation errors. Plus fix an existing bug with unmarshalling empty dates. For CTC-146 #patch --- fixtures/static/js/json-schema-editor.mjs | 7 +++++-- internal/shared/date.go | 4 ++++ internal/shared/date_test.go | 5 +++-- lambda/create/main.go | 12 ++++++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fixtures/static/js/json-schema-editor.mjs b/fixtures/static/js/json-schema-editor.mjs index ac2d6ca1..f9630d46 100644 --- a/fixtures/static/js/json-schema-editor.mjs +++ b/fixtures/static/js/json-schema-editor.mjs @@ -61,12 +61,15 @@ export class JsonSchemaEditor { $container.addEventListener("input", (e) => { if ( - e.target instanceof HTMLInputElement || - e.target instanceof HTMLSelectElement + (e.target instanceof HTMLInputElement || + e.target instanceof HTMLSelectElement) && + e.target.name ) { const value = JSON.parse(this.$module.value); jsonSet(value, e.target.name, e.target.value); this.$module.value = JSON.stringify(value); + + if (e.target.name === "/channel") this.build(); } }); diff --git a/internal/shared/date.go b/internal/shared/date.go index ce20e1f9..ae2d8412 100644 --- a/internal/shared/date.go +++ b/internal/shared/date.go @@ -31,6 +31,10 @@ func (d *Date) UnmarshalJSON(data []byte) error { } func (d *Date) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } + var err error d.t, err = time.Parse(time.DateOnly, string(data)) return err diff --git a/internal/shared/date_test.go b/internal/shared/date_test.go index 1178a379..ace3bfff 100644 --- a/internal/shared/date_test.go +++ b/internal/shared/date_test.go @@ -92,10 +92,11 @@ func TestDateDynamoDB(t *testing.T) { av := &types.AttributeValueMemberS{Value: tc.dynamo} var unmarshal Date - attributevalue.Unmarshal(av, &unmarshal) + assert.Nil(t, attributevalue.Unmarshal(av, &unmarshal)) assert.Equal(t, tc.date, unmarshal) - marshal, _ := attributevalue.Marshal(unmarshal) + marshal, err := attributevalue.Marshal(unmarshal) + assert.Nil(t, err) assert.Equal(t, av, marshal) }) } diff --git a/lambda/create/main.go b/lambda/create/main.go index 41463081..c6e0c492 100644 --- a/lambda/create/main.go +++ b/lambda/create/main.go @@ -89,12 +89,16 @@ func (l *Lambda) HandleEvent(ctx context.Context, req events.APIGatewayProxyRequ // validation if errs := Validate(input); len(errs) > 0 { - problem := shared.ProblemInvalidRequest - problem.Errors = errs + if input.Channel == shared.ChannelPaper { + l.logger.Info("encountered validation errors in lpa", slog.Any("uid", uid)) + } else { + problem := shared.ProblemInvalidRequest + problem.Errors = errs - return problem.Respond() + return problem.Respond() + } } - + data := shared.Lpa{LpaInit: input} data.Uid = uid data.Status = shared.LpaStatusProcessing