Skip to content

Commit

Permalink
Merge branch 'main' into xabpe/Start-from-Command-in-EDI
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersBallingPetersen committed Dec 18, 2024
2 parents 98e6d23 + 431e207 commit 9a5c787
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ namespace Energinet.DataHub.EDI.ArchivedMessages.IntegrationTests;
[Collection(nameof(ArchivedMessagesCollection))]
public class ArchivedMessagesWithOwnedRestrictionTests : IAsyncLifetime
{
private static readonly Guid _actorId = Guid.Parse("00000000-0000-0000-0000-000000000001");
private readonly IArchivedMessagesClient _sut;
private readonly ArchivedMessagesFixture _fixture;

private readonly ActorIdentity _authenticatedActor = new(
ActorNumber.Create("1234512345888"),
Restriction.Owned,
ActorRole.EnergySupplier,
Guid.Parse("00000000-0000-0000-0000-000000000001"));
_actorId);

public ArchivedMessagesWithOwnedRestrictionTests(ArchivedMessagesFixture fixture, ITestOutputHelper testOutputHelper)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ namespace Energinet.DataHub.EDI.ArchivedMessages.IntegrationTests;
[Collection(nameof(ArchivedMessagesCollection))]
public class ArchivedMessagesWithoutRestrictionTests : IAsyncLifetime
{
private static readonly Guid _actorId = Guid.Parse("00000000-0000-0000-0000-000000000001");
private readonly IArchivedMessagesClient _sut;
private readonly ArchivedMessagesFixture _fixture;

private readonly ActorIdentity _authenticatedActor = new(
ActorNumber.Create("1234512345811"),
Restriction.None,
ActorRole.MeteredDataAdministrator,
Guid.Parse("00000000-0000-0000-0000-000000000001"));
_actorId);

public ArchivedMessagesWithoutRestrictionTests(ArchivedMessagesFixture fixture, ITestOutputHelper testOutputHelper)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Energinet.DataHub.EDI.ArchivedMessages.IntegrationTests.Fixture;

public class ArchivedMessagesFixture : IDisposable, IAsyncLifetime
{
private readonly Guid _actorId = Guid.Parse("00000000-0000-0000-0000-000000000001");
private bool _disposed;

public AzuriteManager AzuriteManager { get; } = new(true);
Expand Down Expand Up @@ -113,7 +114,7 @@ public async Task InitializeAsync()
ActorNumber.Create("1234512345888"),
restriction: Restriction.None,
ActorRole.MeteredDataAdministrator,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
_actorId));

ArchivedMessagesClient = Services.GetRequiredService<IArchivedMessagesClient>();
}
Expand Down
8 changes: 4 additions & 4 deletions source/B2BApi.AppTests/Fixtures/B2BApiAppFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ public async Task InitializeAsync()
.CreateAsync();
LogStopwatch(stopwatch, nameof(IntegrationEventsTopicResource));

var processManagerTopic = await ServiceBusResourceProvider
ProcessManagerTopicResource = await ServiceBusResourceProvider
.BuildTopic("process-manager")
.Do(topic => appHostSettings.ProcessEnvironmentVariables
.Add($"{ProcessManagerServiceBusClientOptions.SectionName}__{nameof(ProcessManagerServiceBusClientOptions.TopicName)}", topic.Name))
.AddSubscription("process-manager-subscription")
.CreateAsync();
LogStopwatch(stopwatch, nameof(processManagerTopic));
LogStopwatch(stopwatch, nameof(ProcessManagerTopicResource));
await ServiceBusListenerMock.AddTopicSubscriptionListenerAsync(
topicName: processManagerTopic.Name,
subscriptionName: processManagerTopic.Subscriptions.Single().SubscriptionName);
topicName: ProcessManagerTopicResource.Name,
subscriptionName: ProcessManagerTopicResource.Subscriptions.Single().SubscriptionName);

await ServiceBusResourceProvider
.BuildQueue("edi-inbox")
Expand Down
11 changes: 4 additions & 7 deletions source/B2BApi/Authentication/MarketActorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ public bool Authenticate(ActorNumber? actorNumber, ActorRole? actorRole, string?
return false;
}

if (actorId is null)
{
// This is only possible in the case of certificate authentication, since the actor number above
// is retrieved from the actor id in case of token authentication.
_logger.LogWarning("Authenticated market actor identity has no actor id (ActorNumber={ActorNumber}, ActorRole={ActorRole}).", actorId, actorNumber.Value, actorRole.Code);
}

