Skip to content

Commit

Permalink
[WIRE-717] Fix unknown fields serialization issue (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjtokenring authored Feb 3, 2025
1 parent fb9f403 commit 88de618
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .licenses/go/github.com/arduino/iot-client-go/v3.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: github.com/arduino/iot-client-go/v3
version: v3.0.1
version: v3.1.1
type: go
summary:
homepage: https://pkg.go.dev/github.com/arduino/iot-client-go/v3
Expand Down
2 changes: 1 addition & 1 deletion .licenses/go/golang.org/x/oauth2.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: golang.org/x/oauth2
version: v0.23.0
version: v0.25.0
type: go
summary: Package oauth2 provides support for making OAuth2 authorized and authenticated
HTTP requests, as specified in RFC 6749.
Expand Down
4 changes: 2 additions & 2 deletions .licenses/go/golang.org/x/oauth2/clientcredentials.dep.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: golang.org/x/oauth2/clientcredentials
version: v0.23.0
version: v0.25.0
type: go
summary: Package clientcredentials implements the OAuth2.0 "client credentials" token
flow, also known as the "two-legged OAuth 2.0".
homepage: https://pkg.go.dev/golang.org/x/oauth2/clientcredentials
license: bsd-3-clause
licenses:
- sources: oauth2@v0.23.0/LICENSE
- sources: oauth2@v0.25.0/LICENSE
text: |
Copyright 2009 The Go Authors.
Expand Down
4 changes: 2 additions & 2 deletions .licenses/go/golang.org/x/oauth2/internal.dep.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: golang.org/x/oauth2/internal
version: v0.23.0
version: v0.25.0
type: go
summary: Package internal contains support packages for oauth2 package.
homepage: https://pkg.go.dev/golang.org/x/oauth2/internal
license: bsd-3-clause
licenses:
- sources: oauth2@v0.23.0/LICENSE
- sources: oauth2@v0.25.0/LICENSE
text: |
Copyright 2009 The Go Authors.
Expand Down
7 changes: 6 additions & 1 deletion command/device/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func Show(ctx context.Context, deviceId string, cred *config.Credentials) (*Devi
return nil, net, err
}
for _, netCred := range netCredentialsArray {
net = append(net, netCredentials(netCred))
var netCredToShow netCredentials
netCredToShow.FriendlyName = netCred.FriendlyName
netCredToShow.Required = netCred.Required
netCredToShow.SecretName = netCred.SecretName
netCredToShow.Sensitive = netCred.Sensitive
net = append(net, netCredToShow)
}
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/arduino/arduino-cli v0.0.0-20240927141754-d9dd4ba1ed71
github.com/arduino/go-paths-helper v1.12.1
github.com/arduino/go-win32-utils v1.0.0
github.com/arduino/iot-client-go/v3 v3.0.1
github.com/arduino/iot-client-go/v3 v3.1.1
github.com/gofrs/uuid v4.2.0+incompatible
github.com/google/go-cmp v0.6.0
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
Expand All @@ -19,7 +19,7 @@ require (
go.bug.st/cleanup v1.0.0
go.bug.st/serial v1.6.2
golang.org/x/crypto v0.18.0
golang.org/x/oauth2 v0.23.0
golang.org/x/oauth2 v0.25.0
google.golang.org/grpc v1.61.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ github.com/arduino/go-properties-orderedmap v1.7.1 h1:HQ9Pn/mk3+XyfrE39EEvaZwJkr
github.com/arduino/go-properties-orderedmap v1.7.1/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-win32-utils v1.0.0 h1:/cXB86sOJxOsCHP7sQmXGLkdValwJt56mIwOHYxgQjQ=
github.com/arduino/go-win32-utils v1.0.0/go.mod h1:0jqM7doGEAs6DaJCxxhLBUDS5OawrqF48HqXkcEie/Q=
github.com/arduino/iot-client-go/v3 v3.0.1 h1:AwkctEtP7ilVXBOF2yZPJZpjpuUmKNGr/OdYxPx/4QQ=
github.com/arduino/iot-client-go/v3 v3.0.1/go.mod h1:r2QEAP5Jalkr0YWNPhFl0EJzFRQNy24wN5CVbn11f64=
github.com/arduino/iot-client-go/v3 v3.1.1 h1:bQhbV5PlH8tDuSmeimw9Rjrh5KbIUhqvYWWI/xYMi1M=
github.com/arduino/iot-client-go/v3 v3.1.1/go.mod h1:r2QEAP5Jalkr0YWNPhFl0EJzFRQNy24wN5CVbn11f64=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
Expand Down Expand Up @@ -582,8 +582,8 @@ golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
41 changes: 41 additions & 0 deletions internal/iot/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package iot

import (
"testing"

iotclient "github.com/arduino/iot-client-go/v3"
"github.com/stretchr/testify/assert"
)

func TestJSON_UnknownFields_areAccepted(t *testing.T) {

cert := iotclient.ArduinoDevicev2Cert{}

// Add unknown fields to the JSON and verify that marshalling and unmarshalling works without raising error.
// This is useful when the API is extended with new fields and the client is not updated yet.
certJson := `{
"compressed": {
"not_after": "0001-01-01T00:00:00Z",
"not_before": "0001-01-01T00:00:00Z",
"serial": "",
"signature": "signature",
"signature_asn1_x": "",
"signature_asn1_y": ""
},
"der": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",
"device_id": "123",
"enabled": true,
"href": "",
"id": "",
"pem": "-----BEGIN CERTIFICATE-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",
"unknown_field": "value",
"unknown_field2": "value2",
"new_api_field": 2222
}`

err := cert.UnmarshalJSON([]byte(certJson))
if err != nil {
t.Errorf("UnmarshalJSON failed: %s", err)
}
assert.Equal(t, 3, len(cert.AdditionalProperties))
}
17 changes: 11 additions & 6 deletions internal/template/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,53 +68,58 @@ var (
Widgets: []iotclient.Widget{
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true},
Type: "Switch",
Type: "Switch", AdditionalProperties: map[string]any{},
},
},
AdditionalProperties: map[string]any{},
}

