Skip to content

Commit c1f5bd5

Browse files
committed
Check for empty unique ID
Signed-off-by: Lorenzo <[email protected]>
1 parent e5ac6a5 commit c1f5bd5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ocppj/ocppj.go

+3
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ func (endpoint *Endpoint) ParseMessage(arr []interface{}, pendingRequestState Cl
411411
if !ok {
412412
return nil, ocpp.NewError(FormatErrorType(endpoint), fmt.Sprintf("Invalid element %v at 1, expected unique ID (string)", arr[1]), uniqueId)
413413
}
414+
if uniqueId == "" {
415+
return nil, ocpp.NewError(FormatErrorType(endpoint), "Invalid unique ID, cannot be empty", uniqueId)
416+
}
414417
// Parse message
415418
if typeId == CALL {
416419
if len(arr) != 4 {

ocppj/ocppj_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,22 @@ func (suite *OcppJTestSuite) TestParseMessageInvalidMessageId() {
574574
assert.Equal(t, fmt.Sprintf("Invalid element %v at 1, expected unique ID (string)", invalidMessageId), protoErr.Description)
575575
}
576576

577+
func (suite *OcppJTestSuite) TestParseMessageEmptyMessageID() {
578+
t := suite.T()
579+
mockMessage := make([]interface{}, 3)
580+
// Test invalid message length
581+
mockMessage[0] = float64(ocppj.CALL_RESULT) // Message Type ID
582+
mockMessage[1] = "" // Empty ID
583+
message, err := suite.chargePoint.ParseMessage(mockMessage, suite.chargePoint.RequestState)
584+
require.Nil(t, message)
585+
require.Error(t, err)
586+
protoErr := err.(*ocpp.Error)
587+
require.NotNil(t, protoErr)
588+
suite.Equal("", protoErr.MessageId)
589+
suite.Equal(ocppj.FormatErrorType(suite.chargePoint), protoErr.Code)
590+
suite.Errorf(protoErr, "Invalid unique ID, cannot be empty")
591+
}
592+
577593
func (suite *OcppJTestSuite) TestParseMessageUnknownTypeId() {
578594
t := suite.T()
579595
mockMessage := make([]interface{}, 3)

0 commit comments

Comments
 (0)