Skip to content

Commit f2b46e0

Browse files
committed
Updated HttpContext gRPC conversion to fit updated identity protobuf.
1 parent 2fe0bab commit f2b46e0

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/WebJobs.Script.Grpc/WebJobs.Script.Grpc.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
</Reference>
4242
</ItemGroup>
4343

44-
<ItemGroup>
45-
<Folder Include="Messages\" />
46-
</ItemGroup>
47-
4844
<Target Name="GenerateProtoFiles" BeforeTargets="BeforeBuild" Inputs="azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto" Outputs="Messages/DotNet/FunctionRpc.cs;Messages/DotNet/FunctionRpcGrpc.cs">
4945
<Exec Command="./generate_protos.$(Ext)" />
5046
<ItemGroup>

src/WebJobs.Script.Grpc/generate_protos.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ mkdir %MSGDIR%
4747
set OUTDIR=%MSGDIR%\DotNet
4848
mkdir %OUTDIR%
4949

50-
for /D %%D in (%PROTO_PATH%\*) do for %%F in (%%D\*.proto) do %GRPC_TOOLS_PATH%\protoc.exe %%F --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_TOOLS_PATH%\grpc_csharp_plugin.exe --proto_path=%%D --proto_path=%PROTOBUF_TOOLS%
50+
@rem generate shared types
51+
for %%F in (%PROTO_PATH%\shared\*) do %GRPC_TOOLS_PATH%\protoc.exe %%F --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_TOOLS_PATH%\grpc_csharp_plugin.exe --proto_path=%PROTO_PATH% --proto_path=%PROTOBUF_TOOLS%
52+
53+
@rem generate other types
54+
for /D %%D in (%PROTO_PATH%\*) do for %%F in (%%D\*.proto) do %GRPC_TOOLS_PATH%\protoc.exe %%F --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_TOOLS_PATH%\grpc_csharp_plugin.exe --proto_path=%PROTO_PATH% --proto_path=%%D --proto_path=%PROTOBUF_TOOLS%
5155

5256
%GRPC_TOOLS_PATH%\protoc.exe %PROTO% --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_TOOLS_PATH%\grpc_csharp_plugin.exe --proto_path=%PROTO_PATH% --proto_path=%PROTOBUF_TOOLS%
5357

src/WebJobs.Script.Grpc/generate_protos.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ mkdir $MSGDIR
6666
OUTDIR=$MSGDIR/DotNet
6767
mkdir $OUTDIR
6868

69-
for d in $PROTO_PATH/*/*.proto; do
70-
$GRPC_TOOLS_PATH/protoc $d --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$GRPC_TOOLS_PATH/grpc_csharp_plugin --proto_path=$PROTO_PATH --proto_path=$PROTOBUF_TOOLS
69+
#generate shared types
70+
for f in $PROTO_PATH/shared/*.proto; do
71+
$GRPC_TOOLS_PATH/protoc $f --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$GRPC_TOOLS_PATH/grpc_csharp_plugin --proto_path=$PROTO_PATH --proto_path=$PROTOBUF_TOOLS
72+
done
73+
74+
#generate other types
75+
for f in $PROTO_PATH/*/*.proto; do
76+
$GRPC_TOOLS_PATH/protoc $f --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$GRPC_TOOLS_PATH/grpc_csharp_plugin --proto_path=$PROTO_PATH --proto_path=$PROTOBUF_TOOLS
7177
done
7278

7379
$GRPC_TOOLS_PATH/protoc $PROTO --csharp_out $OUTDIR --grpc_out=$OUTDIR --plugin=protoc-gen-grpc=$GRPC_TOOLS_PATH/grpc_csharp_plugin --proto_path=$PROTO_PATH --proto_path=$PROTOBUF_TOOLS

src/WebJobs.Script/Rpc/MessageExtensions/RpcMessageConversionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ public static TypedData ToRpc(this object value, ILogger logger)
112112
var rpcClaimsIdentity = new RpcClaimsIdentity();
113113
if (id.AuthenticationType != null)
114114
{
115-
rpcClaimsIdentity.AuthenticationType = id.AuthenticationType;
115+
rpcClaimsIdentity.AuthenticationType = new NullableString { Value = id.AuthenticationType };
116116
}
117117

118118
if (id.NameClaimType != null)
119119
{
120-
rpcClaimsIdentity.NameClaimType = id.NameClaimType;
120+
rpcClaimsIdentity.NameClaimType = new NullableString { Value = id.NameClaimType };
121121
}
122122

123123
if (id.RoleClaimType != null)
124124
{
125-
rpcClaimsIdentity.RoleClaimType = id.RoleClaimType;
125+
rpcClaimsIdentity.RoleClaimType = new NullableString { Value = id.RoleClaimType };
126126
}
127127

128128
foreach (var claim in id.Claims)

test/WebJobs.Script.Tests/Rpc/RpcMessageConversionExtensionsTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public void HttpObjects_ClaimsPrincipal()
104104
{
105105
new Claim("http://schemas.microsoft.com/2017/07/functions/claims/authlevel", "Function")
106106
}, "WebJobsAuthLevel");
107-
var claimsIdentities = new List<ClaimsIdentity> { claimsIdentity1, claimsIdentity2 };
107+
var claimsIdentity3 = new ClaimsIdentity();
108+
var claimsIdentities = new List<ClaimsIdentity> { claimsIdentity1, claimsIdentity2, claimsIdentity3 };
108109

109110
request.HttpContext.User = new ClaimsPrincipal(claimsIdentities);
110111

@@ -113,7 +114,7 @@ public void HttpObjects_ClaimsPrincipal()
113114
var identities = request.HttpContext.User.Identities.ToList();
114115
var rpcIdentities = rpcRequestObject.Http.Identities.ToList();
115116

116-
Assert.Equal(2, rpcIdentities.Count);
117+
Assert.Equal(claimsIdentities.Count, rpcIdentities.Count);
117118

118119
for (int i = 0; i < identities.Count; i++)
119120
{
@@ -123,9 +124,9 @@ public void HttpObjects_ClaimsPrincipal()
123124
Assert.NotNull(identity);
124125
Assert.NotNull(rpcIdentity);
125126

126-
Assert.Equal(rpcIdentity.AuthenticationType, identity.AuthenticationType);
127-
Assert.Equal(rpcIdentity.NameClaimType, identity.NameClaimType);
128-
Assert.Equal(rpcIdentity.RoleClaimType, identity.RoleClaimType);
127+
Assert.Equal(rpcIdentity.AuthenticationType?.Value, identity.AuthenticationType);
128+
Assert.Equal(rpcIdentity.NameClaimType?.Value, identity.NameClaimType);
129+
Assert.Equal(rpcIdentity.RoleClaimType?.Value, identity.RoleClaimType);
129130

130131
var claims = identity.Claims.ToList();
131132
for (int j = 0; j < claims.Count; j++)

0 commit comments

Comments
 (0)