mirror of https://github.com/dapr/dotnet-sdk.git
60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
// ------------------------------------------------------------
|
|
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
// ------------------------------------------------------------
|
|
|
|
namespace Dapr.Client.Test
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using Grpc.Net.Client;
|
|
using Xunit;
|
|
using Autogenerated = Dapr.Client.Autogen.Grpc.v1;
|
|
|
|
public class DaprApiTokenTest
|
|
{
|
|
[Fact]
|
|
public async Task DaprCall_WithApiTokenEnvVar()
|
|
{
|
|
// Configure Client
|
|
Environment.SetEnvironmentVariable("DAPR_API_TOKEN", "test_token");
|
|
var httpClient = new TestHttpClient();
|
|
var daprClient = new DaprClientBuilder()
|
|
.UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient })
|
|
.Build();
|
|
|
|
var task = daprClient.GetSecretAsync("testStore", "test_key");
|
|
|
|
// Get Request and validate
|
|
httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
|
|
var request = await GrpcUtils.GetRequestFromRequestMessageAsync<Autogenerated.GetSecretRequest>(entry.Request);
|
|
|
|
entry.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_WithoutApiTokenEnvVar()
|
|
{
|
|
// Configure Client
|
|
var httpClient = new TestHttpClient();
|
|
var daprClient = new DaprClientBuilder()
|
|
.UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient })
|
|
.Build();
|
|
|
|
var task = daprClient.GetSecretAsync("testStore", "test_key");
|
|
|
|
// Get Request and validate
|
|
httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
|
|
var request = await GrpcUtils.GetRequestFromRequestMessageAsync<Autogenerated.GetSecretRequest>(entry.Request);
|
|
|
|
entry.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
|
|
headerValues.Should().BeNull();
|
|
}
|
|
}
|
|
}
|