Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 3d4daf7

Browse files
Merge branch 'main' into Release-8.1.0
2 parents ec55651 + 69171af commit 3d4daf7

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/ApiService/ApiService/onefuzzlib/Events.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Events : IEvents {
3838
private readonly IContainers _containers;
3939
private readonly ICreds _creds;
4040
private readonly JsonSerializerOptions _options;
41+
private readonly JsonSerializerOptions _deserializingFromBlobOptions;
4142

4243
public Events(ILogTracer log, IOnefuzzContext context) {
4344
_queue = context.Queue;
@@ -49,6 +50,9 @@ public Events(ILogTracer log, IOnefuzzContext context) {
4950
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
5051
};
5152
_options.Converters.Add(new RemoveUserInfo());
53+
_deserializingFromBlobOptions = new JsonSerializerOptions(EntityConverter.GetJsonSerializerOptions()) {
54+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
55+
};
5256
}
5357

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

99-
var eventMessage = JsonSerializer.Deserialize<EventMessage>(blob, _options);
103+
var eventMessage = JsonSerializer.Deserialize<EventMessage>(blob, _deserializingFromBlobOptions);
100104
if (eventMessage == null) {
101105
return OneFuzzResult<EventMessage>.Error(ErrorCode.UNEXPECTED_DATA_SHAPE, $"Could not deserialize event with id {eventId}");
102106
}

src/ApiService/ApiService/onefuzzlib/WebhookOperations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface IWebhookOperations : IOrm<Webhook> {
1313
Async.Task<Webhook?> GetByWebhookId(Guid webhookId);
1414
Async.Task<OneFuzzResultVoid> Send(WebhookMessageLog messageLog);
1515
Task<EventPing> Ping(Webhook webhook);
16+
Task<OneFuzzResult<Tuple<string, string?>>> BuildMessage(Guid webhookId, Guid eventId, EventType eventType, BaseEvent webhookEvent, String? secretToken, WebhookMessageFormat? messageFormat);
17+
1618
}
1719

1820
public class WebhookOperations : Orm<Webhook>, IWebhookOperations {

src/ApiService/IntegrationTests/EventsTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Net;
56
using Azure.Storage.Blobs;
67
using FluentAssertions;
@@ -62,4 +63,52 @@ public async Async.Task BlobIsCreatedAndIsAccessible() {
6263
var eventData = await sr.ReadToEndAsync(); // read to make sure the SAS URL works
6364
eventData.Should().Contain(ping.PingId.ToString());
6465
}
66+
67+
[Fact]
68+
public async Async.Task UserInfoIsDeserialized() {
69+
var jobId = Guid.NewGuid();
70+
var taskId = Guid.NewGuid();
71+
var taskConfig = new TaskConfig(
72+
jobId,
73+
null,
74+
new TaskDetails(
75+
TaskType.Coverage,
76+
1
77+
)
78+
);
79+
var webhookId = Guid.NewGuid();
80+
var webhookName = "test-webhook";
81+
var appId = Guid.NewGuid();
82+
var objectId = Guid.NewGuid();
83+
var upn = Guid.NewGuid().ToString();
84+
85+
var insertWebhook = await Context.WebhookOperations.Insert(
86+
new Webhook(webhookId, webhookName, null, new List<EventType> { EventType.TaskStopped }, null, WebhookMessageFormat.Onefuzz)
87+
);
88+
insertWebhook.IsOk.Should().BeTrue();
89+
90+
await Context.Events.SendEvent(new EventTaskStopped(
91+
jobId,
92+
taskId,
93+
new UserInfo(
94+
appId,
95+
objectId,
96+
upn
97+
),
98+
taskConfig
99+
));
100+
101+
var webhookMessageLog = await Context.WebhookMessageLogOperations.SearchAll()
102+
.FirstAsync(wml => wml.WebhookId == webhookId && wml.EventType == EventType.TaskStopped);
103+
104+
webhookMessageLog.Should().NotBeNull();
105+
106+
var message = await Context.WebhookOperations.BuildMessage(webhookMessageLog.WebhookId, webhookMessageLog.EventId, webhookMessageLog.EventType, webhookMessageLog.Event, null, WebhookMessageFormat.Onefuzz);
107+
108+
message.IsOk.Should().BeTrue();
109+
var eventPayload = message.OkV!.Item1;
110+
111+
eventPayload.Should()
112+
.ContainAll(jobId.ToString(), taskId.ToString());
113+
}
65114
}

0 commit comments

Comments
 (0)