Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ApiService/ApiService/onefuzzlib/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Events : IEvents {
private readonly IContainers _containers;
private readonly ICreds _creds;
private readonly JsonSerializerOptions _options;
private readonly JsonSerializerOptions _deserializingFromBlobOptions;

public Events(ILogTracer log, IOnefuzzContext context) {
_queue = context.Queue;
Expand All @@ -49,6 +50,9 @@ public Events(ILogTracer log, IOnefuzzContext context) {
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
_options.Converters.Add(new RemoveUserInfo());
_deserializingFromBlobOptions = new JsonSerializerOptions(EntityConverter.GetJsonSerializerOptions()) {
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}

public virtual async Async.Task QueueSignalrEvent(DownloadableEventMessage message) {
Expand Down Expand Up @@ -96,7 +100,7 @@ public async Async.Task<OneFuzzResult<EventMessage>> GetEvent(Guid eventId) {
return OneFuzzResult<EventMessage>.Error(ErrorCode.UNABLE_TO_FIND, $"Could not find container for event with id {eventId}");
}

var eventMessage = JsonSerializer.Deserialize<EventMessage>(blob, _options);
var eventMessage = JsonSerializer.Deserialize<EventMessage>(blob, _deserializingFromBlobOptions);
if (eventMessage == null) {
return OneFuzzResult<EventMessage>.Error(ErrorCode.UNEXPECTED_DATA_SHAPE, $"Could not deserialize event with id {eventId}");
}
Expand Down
2 changes: 2 additions & 0 deletions src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IWebhookOperations : IOrm<Webhook> {
Async.Task<Webhook?> GetByWebhookId(Guid webhookId);
Async.Task<OneFuzzResultVoid> Send(WebhookMessageLog messageLog);
Task<EventPing> Ping(Webhook webhook);
Task<OneFuzzResult<Tuple<string, string?>>> BuildMessage(Guid webhookId, Guid eventId, EventType eventType, BaseEvent webhookEvent, String? secretToken, WebhookMessageFormat? messageFormat);

}

public class WebhookOperations : Orm<Webhook>, IWebhookOperations {
Expand Down
49 changes: 49 additions & 0 deletions src/ApiService/IntegrationTests/EventsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Azure.Storage.Blobs;
using FluentAssertions;
Expand Down Expand Up @@ -62,4 +63,52 @@ public async Async.Task BlobIsCreatedAndIsAccessible() {
var eventData = await sr.ReadToEndAsync(); // read to make sure the SAS URL works
eventData.Should().Contain(ping.PingId.ToString());
}

[Fact]
public async Async.Task UserInfoIsDeserialized() {
var jobId = Guid.NewGuid();
var taskId = Guid.NewGuid();
var taskConfig = new TaskConfig(
jobId,
null,
new TaskDetails(
TaskType.Coverage,
1
)
);
var webhookId = Guid.NewGuid();
var webhookName = "test-webhook";
var appId = Guid.NewGuid();
var objectId = Guid.NewGuid();
var upn = Guid.NewGuid().ToString();

var insertWebhook = await Context.WebhookOperations.Insert(
new Webhook(webhookId, webhookName, null, new List<EventType> { EventType.TaskStopped }, null, WebhookMessageFormat.Onefuzz)
);
insertWebhook.IsOk.Should().BeTrue();

await Context.Events.SendEvent(new EventTaskStopped(
jobId,
taskId,
new UserInfo(
appId,
objectId,
upn
),
taskConfig
));

var webhookMessageLog = await Context.WebhookMessageLogOperations.SearchAll()
.FirstAsync(wml => wml.WebhookId == webhookId && wml.EventType == EventType.TaskStopped);

webhookMessageLog.Should().NotBeNull();

var message = await Context.WebhookOperations.BuildMessage(webhookMessageLog.WebhookId, webhookMessageLog.EventId, webhookMessageLog.EventType, webhookMessageLog.Event, null, WebhookMessageFormat.Onefuzz);

message.IsOk.Should().BeTrue();
var eventPayload = message.OkV!.Item1;

eventPayload.Should()
.ContainAll(jobId.ToString(), taskId.ToString());
}
}