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
11 changes: 8 additions & 3 deletions src/Tests/WhatsAppModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using Moq;

namespace Devlooped.WhatsApp;

Expand Down Expand Up @@ -196,16 +197,20 @@ public async Task DeserializeReaction()
}

[Fact]
public void SerializeAnonymous()
public async Task SerializeAnonymous()
{
var response = Response.Create("123456789012345", "987654321098765", (client, cancellation) => Task.FromResult<string?>(null));
var response = Response.Create("123456789012345", "987654321098765", (client, cancellation) => Task.FromResult<string?>("asdf"));

var json = JsonSerializer.Serialize(response, JsonContext.DefaultOptions);

var message = JsonSerializer.Deserialize(json, JsonContext.Default.AnonymousResponse);

Assert.NotNull(message);
Assert.Null(message.Sender);

// the value is either null due to not being deserialized, or it's a dummy function that returns null
// since that's the default impl. in the [JsonConstructor]
if (message.Sender != null)
Assert.Null(await message.Sender.Invoke(Mock.Of<IWhatsAppClient>(), default));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/WhatsApp/AzureFunctionsWebhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<IActionResult> Message([HttpTrigger(AuthorizationLevel.Anonymo
logger.LogDebug("Received WhatsApp message: {Message}.", json);

// Detect encrypted flow request setup for flows endpoints
if (JsonSerializer.Deserialize<EncryptedFlowData>(json) is { } encrypted)
if (JsonSerializer.Deserialize<EncryptedFlowData>(json) is { Data.Length: > 0, IV.Length: > 0, Key.Length: > 0 } encrypted)
{
if (string.IsNullOrEmpty(metaOptions.Value.PrivateKey))
return new StatusCodeResult(421);
Expand Down