var actorIdGuid = Guid.TryParse(actorId, out var guidParseResult) ? guidParseResult : (Guid?)null;
if (actorIdGuid is null)
{
// This is only possible in the case of certificate authentication (ebIX), since the actor number above
// is retrieved from the actor id in case of token authentication.
_logger.LogWarning("Authenticated market actor identity has no valid actor id (ActorId={ActorId}, ActorNumber={ActorNumber}, ActorRole={ActorRole}).", actorId, actorNumber.Value, actorRole.Code);
}

_authenticatedActor.SetAuthenticatedActor(new ActorIdentity(
actorNumber,
Expand Down
3 changes: 1 addition & 2 deletions source/B2CWebApi.AppTests/B2CWebApi.AppTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

<ItemGroup>
<PackageReference Include="Energinet.DataHub.Core.Messaging" Version="6.1.1" />
<PackageReference Include="Energinet.DataHub.ProcessManager.Client" Version="0.14.2" />
<PackageReference Include="Energinet.DataHub.ProcessManager.Orchestrations.Abstractions" Version="0.2.3" />
<PackageReference Include="Energinet.DataHub.ProcessManager.Client" Version="0.14.3" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.34.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task When_MessageIsReceived_Then_BodyAndTransactionAndMessageIdAreP
senderActorNumber,
Restriction.Owned,
actorRole,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
ActorId));

// Act
var registerAndSendAsync = await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task AndGiven_DdmMdrHackIsApplicable_When_MessageIsReceived_Then_Bo
var authenticatedActor = GetService<AuthenticatedActor>();
var senderActorNumber = ActorNumber.Create("5799999933318");
authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.GridAccessProvider, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.GridAccessProvider, ActorId));

// Act
await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
Expand Down Expand Up @@ -182,7 +182,7 @@ public async Task AndGiven_ServiceBusFails_When_MessageIsReceived_Then_Transacti
senderActorNumber,
Restriction.Owned,
actorRole,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
ActorId));

_senderSpy.ShouldFail = true;

Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task AndGiven_MultipleRequestsWithSameTransactionAndMessageId_When_
senderActorNumber,
Restriction.Owned,
actorRole,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
ActorId));

// new scope to simulate a race condition.
var sessionProvider = GetService<IServiceProvider>();
Expand Down Expand Up @@ -284,7 +284,7 @@ public async Task AndGiven_ASecondRequestWithSameTransactionIdAndMessageId_When_
senderActorNumber,
Restriction.Owned,
authenticatedActorRole,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
ActorId));

// new scope to simulate a race condition.
var sessionProvider = GetService<IServiceProvider>();
Expand All @@ -297,7 +297,7 @@ public async Task AndGiven_ASecondRequestWithSameTransactionIdAndMessageId_When_
senderActorNumber,
Restriction.None,
authenticatedActorRole,
Guid.Parse("00000000-0000-0000-0000-000000000001")));
ActorId));

var task01 = _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
incomingMarketMessageStream,
Expand Down Expand Up @@ -340,7 +340,7 @@ public async Task AndGiven_FaultyRequest_When_MessageIsReceived_Then_Transaction
var senderActorNumber = ActorNumber.Create("5799999933318");
var authenticatedActor = GetService<AuthenticatedActor>();
authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, ActorId));

// Act
await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
Expand Down Expand Up @@ -370,7 +370,7 @@ public async Task When_MessageIsReceived_Then_IncomingMessageIsArchivedWithCorre
var authenticatedActor = GetService<AuthenticatedActor>();
var senderActorNumber = ActorNumber.Create("5799999933318");
authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, ActorId));

var messageStream = ReadFile(@"IncomingMessages\RequestAggregatedMeasureDataAsDdk.json");

Expand Down Expand Up @@ -406,7 +406,7 @@ public async Task When_MeteredDataForMeasurementPointMessageIsReceived_Then_Inco
var authenticatedActor = GetService<AuthenticatedActor>();
var senderActorNumber = ActorNumber.Create("5790001330552");
authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.MeteredDataResponsible, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.MeteredDataResponsible, ActorId));

var messageStream = ReadFile(@"IncomingMessages\EbixMeteredDataForMeasurementPoint.xml");

