Skip to content

Commit

Permalink
Fix: URL under Capability Statement not Absolute Uri (#3265)
Browse files Browse the repository at this point in the history
* Get absolute Uri

* Duplicated arg

* Fix Tests
  • Loading branch information
abiisnn authored May 1, 2023
1 parent 2074491 commit 05f5275
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,10 +56,11 @@ private CapabilityStatementBuilder(
_supportedProfiles = supportedProfiles;
}

public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> configuration, ISupportedProfilesStore supportedProfiles)
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions<CoreFeatureConfiguration> 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);
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IScoped<IEnumerable<IProvideCapability>>> _capabilityProviders;
private readonly List<Action<ListedCapabilityStatement>> _configurationUpdates = new List<Action<ListedCapabilityStatement>>();
private readonly IOptions<CoreFeatureConfiguration> _configuration;
Expand All @@ -54,14 +56,16 @@ public SystemConformanceProvider(
Func<IScoped<IEnumerable<IProvideCapability>>> capabilityProviders,
IOptions<CoreFeatureConfiguration> configuration,
ISupportedProfilesStore supportedProfiles,
ILogger<SystemConformanceProvider> logger)
ILogger<SystemConformanceProvider> logger,
IUrlResolver urlResolver)
{
EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));
EnsureArg.IsNotNull(searchParameterDefinitionManagerResolver, nameof(searchParameterDefinitionManagerResolver));
EnsureArg.IsNotNull(capabilityProviders, nameof(capabilityProviders));
EnsureArg.IsNotNull(configuration, nameof(configuration));
EnsureArg.IsNotNull(supportedProfiles, nameof(supportedProfiles));
EnsureArg.IsNotNull(logger, nameof(logger));
EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));

_modelInfoProvider = modelInfoProvider;
_searchParameterDefinitionManager = searchParameterDefinitionManagerResolver();
Expand All @@ -70,6 +74,7 @@ public SystemConformanceProvider(
_supportedProfiles = supportedProfiles;
_logger = logger;
_disposed = false;
_urlResolver = urlResolver;
}

public override async Task<ResourceElement> GetCapabilityStatementOnStartup(CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -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<IEnumerable<IProvideCapability>> providerFactory = _capabilityProviders())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand All @@ -44,11 +46,15 @@ public ConformanceBuilderTests()

_searchParameterDefinitionManager = Substitute.For<ISearchParameterDefinitionManager>();
_supportedProfiles = Substitute.For<ISupportedProfilesStore>();
_urlResolver = Substitute.For<IUrlResolver>();
_urlResolver.ResolveMetadataUrl(Arg.Any<bool>()).Returns(new System.Uri("https://test.com"));

_builder = CapabilityStatementBuilder.Create(
ModelInfoProvider.Instance,
_searchParameterDefinitionManager,
configuration,
_supportedProfiles);
_supportedProfiles,
_urlResolver);
}

[Fact]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 05f5275

Please sign in to comment.