Skip to content

Commit

Permalink
Also check for length
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jun 26, 2024
1 parent 3b039de commit d3a0c08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (s *Service) Setup() error {
}
deviceAddress = fmt.Sprintf("d:_%s:%s_%s%s", vendorType, vendor, sd.DeviceModel(), serial)

if len(deviceAddress) > 256 {
return fmt.Errorf("generated device address may not be longer than 256 characters: %s", deviceAddress)
}

// Create the local SPINE device
s.spineLocalDevice = spine.NewDeviceLocal(
sd.DeviceBrand(),
Expand Down
25 changes: 25 additions & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,28 @@ func (s *ServiceSuite) Test_Setup_IANA() {
device := s.sut.LocalDevice()
assert.NotNil(s.T(), device)
}

func (s *ServiceSuite) Test_Setup_Error_DeviceName() {
var err error
certificate := tls.Certificate{}
s.config, err = api.NewConfiguration(
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"brand",
"modelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodelmodel",
"serialserialserialserialserialserialserialserialserialserialserialserialserialserialserialserialserial",
model.DeviceTypeTypeEnergyManagementSystem,
[]model.EntityTypeType{model.EntityTypeTypeCEM}, 4729, certificate, 230.0, time.Second*4)
assert.Nil(s.T(), nil, err)

s.sut = NewService(s.config, s.serviceReader)

err = s.sut.Setup()
assert.NotNil(s.T(), err)

certificate, err = cert.CreateCertificate("unit", "org", "de", "cn")
assert.Nil(s.T(), err)
s.config.SetCertificate(certificate)

err = s.sut.Setup()
assert.NotNil(s.T(), err)
}

0 comments on commit d3a0c08

Please sign in to comment.