Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Validate method invocation with extraneous headers #1355

Merged
merged 4 commits into from
Oct 11, 2024
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
29 changes: 29 additions & 0 deletions test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Linq;
using System.Net.Http.Headers;

namespace Dapr.Client.Test
{
using System;
Expand Down Expand Up @@ -654,8 +657,34 @@ public async Task CreateInvokeMethodRequest_WithData_CreatesJsonContentWithQuery
var actual = await content.ReadFromJsonAsync<Widget>(this.jsonSerializerOptions);
Assert.Equal(data.Color, actual.Color);
}

[Fact]
public async Task InvokeMethodWithoutResponse_WithExtraneousHeaders()
{
await using var client = TestClient.CreateForDaprClient(c =>
{
c.UseGrpcEndpoint("http://localhost").UseHttpEndpoint("https://test-endpoint:3501").UseJsonSerializationOptions(this.jsonSerializerOptions);
});

var req = await client.CaptureHttpRequestAsync(async DaprClient =>
{
var request = client.InnerClient.CreateInvokeMethodRequest(HttpMethod.Get, "test-app", "mymethod");
request.Headers.Add("test-api-key", "test");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "abc123");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

await DaprClient.InvokeMethodAsync(request);
});

req.Dismiss();

Assert.NotNull(req);
Assert.True(req.Request.Headers.Contains("test-api-key"));
Assert.Equal("test", req.Request.Headers.GetValues("test-api-key").First());
Assert.True(req.Request.Headers.Contains("Authorization"));
Assert.Equal("Bearer abc123", req.Request.Headers.GetValues("Authorization").First());
Assert.Equal("application/json", req.Request.Headers.GetValues("Accept").First());
}

[Fact]
public async Task InvokeMethodWithResponseAsync_ReturnsMessageWithoutCheckingStatus()
Expand Down
4 changes: 2 additions & 2 deletions test/Shared/TestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -394,7 +394,7 @@ public async Task<TestGrpcRequest<T>> CaptureGrpcRequestAsync<T>(Func<TClient, T
var task = operation(this.InnerClient);
if (task.IsFaulted)
{
// If the task throws, we want to bubble that up eaglerly.
// If the task throws, we want to bubble that up eagerly.
await task;
}

Expand Down
Loading