mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-18 22:55:08 +08:00
7e25e1a3d7
# Description The shared AI deployment contracts and instance registration; DI software-upload outcomes, digest handling and simulator; bounded Positioning/Pumps reads; PubSub raw-data/matrix and security-provider handling; Vision read-quality contracts; xRegistry resource writes and instance projection; OpenUSD authoring, embedded viewport and retained-frame capture APIs; standalone sample CLI controls; and the generic Debug/RID package-policy and fork/Dependabot coverage-comment fixes. The Linux native prerequisite step is retained for **Vision tests only**. ## Related Issues - Related tracking issue: [#4461](https://github.com/OPCFoundation/UA-.NETStandard/issues/4461), without automatic closure. - Source work: [#4462](https://github.com/OPCFoundation/UA-.NETStandard/pull/4462), which remains intact for the coordinator's later integration. - Immediate stacked predecessor: [#4804](https://github.com/OPCFoundation/UA-.NETStandard/pull/4804). ## Checklist _Put an `x` in the boxes that apply. You can complete these step by step after opening the PR._ - [ ] 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. - [ ] 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. - [ ] 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.
210 lines
7.9 KiB
C#
210 lines
7.9 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Client;
|
|
using Opc.Ua.Di.Client;
|
|
using Opc.Ua.Di.Server.Builders;
|
|
using Opc.Ua.Di.Server.SoftwareUpdate;
|
|
|
|
namespace Opc.Ua.Di.Tests
|
|
{
|
|
/// <summary>
|
|
/// Drives <see cref="SoftwareUpdateClient.UploadPackageAsync(Stream, string, int?, CancellationToken)"/>
|
|
/// against the in-process <see cref="DiServerFixture"/> via the
|
|
/// <see cref="DiInProcessSessionBridge"/> Moq-backed
|
|
/// <see cref="ISession"/> so the client + server wiring are exercised
|
|
/// together without standing up a real TCP endpoint.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("DI")]
|
|
[Category("SoftwareUpdate")]
|
|
[Category("FileTransfer")]
|
|
[Category("Integration")]
|
|
public sealed class SoftwareUpdateClientUploadIntegrationTests
|
|
{
|
|
private DiServerFixture m_fixture = null!;
|
|
private MemoryPackageStore m_store = null!;
|
|
|
|
[SetUp]
|
|
public async Task SetUpAsync()
|
|
{
|
|
m_fixture = new DiServerFixture();
|
|
await m_fixture.StartAsync().ConfigureAwait(false);
|
|
m_store = new MemoryPackageStore();
|
|
}
|
|
|
|
[TearDown]
|
|
public async Task TearDownAsync()
|
|
{
|
|
await m_fixture.DisposeAsync().ConfigureAwait(false);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UploadPackageAsyncCommitsPayloadToPackageStore()
|
|
{
|
|
(NodeState su, _) = await CreateDeviceWithSuAsync("UploadE2E")
|
|
.ConfigureAwait(false);
|
|
|
|
Mock<ISession> sessionMock = DiInProcessSessionBridge.Build(m_fixture);
|
|
var client = new SoftwareUpdateClient(
|
|
sessionMock.Object,
|
|
su.NodeId,
|
|
NullTelemetry());
|
|
|
|
byte[] payload = MakeSequentialPayload(12_288);
|
|
const string packageId = "upload-integration-1";
|
|
|
|
long uploaded = await client
|
|
.UploadPackageAsync(payload, packageId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(uploaded, Is.EqualTo(payload.LongLength));
|
|
byte[] stored = await ReadAllAsync(m_store, packageId)
|
|
.ConfigureAwait(false);
|
|
Assert.That(
|
|
stored,
|
|
Is.EqualTo(payload),
|
|
"Stored package bytes must match the uploaded payload.");
|
|
SoftwarePackage? metadata = await m_store.GetAsync(packageId).ConfigureAwait(false);
|
|
Assert.That(metadata!.Hash, Is.EqualTo(CoreUtils.ToHexString(SHA256.HashData(payload))));
|
|
}
|
|
|
|
[Test]
|
|
public async Task UploadPackageAsyncStreamOverloadStreamsViaCustomChunkSize()
|
|
{
|
|
(NodeState su, _) = await CreateDeviceWithSuAsync("UploadStream")
|
|
.ConfigureAwait(false);
|
|
|
|
Mock<ISession> sessionMock = DiInProcessSessionBridge.Build(m_fixture);
|
|
var client = new SoftwareUpdateClient(
|
|
sessionMock.Object,
|
|
su.NodeId,
|
|
NullTelemetry());
|
|
|
|
byte[] payload = MakeSequentialPayload(5000);
|
|
using var ms = new MemoryStream(payload, writable: false);
|
|
|
|
long uploaded = await client.UploadPackageAsync(
|
|
ms,
|
|
suggestedPackageId: "stream-upload",
|
|
chunkSizeBytes: 1024)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(uploaded, Is.EqualTo(payload.LongLength));
|
|
byte[] stored = await ReadAllAsync(m_store, "stream-upload")
|
|
.ConfigureAwait(false);
|
|
Assert.That(stored, Is.EqualTo(payload));
|
|
}
|
|
|
|
[Test]
|
|
public async Task UploadPackageAsyncEmptyPayloadStillCommitsEmptyPackage()
|
|
{
|
|
(NodeState su, _) = await CreateDeviceWithSuAsync("UploadEmpty")
|
|
.ConfigureAwait(false);
|
|
|
|
Mock<ISession> sessionMock = DiInProcessSessionBridge.Build(m_fixture);
|
|
var client = new SoftwareUpdateClient(
|
|
sessionMock.Object,
|
|
su.NodeId,
|
|
NullTelemetry());
|
|
|
|
long uploaded = await client
|
|
.UploadPackageAsync([], "empty-package")
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(uploaded, Is.Zero);
|
|
byte[] stored = await ReadAllAsync(m_store, "empty-package")
|
|
.ConfigureAwait(false);
|
|
Assert.That(stored, Has.Length.EqualTo(0));
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
// helpers
|
|
// ------------------------------------------------------------------
|
|
|
|
private async Task<(NodeState Su, PackageLoadingState Loading)>
|
|
CreateDeviceWithSuAsync(string deviceName)
|
|
{
|
|
IDeviceBuilder<DeviceState> builder = await m_fixture.Manager
|
|
.CreateDeviceAsync(
|
|
new QualifiedName(
|
|
deviceName,
|
|
m_fixture.Manager.DiNamespaceIndex))
|
|
.ConfigureAwait(false);
|
|
builder.WithSoftwareUpdate(m_store);
|
|
|
|
ushort diNs = m_fixture.Manager.DiNamespaceIndex;
|
|
ISystemContext ctx = m_fixture.Manager.SystemContext;
|
|
NodeState su = builder.Device.FindChild(
|
|
ctx,
|
|
new QualifiedName("SoftwareUpdate", diNs))!;
|
|
var loading = (PackageLoadingState)su.FindChild(
|
|
ctx,
|
|
new QualifiedName("Loading", diNs))!;
|
|
return (su, loading);
|
|
}
|
|
|
|
private static async Task<byte[]> ReadAllAsync(
|
|
MemoryPackageStore store,
|
|
string packageId)
|
|
{
|
|
// 'using' (sync dispose) instead of 'await using' so the
|
|
// assertion helper compiles on net48 where System.IO.Stream
|
|
// does not implement IAsyncDisposable.
|
|
using Stream stream = await store
|
|
.OpenReadAsync(packageId, CancellationToken.None)
|
|
.ConfigureAwait(false);
|
|
using var ms = new MemoryStream();
|
|
await stream.CopyToAsync(ms).ConfigureAwait(false);
|
|
return ms.ToArray();
|
|
}
|
|
|
|
private static ITelemetryContext NullTelemetry()
|
|
{
|
|
return new Mock<ITelemetryContext>().Object;
|
|
}
|
|
|
|
private static byte[] MakeSequentialPayload(int length)
|
|
{
|
|
byte[] bytes = new byte[length];
|
|
for (int i = 0; i < bytes.Length; i++)
|
|
{
|
|
bytes[i] = (byte)(i & 0xFF);
|
|
}
|
|
return bytes;
|
|
}
|
|
}
|
|
}
|