Skip to content

Commit

Permalink
tests: Test code to investigate auth failure modes
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed May 8, 2024
1 parent 4ffdce0 commit 75821eb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions issues/AuthFailureModes/AuthFailureModes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.Language.V1" Version="3.6.0" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions issues/AuthFailureModes/AuthFailureModes.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthFailureModes", "AuthFailureModes.csproj", "{B86F8B68-4FE5-4C54-ACA1-8F46EFCE650C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B86F8B68-4FE5-4C54-ACA1-8F46EFCE650C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B86F8B68-4FE5-4C54-ACA1-8F46EFCE650C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B86F8B68-4FE5-4C54-ACA1-8F46EFCE650C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B86F8B68-4FE5-4C54-ACA1-8F46EFCE650C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {438FF094-160E-4EBF-905A-D0C1F3791609}
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions issues/AuthFailureModes/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License"):
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Google.Api.Gax.Grpc;
using Google.Api.Gax.Grpc.Rest;
using Google.Cloud.Language.V1;

Test(new LanguageServiceClientBuilder { UseJwtAccessWithScopes = true });
Test(new LanguageServiceClientBuilder { UseJwtAccessWithScopes = false });
Test(new LanguageServiceClientBuilder { GrpcAdapter = RestGrpcAdapter.Default, UseJwtAccessWithScopes = true });
Test(new LanguageServiceClientBuilder { GrpcAdapter = RestGrpcAdapter.Default, UseJwtAccessWithScopes = false });
Test(new LanguageServiceClientBuilder { GrpcAdapter = GrpcCoreAdapter.Instance, UseJwtAccessWithScopes = true });
Test(new LanguageServiceClientBuilder { GrpcAdapter = GrpcCoreAdapter.Instance, UseJwtAccessWithScopes = false });

void Test(LanguageServiceClientBuilder builder)
{
Console.WriteLine($"GrpcAdapter: {builder.GrpcAdapter}");
Console.WriteLine($"UseJwtAccessWithScopes: {builder.UseJwtAccessWithScopes}");
try
{
var client = builder.Build();
var response = client.AnalyzeSyntax(Document.FromPlainText("It is raining"));
Console.WriteLine("Call succeeded");
}
catch (Exception e)
{
Console.WriteLine($"Failure: {e}");
}
Console.WriteLine();
}

0 comments on commit 75821eb

Please sign in to comment.