Skip to content

Commit 9630a52

Browse files
committed
Fixed generate_protos.sh.
1 parent 8b4bac7 commit 9630a52

File tree

4 files changed

+66
-31
lines changed

4 files changed

+66
-31
lines changed

src/WebJobs.Script.Grpc/generate_protos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ OUTDIR=$MSGDIR/DotNet
6767
mkdir $OUTDIR
6868

6969
for d in $PROTO_PATH/*/*.proto; do
70-
$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
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
7171
done
7272

7373
$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/LanguageWorkerChannel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ internal void SendInvocationRequest(ScriptInvocationContext context)
399399
{
400400
if (pair.Value != null)
401401
{
402-
invocationRequest.TriggerMetadata.Add(pair.Key, pair.Value.ToRpc());
402+
invocationRequest.TriggerMetadata.Add(pair.Key, pair.Value.ToRpc(_workerChannelLogger));
403403
}
404404
}
405405
foreach (var input in context.Inputs)
406406
{
407407
invocationRequest.InputData.Add(new ParameterBinding()
408408
{
409409
Name = input.name,
410-
Data = input.val.ToRpc()
410+
Data = input.val.ToRpc(_workerChannelLogger)
411411
});
412412
}
413413

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Azure.WebJobs.Extensions.Http;
1212
using Microsoft.Azure.WebJobs.Script.Description;
1313
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
14+
using Microsoft.Extensions.Logging;
1415
using Newtonsoft.Json;
1516
using Newtonsoft.Json.Linq;
1617
using RpcDataType = Microsoft.Azure.WebJobs.Script.Grpc.Messages.TypedData.DataOneofCase;
@@ -46,7 +47,7 @@ public static object ToObject(this TypedData typedData)
4647
}
4748
}
4849

49-
public static TypedData ToRpc(this object value)
50+
public static TypedData ToRpc(this object value, ILogger logger)
5051
{
5152
TypedData typedData = new TypedData();
5253

@@ -105,23 +106,34 @@ public static TypedData ToRpc(this object value)
105106
// parse ClaimsPrincipal if exists
106107
if (request.HttpContext?.User?.Identities != null)
107108
{
109+
logger.LogDebug("HttpContext has ClaimsPrincipal; parsing to gRPC.");
108110
foreach (var id in request.HttpContext.User.Identities)
109111
{
110-
// asdf
111-
var rpcId = new RpcClaimsIdentity();
112+
var rpcClaimsIdentity = new RpcClaimsIdentity();
112113
if (id.AuthenticationType != null)
113114
{
114-
rpcId.AuthenticationType = id.AuthenticationType;
115+
rpcClaimsIdentity.AuthenticationType = id.AuthenticationType;
116+
}
117+
118+
if (id.NameClaimType != null)
119+
{
120+
rpcClaimsIdentity.NameClaimType = id.NameClaimType;
121+
}
122+
123+
if (id.RoleClaimType != null)
124+
{
125+
rpcClaimsIdentity.RoleClaimType = id.RoleClaimType;
115126
}
116-
rpcId.NameClaimType = id.NameClaimType;
117-
rpcId.RoleClaimType = id.RoleClaimType;
118127

119128
foreach (var claim in id.Claims)
120129
{
121-
rpcId.Claims.Add(new RpcClaim { Value = claim.Value, Type = claim.Type });
130+
if (claim.Type != null && claim.Value != null)
131+
{
132+
rpcClaimsIdentity.Claims.Add(new RpcClaim { Value = claim.Value, Type = claim.Type });
133+
}
122134
}
123135

124-
http.Identities.Add(rpcId);
136+
http.Identities.Add(rpcClaimsIdentity);
125137
}
126138
}
127139

@@ -165,8 +177,8 @@ public static TypedData ToRpc(this object value)
165177
}
166178

167179
request.Body.Position = 0;
168-
http.Body = body.ToRpc();
169-
http.RawBody = rawBody.ToRpc();
180+
http.Body = body.ToRpc(logger);
181+
http.RawBody = rawBody.ToRpc(logger);
170182
}
171183
}
172184
else

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

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public class RpcMessageConversionExtensionsTests
1919
[InlineData("application/x-www-form-urlencoded’", "say=Hi&to=Mom")]
2020
public void HttpObjects_StringBody(string expectedContentType, object body)
2121
{
22+
var logger = MockNullLoggerFactory.CreateLogger();
23+
2224
var headers = new HeaderDictionary();
2325
headers.Add("content-type", expectedContentType);
2426
HttpRequest request = HttpTestHelpers.CreateHttpRequest("GET", "http://localhost/api/httptrigger-scenarios", headers, body);
2527

26-
var rpcRequestObject = request.ToRpc();
28+
var rpcRequestObject = request.ToRpc(logger);
2729
Assert.Equal(body.ToString(), rpcRequestObject.Http.Body.String);
2830

2931
string contentType;
@@ -37,9 +39,11 @@ public void HttpObjects_StringBody(string expectedContentType, object body)
3739
[InlineData("say=Hi&to=", new string[] { "say" }, new string[] { "Hi" })] // Removes empty value query params
3840
public void HttpObjects_Query(string queryString, string[] expectedKeys, string[] expectedValues)
3941
{
42+
var logger = MockNullLoggerFactory.CreateLogger();
43+
4044
HttpRequest request = HttpTestHelpers.CreateHttpRequest("GET", $"http://localhost/api/httptrigger-scenarios?{queryString}");
4145

42-
var rpcRequestObject = request.ToRpc();
46+
var rpcRequestObject = request.ToRpc(logger);
4347
// Same number of expected key value pairs
4448
Assert.Equal(rpcRequestObject.Http.Query.Count, expectedKeys.Length);
4549
Assert.Equal(rpcRequestObject.Http.Query.Count, expectedValues.Length);
@@ -91,30 +95,49 @@ public void ToBindingInfo_Defaults_EmptyDataType()
9195
[Fact]
9296
public void HttpObjects_ClaimsPrincipal()
9397
{
98+
var logger = MockNullLoggerFactory.CreateLogger();
99+
94100
HttpRequest request = HttpTestHelpers.CreateHttpRequest("GET", $"http://localhost/apihttptrigger-scenarios");
95101

96-
MockEasyAuth(request, "facebook", "Connor McMahon", "10241897674253170");
102+
var claimsIdentity1 = MockEasyAuth("facebook", "Connor McMahon", "10241897674253170");
103+
var claimsIdentity2 = new ClaimsIdentity(new List<Claim>
104+
{
105+
new Claim("http://schemas.microsoft.com/2017/07/functions/claims/authlevel", "Function")
106+
}, "WebJobsAuthLevel");
107+
var claimsIdentities = new List<ClaimsIdentity> { claimsIdentity1, claimsIdentity2 };
108+
109+
request.HttpContext.User = new ClaimsPrincipal(claimsIdentities);
110+
111+
var rpcRequestObject = request.ToRpc(logger);
97112

98-
var rpcRequestObject = request.ToRpc();
99-
var identity = request.HttpContext.User.Identities.ToList().ElementAtOrDefault(0);
100-
var rpcIdentity = rpcRequestObject.Http.Identities.ElementAtOrDefault(0);
101-
Assert.NotNull(identity);
102-
Assert.NotNull(rpcIdentity);
113+
var identities = request.HttpContext.User.Identities.ToList();
114+
var rpcIdentities = rpcRequestObject.Http.Identities.ToList();
103115

104-
Assert.Equal(rpcIdentity.AuthenticationType, "facebook");
105-
Assert.Equal(rpcIdentity.NameClaimType, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name");
106-
Assert.Equal(rpcIdentity.RoleClaimType, "http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
116+
Assert.Equal(2, rpcIdentities.Count);
107117

108-
var claims = identity.Claims.ToList();
109-
for (int j = 0; j < claims.Count; j++)
118+
for (int i = 0; i < identities.Count; i++)
110119
{
111-
Assert.True(rpcIdentity.Claims.ElementAtOrDefault(j) != null);
112-
Assert.Equal(rpcIdentity.Claims[j].Type, claims[j].Type);
113-
Assert.Equal(rpcIdentity.Claims[j].Value, claims[j].Value);
120+
var identity = identities[i];
121+
var rpcIdentity = rpcIdentities.ElementAtOrDefault(i);
122+
123+
Assert.NotNull(identity);
124+
Assert.NotNull(rpcIdentity);
125+
126+
Assert.Equal(rpcIdentity.AuthenticationType, identity.AuthenticationType);
127+
Assert.Equal(rpcIdentity.NameClaimType, identity.NameClaimType);
128+
Assert.Equal(rpcIdentity.RoleClaimType, identity.RoleClaimType);
129+
130+
var claims = identity.Claims.ToList();
131+
for (int j = 0; j < claims.Count; j++)
132+
{
133+
Assert.True(rpcIdentity.Claims.ElementAtOrDefault(j) != null);
134+
Assert.Equal(rpcIdentity.Claims[j].Type, claims[j].Type);
135+
Assert.Equal(rpcIdentity.Claims[j].Value, claims[j].Value);
136+
}
114137
}
115138
}
116139

117-
internal static void MockEasyAuth(HttpRequest request, string provider, string name, string id)
140+
internal static ClaimsIdentity MockEasyAuth(string provider, string name, string id)
118141
{
119142
var claims = new List<Claim>
120143
{
@@ -129,7 +152,7 @@ internal static void MockEasyAuth(HttpRequest request, string provider, string n
129152
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
130153
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
131154

132-
request.HttpContext.User = new ClaimsPrincipal(new List<ClaimsIdentity> { identity });
155+
return identity;
133156
}
134157
}
135158
}

0 commit comments

Comments
 (0)