Expand Down Expand Up @@ -450,7 +450,7 @@ public async Task When_MessageIsReceived_Then_IncomingMessageIsArchivedWithCorre
var senderActorNumber = ActorNumber.Create("5799999933318");
var authenticatedActor = GetService<AuthenticatedActor>();
authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(senderActorNumber, Restriction.Owned, ActorRole.BalanceResponsibleParty, ActorId));

var messageStream = ReadFile(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task AndGiven_MessageFromDelegated_When_Received_Then_ActorProperti
var documentFormat = DocumentFormat.Json;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, ActorId));

var messageStream = RequestAggregatedMeasureDataRequestBuilder.CreateIncomingMessage(
DocumentFormat.Json,
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task AndGiven_MessageFromDelegated_AndGiven_DelegationHasStopped_Wh
var documentFormat = DocumentFormat.Json;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, ActorId));

var messageStream = RequestAggregatedMeasureDataRequestBuilder.CreateIncomingMessage(
DocumentFormat.Json,
Expand Down Expand Up @@ -204,7 +204,7 @@ public async Task AndGiven_RequestMessageActorIsNotSameAsDelegatedBy_When_Receiv
var documentFormat = DocumentFormat.Json;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, ActorId));

var messageStream = RequestAggregatedMeasureDataRequestBuilder.CreateIncomingMessage(
DocumentFormat.Json,
Expand Down Expand Up @@ -270,7 +270,7 @@ public async Task
var documentFormat = DocumentFormat.Json;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(_delegatedTo.ActorNumber, Restriction.Owned, _delegatedTo.ActorRole, ActorId));

var energySupplier = requestDataForEnergySupplierId != null
? ActorNumber.Create(requestDataForEnergySupplierId)
Expand Down Expand Up @@ -362,7 +362,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
var documentFormat = DocumentFormat.Ebix;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(delegatedToAsDelegated.ActorNumber, Restriction.Owned, delegatedToAsDelegated.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(delegatedToAsDelegated.ActorNumber, Restriction.Owned, delegatedToAsDelegated.ActorRole, ActorId));

