Files
5e71e2243c Test that a secured connection refuses its JSON metadata announcement (#4724)
# Description

#4712 makes a connection configured for message security send its
DataSetMetaData announcement through the connection's security step, so
the announcement is never sent unsecured. Its tests cover the UADP
announcement. This adds the JSON case.

The UADP security wrapper cannot protect a JSON message, so a connection
whose WriterGroup uses `SignAndEncrypt` must refuse the JSON metadata
announcement rather than publish the DataSet layout in plaintext.
`MetaDataPublisherTests.JsonAnnouncementOfASecuredWriterGroupIsRefusedAsync`
checks that nothing is published on the metadata topic and that the
refusal is counted in `EncryptionErrors`. `PubSubApplication.StartAsync`
returns after the initial announcement was sent or refused, so the check
needs no wait.

The test covers the fail-closed branch of
`PubSubConnection.EncodeOutboundAsync` and the refused-send return of
`SendNetworkMessageAsync`, two of the three changed lines the
patch-coverage report of #4712 listed as uncovered. Test-only change.

Review: the test double `RecordingTransport` guards its recorded sends
with a private `System.Threading.Lock` and exposes `SendCount` and
`GetSendsSnapshot()`, so the tests no longer lock the list itself
(b7e0ba4b1).

### Validation

| Command | Result |
| --- | --- |
| `dotnet test tests/Opc.Ua.PubSub.Tests -f net10.0 --filter
"Name~JsonAnnouncementOfASecuredWriterGroupIsRefusedAsync"` with the
fail-closed branch of `EncodeOutboundAsync` temporarily removed | Fails:
`Expected: no item String containing "/metadata/"`, but the announcement
was published on `opcua/json/metadata/p17/7/42` |
| `dotnet test tests/Opc.Ua.PubSub.Tests -f net10.0` | 1499 passed, 1
skipped |
| `dotnet test tests/Opc.Ua.PubSub.Tests -f net48 --filter
FullyQualifiedName~MetaDataPublisherTests` | 10 passed |
| On the merged head with the lock change (07142f7b3):
`MetaDataPublisherTests` on net10.0 (3 runs) and net48; the full
`Opc.Ua.PubSub.Tests` on net10.0 | 10 passed each; 1498 passed, 2
skipped (the UDP multicast loopback tests, which skip when loopback is
not available) |

## Related Issues

- Follow-up to #4712.

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
2026-10-11 14:04:59 +02:00
..