From 45b397cd6779da3863f478270170d5b89912360b Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 11 Jun 2024 20:58:42 +0200 Subject: [PATCH 1/4] EEbus: fix unmarshaling config --- charger/eebus/eebus.go | 4 ++-- charger/eebus/eebus_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 charger/eebus/eebus_test.go diff --git a/charger/eebus/eebus.go b/charger/eebus/eebus.go index c0170b6f1f..f9d8b84ab4 100644 --- a/charger/eebus/eebus.go +++ b/charger/eebus/eebus.go @@ -34,7 +34,7 @@ type Config struct { ShipID string Interfaces []string Certificate struct { - Public, Private []byte + Public, Private string } } @@ -77,7 +77,7 @@ func NewServer(other Config) (*EEBus, error) { serial = cc.ShipID } - certificate, err := tls.X509KeyPair(cc.Certificate.Public, cc.Certificate.Private) + certificate, err := tls.X509KeyPair([]byte(cc.Certificate.Public), []byte(cc.Certificate.Private)) if err != nil { return nil, err } diff --git a/charger/eebus/eebus_test.go b/charger/eebus/eebus_test.go new file mode 100644 index 0000000000..fef12145eb --- /dev/null +++ b/charger/eebus/eebus_test.go @@ -0,0 +1,27 @@ +package eebus + +import ( + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" +) + +func TestConfig(t *testing.T) { + conf := ` +certificate: + private: | + -----BEGIN EC PRIVATE KEY----- + MHcCfoo== + -----END EC PRIVATE KEY----- + public: | + -----BEGIN CERTIFICATE----- + MIIBbar= + -----END CERTIFICATE----- +` + + var res Config + + err := yaml.Unmarshal([]byte(conf), &res) + require.NoError(t, err) +} From 7c585a6daa11217ce825a12a92e5519453076f61 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 11 Jun 2024 21:02:00 +0200 Subject: [PATCH 2/4] wip --- charger/eebus/eebus_test.go | 1 - cmd/setup_test.go | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/charger/eebus/eebus_test.go b/charger/eebus/eebus_test.go index fef12145eb..3dd3a958da 100644 --- a/charger/eebus/eebus_test.go +++ b/charger/eebus/eebus_test.go @@ -21,7 +21,6 @@ certificate: ` var res Config - err := yaml.Unmarshal([]byte(conf), &res) require.NoError(t, err) } diff --git a/cmd/setup_test.go b/cmd/setup_test.go index f4dae37f57..be1896858e 100644 --- a/cmd/setup_test.go +++ b/cmd/setup_test.go @@ -8,6 +8,8 @@ import ( "github.com/evcc-io/evcc/api/globalconfig" "github.com/evcc-io/evcc/core" "github.com/evcc-io/evcc/util" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" ) func TestYamlOff(t *testing.T) { @@ -32,3 +34,22 @@ func TestYamlOff(t *testing.T) { t.Errorf("expected `off`, got %s", lp.Mode_) } } + +func TestEEbusConfig(t *testing.T) { + conf := ` +eebus: + certificate: + private: | + -----BEGIN EC PRIVATE KEY----- + MHcCfoo== + -----END EC PRIVATE KEY----- + public: | + -----BEGIN CERTIFICATE----- + MIIBbar= + -----END CERTIFICATE----- +` + + var res globalconfig.All + err := yaml.Unmarshal([]byte(conf), &res) + require.NoError(t, err) +} From f70d69cd0e80fe060cf990f5c35b44bcc39c9c79 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 12 Jun 2024 18:44:31 +0200 Subject: [PATCH 3/4] wip --- cmd/setup_test.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/cmd/setup_test.go b/cmd/setup_test.go index be1896858e..f4dae37f57 100644 --- a/cmd/setup_test.go +++ b/cmd/setup_test.go @@ -8,8 +8,6 @@ import ( "github.com/evcc-io/evcc/api/globalconfig" "github.com/evcc-io/evcc/core" "github.com/evcc-io/evcc/util" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" ) func TestYamlOff(t *testing.T) { @@ -34,22 +32,3 @@ func TestYamlOff(t *testing.T) { t.Errorf("expected `off`, got %s", lp.Mode_) } } - -func TestEEbusConfig(t *testing.T) { - conf := ` -eebus: - certificate: - private: | - -----BEGIN EC PRIVATE KEY----- - MHcCfoo== - -----END EC PRIVATE KEY----- - public: | - -----BEGIN CERTIFICATE----- - MIIBbar= - -----END CERTIFICATE----- -` - - var res globalconfig.All - err := yaml.Unmarshal([]byte(conf), &res) - require.NoError(t, err) -} From afaa61f133848b2898430eaece10aa1d3f17b3dc Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 12 Jun 2024 18:46:39 +0200 Subject: [PATCH 4/4] wip --- charger/eebus/eebus_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/charger/eebus/eebus_test.go b/charger/eebus/eebus_test.go index 3dd3a958da..f4dc83abdf 100644 --- a/charger/eebus/eebus_test.go +++ b/charger/eebus/eebus_test.go @@ -21,6 +21,5 @@ certificate: ` var res Config - err := yaml.Unmarshal([]byte(conf), &res) - require.NoError(t, err) + require.NoError(t, yaml.Unmarshal([]byte(conf), &res)) }