From 05f5275f4275893c5a526cb1538be05daf1580a0 Mon Sep 17 00:00:00 2001 From: Abigail Nicolas Date: Mon, 1 May 2023 16:26:02 -0700 Subject: [PATCH] Fix: URL under Capability Statement not Absolute Uri (#3265) * Get absolute Uri * Duplicated arg * Fix Tests --- .../Conformance/CapabilityStatementBuilder.cs | 7 ++++++- .../Conformance/SystemConformanceProvider.cs | 9 +++++++-- .../Conformance/ConformanceBuilderTests.cs | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Health.Fhir.Core/Features/Conformance/CapabilityStatementBuilder.cs b/src/Microsoft.Health.Fhir.Core/Features/Conformance/CapabilityStatementBuilder.cs index 2651f2a296..60ae8b58f5 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Conformance/CapabilityStatementBuilder.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Conformance/CapabilityStatementBuilder.cs @@ -17,6 +17,7 @@ using Microsoft.Health.Fhir.Core.Features.Conformance.Models; using Microsoft.Health.Fhir.Core.Features.Conformance.Serialization; using Microsoft.Health.Fhir.Core.Features.Definition; +using Microsoft.Health.Fhir.Core.Features.Routing; using Microsoft.Health.Fhir.Core.Features.Search; using Microsoft.Health.Fhir.Core.Features.Validation; using Microsoft.Health.Fhir.Core.Features.Version; @@ -55,10 +56,11 @@ private CapabilityStatementBuilder( _supportedProfiles = supportedProfiles; } - public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions configuration, ISupportedProfilesStore supportedProfiles) + public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions configuration, ISupportedProfilesStore supportedProfiles, IUrlResolver urlResolver) { EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager)); + EnsureArg.IsNotNull(urlResolver, nameof(urlResolver)); using Stream resourceStream = modelInfoProvider.OpenVersionedFileStream("BaseCapabilities.json"); using var reader = new StreamReader(resourceStream); @@ -82,6 +84,9 @@ public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoPro statement.FhirVersion = modelInfoProvider.SupportedVersion.VersionString; statement.Date = ProductVersionInfo.CreationTime.ToString("O"); + + Uri baseUri = new Uri(urlResolver.ResolveMetadataUrl(false).ToString()); + statement.Url = new Uri(baseUri, "metadata"); return new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, configuration, supportedProfiles); } diff --git a/src/Microsoft.Health.Fhir.Core/Features/Conformance/SystemConformanceProvider.cs b/src/Microsoft.Health.Fhir.Core/Features/Conformance/SystemConformanceProvider.cs index 8b9db2f60d..cd285a12d8 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Conformance/SystemConformanceProvider.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Conformance/SystemConformanceProvider.cs @@ -17,6 +17,7 @@ using Microsoft.Health.Fhir.Core.Extensions; using Microsoft.Health.Fhir.Core.Features.Conformance.Models; using Microsoft.Health.Fhir.Core.Features.Definition; +using Microsoft.Health.Fhir.Core.Features.Routing; using Microsoft.Health.Fhir.Core.Features.Validation; using Microsoft.Health.Fhir.Core.Messages.CapabilityStatement; using Microsoft.Health.Fhir.Core.Models; @@ -36,6 +37,7 @@ public sealed class SystemConformanceProvider private readonly int _rebuildDelay = 240; // 4 hours in minutes private readonly IModelInfoProvider _modelInfoProvider; private readonly ISearchParameterDefinitionManager _searchParameterDefinitionManager; + private readonly IUrlResolver _urlResolver; private readonly Func>> _capabilityProviders; private readonly List> _configurationUpdates = new List>(); private readonly IOptions _configuration; @@ -54,7 +56,8 @@ public SystemConformanceProvider( Func>> capabilityProviders, IOptions configuration, ISupportedProfilesStore supportedProfiles, - ILogger logger) + ILogger logger, + IUrlResolver urlResolver) { EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); EnsureArg.IsNotNull(searchParameterDefinitionManagerResolver, nameof(searchParameterDefinitionManagerResolver)); @@ -62,6 +65,7 @@ public SystemConformanceProvider( EnsureArg.IsNotNull(configuration, nameof(configuration)); EnsureArg.IsNotNull(supportedProfiles, nameof(supportedProfiles)); EnsureArg.IsNotNull(logger, nameof(logger)); + EnsureArg.IsNotNull(urlResolver, nameof(urlResolver)); _modelInfoProvider = modelInfoProvider; _searchParameterDefinitionManager = searchParameterDefinitionManagerResolver(); @@ -70,6 +74,7 @@ public SystemConformanceProvider( _supportedProfiles = supportedProfiles; _logger = logger; _disposed = false; + _urlResolver = urlResolver; } public override async Task GetCapabilityStatementOnStartup(CancellationToken cancellationToken = default(CancellationToken)) @@ -89,7 +94,7 @@ public SystemConformanceProvider( { if (_listedCapabilityStatement == null) { - _builder = CapabilityStatementBuilder.Create(_modelInfoProvider, _searchParameterDefinitionManager, _configuration, _supportedProfiles); + _builder = CapabilityStatementBuilder.Create(_modelInfoProvider, _searchParameterDefinitionManager, _configuration, _supportedProfiles, _urlResolver); using (IScoped> providerFactory = _capabilityProviders()) { diff --git a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Conformance/ConformanceBuilderTests.cs b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Conformance/ConformanceBuilderTests.cs index 803ca09285..8c1319afbb 100644 --- a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Conformance/ConformanceBuilderTests.cs +++ b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Conformance/ConformanceBuilderTests.cs @@ -15,6 +15,7 @@ using Microsoft.Health.Fhir.Core.Features.Conformance; using Microsoft.Health.Fhir.Core.Features.Conformance.Models; using Microsoft.Health.Fhir.Core.Features.Definition; +using Microsoft.Health.Fhir.Core.Features.Routing; using Microsoft.Health.Fhir.Core.Features.Validation; using Microsoft.Health.Fhir.Core.Models; using Microsoft.Health.Fhir.Tests.Common; @@ -36,6 +37,7 @@ public partial class ConformanceBuilderTests private readonly ICapabilityStatementBuilder _builder; private readonly ISearchParameterDefinitionManager _searchParameterDefinitionManager; private readonly ISupportedProfilesStore _supportedProfiles; + private readonly IUrlResolver _urlResolver; public ConformanceBuilderTests() { @@ -44,11 +46,15 @@ public ConformanceBuilderTests() _searchParameterDefinitionManager = Substitute.For(); _supportedProfiles = Substitute.For(); + _urlResolver = Substitute.For(); + _urlResolver.ResolveMetadataUrl(Arg.Any()).Returns(new System.Uri("https://test.com")); + _builder = CapabilityStatementBuilder.Create( ModelInfoProvider.Instance, _searchParameterDefinitionManager, configuration, - _supportedProfiles); + _supportedProfiles, + _urlResolver); } [Fact] @@ -88,7 +94,8 @@ public void GivenAConformanceBuilder_WhenVersionofResourceIsDifferentFromDefault ModelInfoProvider.Instance, _searchParameterDefinitionManager, configuration, - supportedProfiles); + supportedProfiles, + _urlResolver); ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c => { c.Interaction.Add(new ResourceInteractionComponent @@ -118,7 +125,8 @@ public void GivenAConformanceBuilder_WhenResourceTypeOverridesContainsResourcesT ModelInfoProvider.Instance, _searchParameterDefinitionManager, configuration, - supportedProfiles); + supportedProfiles, + _urlResolver); ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c => { c.Interaction.Add(new ResourceInteractionComponent @@ -147,7 +155,8 @@ public void GivenAConformanceBuilder_WhenResourceTypeOverridesIsEmpty_ThenResour ModelInfoProvider.Instance, _searchParameterDefinitionManager, configuration, - supportedProfiles); + supportedProfiles, + _urlResolver); ICapabilityStatementBuilder capabilityStatement = builder.ApplyToResource("Patient", c => { c.Interaction.Add(new ResourceInteractionComponent