From 6b715c1f034c84497c0e241d67a26d0f0fdae60b Mon Sep 17 00:00:00 2001 From: Hendrik Steidl <837420+hsteidl@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:38:15 +0100 Subject: [PATCH] fix(ocpp1.6/core): allow empty idTag https://grid-x.atlassian.net/browse/INTE-1856 --- ocpp1.6/core/authorize.go | 5 +++-- ocpp1.6/core/start_transaction.go | 5 +++-- ocpp1.6_test/authorize_test.go | 7 ++++--- ocpp1.6_test/start_transaction_test.go | 7 ++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ocpp1.6/core/authorize.go b/ocpp1.6/core/authorize.go index 3a9874ad..ab48cf09 100644 --- a/ocpp1.6/core/authorize.go +++ b/ocpp1.6/core/authorize.go @@ -1,8 +1,9 @@ package core import ( - "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "reflect" + + "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" ) // -------------------- Authorize (CP -> CS) -------------------- @@ -11,7 +12,7 @@ const AuthorizeFeatureName = "Authorize" // The field definition of the Authorize request payload sent by the Charge Point to the Central System. type AuthorizeRequest struct { - IdTag string `json:"idTag" validate:"required,max=20"` + IdTag string `json:"idTag" validate:"omitempty,max=20"` } // This field definition of the Authorize confirmation payload, sent by the Charge Point to the Central System in response to an AuthorizeRequest. diff --git a/ocpp1.6/core/start_transaction.go b/ocpp1.6/core/start_transaction.go index 3b3bdaf6..3a0fef3d 100644 --- a/ocpp1.6/core/start_transaction.go +++ b/ocpp1.6/core/start_transaction.go @@ -1,8 +1,9 @@ package core import ( - "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "reflect" + + "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" ) // -------------------- Start Transaction (CP -> CS) -------------------- @@ -12,7 +13,7 @@ const StartTransactionFeatureName = "StartTransaction" // This field definition of the StartTransactionRequest payload sent by the Charge Point to the Central System. type StartTransactionRequest struct { ConnectorId int `json:"connectorId" validate:"gt=0"` - IdTag string `json:"idTag" validate:"required,max=20"` + IdTag string `json:"idTag" validate:"omitempty,max=20"` MeterStart int `json:"meterStart" validate:"gte=0"` ReservationId *int `json:"reservationId,omitempty" validate:"omitempty"` Timestamp *types.DateTime `json:"timestamp" validate:"required"` diff --git a/ocpp1.6_test/authorize_test.go b/ocpp1.6_test/authorize_test.go index 665b36f1..713081bf 100644 --- a/ocpp1.6_test/authorize_test.go +++ b/ocpp1.6_test/authorize_test.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" - "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" ) // Test @@ -16,7 +17,7 @@ func (suite *OcppV16TestSuite) TestAuthorizeRequestValidation() { t := suite.T() var requestTable = []GenericTestEntry{ {core.AuthorizeRequest{IdTag: "12345"}, true}, - {core.AuthorizeRequest{}, false}, + {core.AuthorizeRequest{}, true}, {core.AuthorizeRequest{IdTag: ">20.................."}, false}, } ExecuteGenericTestTable(t, requestTable) diff --git a/ocpp1.6_test/start_transaction_test.go b/ocpp1.6_test/start_transaction_test.go index 5991acb5..88eddf30 100644 --- a/ocpp1.6_test/start_transaction_test.go +++ b/ocpp1.6_test/start_transaction_test.go @@ -4,11 +4,12 @@ import ( "fmt" "time" - "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" - "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" ) // Test @@ -22,7 +23,7 @@ func (suite *OcppV16TestSuite) TestStartTransactionRequestValidation() { {core.StartTransactionRequest{ConnectorId: -1, IdTag: "12345", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false}, {core.StartTransactionRequest{ConnectorId: 1, IdTag: ">20..................", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false}, {core.StartTransactionRequest{IdTag: "12345", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false}, - {core.StartTransactionRequest{ConnectorId: 1, MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false}, + {core.StartTransactionRequest{ConnectorId: 1, MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, true}, {core.StartTransactionRequest{ConnectorId: 1, IdTag: "12345", MeterStart: 100}, false}, } ExecuteGenericTestTable(t, requestTable)