|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
| 4 | +using System.Linq; |
4 | 5 | using System.Net; |
5 | 6 | using Azure.Storage.Blobs; |
6 | 7 | using FluentAssertions; |
@@ -62,4 +63,52 @@ public async Async.Task BlobIsCreatedAndIsAccessible() { |
62 | 63 | var eventData = await sr.ReadToEndAsync(); // read to make sure the SAS URL works |
63 | 64 | eventData.Should().Contain(ping.PingId.ToString()); |
64 | 65 | } |
| 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 | + } |
65 | 114 | } |
0 commit comments