public void SimpleUnaryWithACLsDenied(NamedPipeChannelContextFactory factory)
        {
            PipeSecurity       security = new PipeSecurity();
            SecurityIdentifier sid      = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

            security.AddAccessRule(new PipeAccessRule(sid, PipeAccessRights.ReadWrite, AccessControlType.Allow));
            security.AddAccessRule(new PipeAccessRule(WindowsIdentity.GetCurrent().User, PipeAccessRights.ReadWrite, AccessControlType.Deny));

            NamedPipeServerOptions options = new NamedPipeServerOptions {
                PipeSecurity = security
            };

            using var ctx = factory.Create(options);
            var exception = Assert.Throws <UnauthorizedAccessException>(() => ctx.Client.SimpleUnary(new RequestMessage {
                Value = 10
            }));
        }
        public async Task CancelServerStreaming()
        {
            // Don't run for http (exception throwing is flaky)
            var factory = new NamedPipeChannelContextFactory();

            using var ctx = factory.Create();
            var cts  = new CancellationTokenSource();
            var call = ctx.Client.DelayedServerStreaming(new RequestMessage {
                Value = 3
            },
                                                         cancellationToken: cts.Token);

            cts.CancelAfter(100);
            Assert.True(await call.ResponseStream.MoveNext());
            Assert.Equal(3, call.ResponseStream.Current.Value);
            var exception = await Assert.ThrowsAsync <RpcException>(async() => await call.ResponseStream.MoveNext());

            Assert.Equal(StatusCode.Cancelled, exception.StatusCode);
        }
        public void SimpleUnaryWithACLs(NamedPipeChannelContextFactory factory)
        {
            PipeSecurity       security = new PipeSecurity();
            SecurityIdentifier sid      = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

            security.AddAccessRule(new PipeAccessRule(sid, PipeAccessRights.ReadWrite, AccessControlType.Allow));
            security.AddAccessRule(new PipeAccessRule(WindowsIdentity.GetCurrent().User, PipeAccessRights.FullControl, AccessControlType.Allow));

            NamedPipeServerOptions options = new NamedPipeServerOptions {
                PipeSecurity = security
            };

            using var ctx = factory.Create(options);
            var response = ctx.Client.SimpleUnary(new RequestMessage {
                Value = 10
            });

            Assert.Equal(10, response.Value);
            Assert.True(ctx.Impl.SimplyUnaryCalled);
        }
Beispiel #4
0
        public async Task CancellationRace(NamedPipeChannelContextFactory factory)
        {
            using var ctx = factory.Create();
            var random = new Random();

            for (int i = 0; i < 200; i++)
            {
                var cts      = new CancellationTokenSource();
                var response = ctx.Client.SimpleUnaryAsync(new RequestMessage {
                    Value = 10
                }, cancellationToken: cts.Token);
                Thread.Sleep(random.Next(10));
                cts.Cancel();
                // Either a result or cancellation is okay, but we shouldn't get any other errors
                try
                {
                    Assert.Equal(10, (await response).Value);
                }
                catch (RpcException ex)
                {
                    Assert.Equal(StatusCode.Cancelled, ex.StatusCode);
                }
            }
        }