mirror of https://github.com/dapr/dotnet-sdk.git
58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
// ------------------------------------------------------------
|
|
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
// ------------------------------------------------------------
|
|
|
|
namespace Dapr.Client.Test
|
|
{
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
using Autogenerated = Dapr.Client.Autogen.Grpc.v1;
|
|
|
|
public class DaprApiTokenTest
|
|
{
|
|
[Fact]
|
|
public async Task DaprCall_WithApiTokenSet()
|
|
{
|
|
// Configure Client
|
|
await using var client = TestClient.CreateForDaprClient(c => c.UseDaprApiToken("test_token"));
|
|
|
|
var request = await client.CaptureGrpcRequestAsync(async daprClient =>
|
|
{
|
|
return await daprClient.GetSecretAsync("testStore", "test_key");
|
|
});
|
|
|
|
request.Dismiss();
|
|
|
|
// Get Request and validate
|
|
var envelope = await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();
|
|
|
|
request.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
|
|
headerValues.Count().Should().Be(1);
|
|
headerValues.First().Should().Be("test_token");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DaprCall_WithoutApiToken()
|
|
{
|
|
// Configure Client
|
|
await using var client = TestClient.CreateForDaprClient();
|
|
|
|
var request = await client.CaptureGrpcRequestAsync(async daprClient =>
|
|
{
|
|
return await daprClient.GetSecretAsync("testStore", "test_key");
|
|
});
|
|
|
|
request.Dismiss();
|
|
|
|
// Get Request and validate
|
|
var envelope = await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();
|
|
|
|
request.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
|
|
headerValues.Should().BeNull();
|
|
}
|
|
}
|
|
}
|