dashboardNoOptions = &iotclient.Dashboardv2{
Name: toStringPointer("dashboard-no-options"),
Widgets: []iotclient.Widget{
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{},
Type: "Switch",
Type: "Switch", AdditionalProperties: map[string]any{},
},
},
AdditionalProperties: map[string]any{},
}

dashboardWithVariable = &iotclient.Dashboardv2{
Name: toStringPointer("dashboard-with-variable"),
Widgets: []iotclient.Widget{
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
Variables: []string{switchyID},
Variables: []string{switchyID}, AdditionalProperties: map[string]any{},
},
},
AdditionalProperties: map[string]any{},
}

dashboardVariableOverride = &iotclient.Dashboardv2{
Name: toStringPointer("dashboard-with-variable"),
Widgets: []iotclient.Widget{
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
Variables: []string{switchyOverriddenID},
Variables: []string{switchyOverriddenID}, AdditionalProperties: map[string]any{},
},
},
AdditionalProperties: map[string]any{},
}

dashboardTwoWidgets = &iotclient.Dashboardv2{
Name: toStringPointer("dashboard-two-widgets"),
Widgets: []iotclient.Widget{
{Name: toStringPointer("blink_speed"), Height: 7, Width: 8,
X: 7, Y: 5, Options: map[string]interface{}{"min": float64(0), "max": float64(5000)}, Type: "Slider",
Variables: []string{blinkSpeedID},
Variables: []string{blinkSpeedID}, AdditionalProperties: map[string]any{},
},
{Name: toStringPointer("relay_2"), Height: 5, Width: 5,
X: 5, Y: 0, Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
Variables: []string{relayID},
Variables: []string{relayID}, AdditionalProperties: map[string]any{},
},
},
AdditionalProperties: map[string]any{},
}
)

Expand Down

0 comments on commit 88de618

Please sign in to comment.