diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c7f66a..6be44c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add events for device deletion started and finished. - Add event for device registration. +## [1.2.1] - Unreleased + +### Fixed +- [astarte_realm_management] Insufficient validation for conflicting options in interface aggregate mappings + [#1072](https://github.com/astarte-platform/astarte/issues/1072) + +## [1.2.1-rc.0] - 2025-08-22 +### Added +- Allow `to_int` in custom enum types to be called with valid integers +- Allow `from_int` in custom enum types to be called with valid atoms +- Expose a custom `@type` for all structs +- Implement json encoder for `IncomingIntrospectionEvent` + ## [1.2.0] - 2024-07-01 ## [1.2.0-rc.0] - 2024-05-28 diff --git a/lib/astarte_core/interface.ex b/lib/astarte_core/interface.ex index dbffb5e..80440fb 100644 --- a/lib/astarte_core/interface.ex +++ b/lib/astarte_core/interface.ex @@ -218,7 +218,7 @@ defmodule Astarte.Core.Interface do defp validate_all_mappings_have_same_attributes(changeset) do mappings = get_field(changeset, :mappings, []) - aggregation = get_field(changeset, :aggregation, []) + aggregation = get_field(changeset, :aggregation, :individual) if aggregation == :object and mappings != [] do %Mapping{ @@ -226,7 +226,9 @@ defmodule Astarte.Core.Interface do reliability: reliability, expiry: expiry, allow_unset: allow_unset, - explicit_timestamp: explicit_timestamp + explicit_timestamp: explicit_timestamp, + database_retention_policy: database_retention_policy, + database_retention_ttl: database_retention_ttl } = List.first(mappings) all_same_attributes = @@ -236,12 +238,16 @@ defmodule Astarte.Core.Interface do reliability: mapping_reliability, expiry: mapping_expiry, allow_unset: mapping_allow_unset, - explicit_timestamp: mapping_explicit_timestamp + explicit_timestamp: mapping_explicit_timestamp, + database_retention_policy: mapping_database_retention_policy, + database_retention_ttl: mapping_database_retention_ttl } = mapping retention == mapping_retention and reliability == mapping_reliability and expiry == mapping_expiry and allow_unset == mapping_allow_unset and - explicit_timestamp == mapping_explicit_timestamp + explicit_timestamp == mapping_explicit_timestamp and + database_retention_policy == mapping_database_retention_policy and + database_retention_ttl == mapping_database_retention_ttl end) unless all_same_attributes do diff --git a/test/astarte_core/interface_test.exs b/test/astarte_core/interface_test.exs index 842cfd8..11e5c77 100644 --- a/test/astarte_core/interface_test.exs +++ b/test/astarte_core/interface_test.exs @@ -123,6 +123,31 @@ defmodule Astarte.Core.InterfaceTest do } """ + @conflicting_properties_aggregated_datastreams """ + { + "interface_name": "com.secomind.Hemera.DeviceValues", + "version_major": 1, + "version_minor": 0, + "type": "datastream", + "ownership": "producer", + "aggregation": "object", + "mappings": [ + { + "endpoint": "/value/first", + "type": "integer", + "database_retention_policy": "use_ttl", + "database_retention_ttl": 600 + }, + { + "endpoint": "/value/second", + "type": "integer", + "database_retention_policy": "use_ttl", + "database_retention_ttl": 300 + } + ] + } + """ + test "aggregated datastream interface deserialization" do {:ok, params} = Jason.decode(@aggregated_datastream_interface_json) @@ -212,6 +237,16 @@ defmodule Astarte.Core.InterfaceTest do assert %Ecto.Changeset{valid?: false, errors: [endpoint: _]} = mapping_changeset end + test "attributes mismatch in aggregate mappings" do + {:ok, params} = Jason.decode(@conflicting_properties_aggregated_datastreams) + + assert %Ecto.Changeset{ + valid?: false, + errors: [mappings: _] + } = + Interface.changeset(%Interface{}, params) + end + test "invalid interface name" do params = %{ "interface_name" => "notok; DROP KEYSPACE astarte;//",