Skip to content

Commit 42b92a5

Browse files
authored
chore: merge #135
fix: reject interfaces with conflicting options in aggregate mappings (fw-port for release 1.3)
2 parents ed0f131 + 7385079 commit 42b92a5

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2121
- Add events for device deletion started and finished.
2222
- Add event for device registration.
2323

24+
## [1.2.1] - Unreleased
25+
26+
### Fixed
27+
- [astarte_realm_management] Insufficient validation for conflicting options in interface aggregate mappings
28+
[#1072](https://github.com/astarte-platform/astarte/issues/1072)
29+
30+
## [1.2.1-rc.0] - 2025-08-22
31+
### Added
32+
- Allow `to_int` in custom enum types to be called with valid integers
33+
- Allow `from_int` in custom enum types to be called with valid atoms
34+
- Expose a custom `@type` for all structs
35+
- Implement json encoder for `IncomingIntrospectionEvent`
36+
2437
## [1.2.0] - 2024-07-01
2538

2639
## [1.2.0-rc.0] - 2024-05-28

lib/astarte_core/interface.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,17 @@ defmodule Astarte.Core.Interface do
218218

219219
defp validate_all_mappings_have_same_attributes(changeset) do
220220
mappings = get_field(changeset, :mappings, [])
221-
aggregation = get_field(changeset, :aggregation, [])
221+
aggregation = get_field(changeset, :aggregation, :individual)
222222

223223
if aggregation == :object and mappings != [] do
224224
%Mapping{
225225
retention: retention,
226226
reliability: reliability,
227227
expiry: expiry,
228228
allow_unset: allow_unset,
229-
explicit_timestamp: explicit_timestamp
229+
explicit_timestamp: explicit_timestamp,
230+
database_retention_policy: database_retention_policy,
231+
database_retention_ttl: database_retention_ttl
230232
} = List.first(mappings)
231233

232234
all_same_attributes =
@@ -236,12 +238,16 @@ defmodule Astarte.Core.Interface do
236238
reliability: mapping_reliability,
237239
expiry: mapping_expiry,
238240
allow_unset: mapping_allow_unset,
239-
explicit_timestamp: mapping_explicit_timestamp
241+
explicit_timestamp: mapping_explicit_timestamp,
242+
database_retention_policy: mapping_database_retention_policy,
243+
database_retention_ttl: mapping_database_retention_ttl
240244
} = mapping
241245

242246
retention == mapping_retention and reliability == mapping_reliability and
243247
expiry == mapping_expiry and allow_unset == mapping_allow_unset and
244-
explicit_timestamp == mapping_explicit_timestamp
248+
explicit_timestamp == mapping_explicit_timestamp and
249+
database_retention_policy == mapping_database_retention_policy and
250+
database_retention_ttl == mapping_database_retention_ttl
245251
end)
246252

247253
unless all_same_attributes do

test/astarte_core/interface_test.exs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ defmodule Astarte.Core.InterfaceTest do
123123
}
124124
"""
125125

126+
@conflicting_properties_aggregated_datastreams """
127+
{
128+
"interface_name": "com.secomind.Hemera.DeviceValues",
129+
"version_major": 1,
130+
"version_minor": 0,
131+
"type": "datastream",
132+
"ownership": "producer",
133+
"aggregation": "object",
134+
"mappings": [
135+
{
136+
"endpoint": "/value/first",
137+
"type": "integer",
138+
"database_retention_policy": "use_ttl",
139+
"database_retention_ttl": 600
140+
},
141+
{
142+
"endpoint": "/value/second",
143+
"type": "integer",
144+
"database_retention_policy": "use_ttl",
145+
"database_retention_ttl": 300
146+
}
147+
]
148+
}
149+
"""
150+
126151
test "aggregated datastream interface deserialization" do
127152
{:ok, params} = Jason.decode(@aggregated_datastream_interface_json)
128153

@@ -212,6 +237,16 @@ defmodule Astarte.Core.InterfaceTest do
212237
assert %Ecto.Changeset{valid?: false, errors: [endpoint: _]} = mapping_changeset
213238
end
214239

240+
test "attributes mismatch in aggregate mappings" do
241+
{:ok, params} = Jason.decode(@conflicting_properties_aggregated_datastreams)
242+
243+
assert %Ecto.Changeset{
244+
valid?: false,
245+
errors: [mappings: _]
246+
} =
247+
Interface.changeset(%Interface{}, params)
248+
end
249+
215250
test "invalid interface name" do
216251
params = %{
217252
"interface_name" => "notok; DROP KEYSPACE astarte;//",

0 commit comments

Comments
 (0)