Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions lib/astarte_core/interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,17 @@ 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{
retention: retention,
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 =
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/astarte_core/interface_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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;//",
Expand Down
Loading