Skip to content

Commit

Permalink
Rollback from CloudEventEnvelope to CloudEvent as inbound model in Ev…
Browse files Browse the repository at this point in the history
…entsReceiver
  • Loading branch information
Ronny Birkeli committed Nov 7, 2022
1 parent 51fa5fa commit ee468e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/Altinn.App.Api/Controllers/EventsReceiverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,19 @@ public EventsReceiverController(
[ProducesResponseType(425)]
[ProducesResponseType(500)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult> Post([FromQuery] string code, [FromBody] CloudEventEnvelope cloudEventEnvelope)
public async Task<ActionResult> Post([FromQuery] string code, [FromBody] CloudEvent cloudEvent)
{
if (await _secretCodeProvider.GetSecretCode() != code)
{
return Unauthorized();
}

if (cloudEventEnvelope.CloudEvent == null)
if (cloudEvent.Type == null)
{
_logger.LogError("CloudEvent is null, unable to process event! Data received: {data}", JsonSerializer.Serialize(cloudEventEnvelope));
_logger.LogError("CloudEvent.Type is null, unable to process event! Data received: {data}", JsonSerializer.Serialize(cloudEvent));
return BadRequest();
}

CloudEvent cloudEvent = cloudEventEnvelope.CloudEvent;

IEventHandler eventHandler = _eventHandlerResolver.ResolveEventHandler(cloudEvent.Type);
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ public async Task Post_ValidEventType_ShouldReturnOk()
Time = DateTime.Parse("2022-10-13T09:33:46.6330634Z"),
AlternativeSubject = "/person/17858296439"
};
CloudEventEnvelope envelope = new() { CloudEvent = cloudEvent };

var org = "ttd";
var app = "non-existing-app";
string requestUrl = $"{org}/{app}/api/v1/eventsreceiver?code={await _secretCodeProvider.GetSecretCode()}";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl)
{
Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(envelope), Encoding.UTF8, "application/json")
Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(cloudEvent), Encoding.UTF8, "application/json")
};

HttpResponseMessage response = await client.SendAsync(request);
Expand All @@ -71,14 +70,13 @@ public async Task Post_NonValidEventType_ShouldReturnBadRequest()
Time = DateTime.Parse("2022-10-13T09:33:46.6330634Z"),
AlternativeSubject = "/person/17858296439"
};
CloudEventEnvelope envelope = new() { CloudEvent = null };

var org = "ttd";
var app = "non-existing-app";
string requestUrl = $"{org}/{app}/api/v1/eventsreceiver?code={await _secretCodeProvider.GetSecretCode()}";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl)
{
Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(envelope), Encoding.UTF8, "application/json")
Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(cloudEvent), Encoding.UTF8, "application/json")
};

HttpResponseMessage response = await client.SendAsync(request);
Expand Down

0 comments on commit ee468e5

Please sign in to comment.