var messageStream = MeteredDataForMeasurementPointBuilder.CreateIncomingMessage(
documentFormat,
Expand Down Expand Up @@ -418,7 +418,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
var documentFormat = DocumentFormat.Ebix;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(delegatedToAsDelegated.ActorNumber, Restriction.Owned, delegatedToAsDelegated.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(delegatedToAsDelegated.ActorNumber, Restriction.Owned, delegatedToAsDelegated.ActorRole, ActorId));

var messageStream = MeteredDataForMeasurementPointBuilder.CreateIncomingMessage(
documentFormat,
Expand Down Expand Up @@ -458,7 +458,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
var documentFormat = DocumentFormat.Ebix;

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(delegatedToAsGridAccessProvider.ActorNumber, Restriction.Owned, delegatedToAsGridAccessProvider.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(delegatedToAsGridAccessProvider.ActorNumber, Restriction.Owned, delegatedToAsGridAccessProvider.ActorRole, ActorId));

var messageStream = MeteredDataForMeasurementPointBuilder.CreateIncomingMessage(
documentFormat,
Expand Down Expand Up @@ -514,7 +514,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
_clockStub.SetCurrentInstant(now);

_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(delegatedToAsGridAccessProvider.ActorNumber, Restriction.Owned, delegatedToAsGridAccessProvider.ActorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(delegatedToAsGridAccessProvider.ActorNumber, Restriction.Owned, delegatedToAsGridAccessProvider.ActorRole, ActorId));
var documentFormat = DocumentFormat.Ebix;

var messageStream = MeteredDataForMeasurementPointBuilder.CreateIncomingMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GivenIncomingMeteredDataForMeasurementMessageTests(
ActorNumber.Create("1234567890123"),
restriction: Restriction.None,
ActorRole.FromCode("DDM"),
Guid.Parse("00000000-0000-0000-0000-000000000001"));
ActorId);
authenticatedActor.SetAuthenticatedActor(_actorIdentity);

_validateIncomingMessage = GetService<ValidateIncomingMessage>();
Expand Down Expand Up @@ -297,7 +297,7 @@ public async Task When_AuthenticatedSenderRoleIsIncorrect_Then_ResultContainExce
var documentFormat = DocumentFormat.Ebix;
var authenticatedActor = GetService<AuthenticatedActor>();
var invalidSenderRole = ActorRole.EnergySupplier;
var actorIdentity = new ActorIdentity(ActorNumber.Create("1234567890123"), restriction: Restriction.None, invalidSenderRole, Guid.Parse("00000000-0000-0000-0000-000000000001"));
var actorIdentity = new ActorIdentity(ActorNumber.Create("1234567890123"), restriction: Restriction.None, invalidSenderRole, ActorId);
authenticatedActor.SetAuthenticatedActor(actorIdentity);
var message = MeteredDataForMeasurementPointBuilder.CreateIncomingMessage(
documentFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ protected IncomingMessagesTestBase(IncomingMessagesTestFixture incomingMessagesT
_incomingMessagesContext = GetService<IncomingMessagesContext>();
AuthenticatedActor = GetService<AuthenticatedActor>();
AuthenticatedActor.SetAuthenticatedActor(
new ActorIdentity(ActorNumber.Create("1234512345888"), Restriction.None, ActorRole.EnergySupplier, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(ActorNumber.Create("1234512345888"), Restriction.None, ActorRole.EnergySupplier, ActorId));
}

protected Guid ActorId => Guid.Parse("00000000-0000-0000-0000-000000000001");

protected IncomingMessagesTestFixture Fixture { get; }

protected FeatureFlagManagerStub FeatureFlagManagerStub { get; } = new();
Expand Down
7 changes: 4 additions & 3 deletions source/IntegrationTests/Behaviours/BehavioursTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace Energinet.DataHub.EDI.IntegrationTests.Behaviours;
public class BehavioursTestBase : IDisposable
{
private const string MockServiceBusName = "mock-name";
private readonly Guid _actorId = Guid.Parse("00000000-0000-0000-0000-000000000001");
private readonly ServiceBusSenderFactoryStub _serviceBusSenderFactoryStub;
private readonly ProcessContext _processContext;
private readonly IncomingMessagesContext _incomingMessagesContext;
Expand Down Expand Up @@ -153,7 +154,7 @@ protected BehavioursTestBase(IntegrationTestFixture integrationTestFixture, ITes
_incomingMessagesContext = GetService<IncomingMessagesContext>();
_authenticatedActor = GetService<AuthenticatedActor>();
_authenticatedActor.SetAuthenticatedActor(
new ActorIdentity(ActorNumber.Create("1234512345888"), Restriction.None, ActorRole.DataHubAdministrator, Guid.Parse("00000000-0000-0000-0000-000000000001")));
new ActorIdentity(ActorNumber.Create("1234512345888"), Restriction.None, ActorRole.DataHubAdministrator, _actorId));
}

private TestAggregatedTimeSeriesRequestAcceptedHandlerSpy TestAggregatedTimeSeriesRequestAcceptedHandlerSpy { get; }
Expand Down Expand Up @@ -242,7 +243,7 @@ await GetService<IInboxEventReceiver>().

protected void GivenAuthenticatedActorIs(ActorNumber actorNumber, ActorRole actorRole)
{
_authenticatedActor.SetAuthenticatedActor(new ActorIdentity(actorNumber, Restriction.Owned, actorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
_authenticatedActor.SetAuthenticatedActor(new ActorIdentity(actorNumber, Restriction.Owned, actorRole, _actorId));
}

protected void GivenNowIs(int year, int month, int day)
Expand Down Expand Up @@ -350,7 +351,7 @@ protected async Task GivenIntegrationEventReceived(IEventMessage @event)
await using var scope = _serviceProvider.CreateAsyncScope();
var outgoingMessagesClient = scope.ServiceProvider.GetRequiredService<IOutgoingMessagesClient>();
var authenticatedActor = scope.ServiceProvider.GetRequiredService<AuthenticatedActor>();
authenticatedActor.SetAuthenticatedActor(new ActorIdentity(actorNumber, Restriction.Owned, actorRole, Guid.Parse("00000000-0000-0000-0000-000000000001")));
authenticatedActor.SetAuthenticatedActor(new ActorIdentity(actorNumber, Restriction.Owned, actorRole, _actorId));
var peekResult = await outgoingMessagesClient.PeekAndCommitAsync(new PeekRequestDto(actorNumber, messageCategory, actorRole, documentFormat), CancellationToken.None);
return peekResult;
}
Expand Down
Loading

0 comments on commit 9a5c787

Please sign in to comment.