public void Manager_Sets_Service_ACLs_On_Memory() { // arrange var networkServiceSid = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null); var networkServiceAccount = networkServiceSid.Translate(typeof(NTAccount)); var servicePrincipal = new[] { networkServiceAccount.ToString() }; var self = WindowsIdentity.GetCurrent().User; // act using (var mcb = new MemoryManager.ManagedCommunicationBlock("Local", _key, 100, 1, servicePrincipal)) using (var mmb = new MemoryManager.ManagedMemoryBlock("Local", _key, 100, 1, servicePrincipal)) { var mcbRules = mcb.MemoryAcl.GetAccessRules(true, false, typeof(SecurityIdentifier)); var mmbRules = mmb.MemoryAcl.GetAccessRules(true, false, typeof(SecurityIdentifier)); var rules = new[] { mcbRules, mmbRules }; // assert foreach (var ruleset in rules) { Assert.That(ruleset.Count, Is.EqualTo(2)); Assert.That(ruleset.Cast <AccessRule>().Any(r => r.IdentityReference == networkServiceSid)); Assert.That(ruleset.Cast <AccessRule>() .Where(r => r.IdentityReference == networkServiceSid) .Any(r => r.AccessControlType == AccessControlType.Allow)); Assert.That(ruleset.Cast <AccessRule>().Any(r => r.IdentityReference == self)); Assert.That(ruleset.Cast <AccessRule>() .Where(r => r.IdentityReference == self) .Any(r => r.AccessControlType == AccessControlType.Allow)); } } }
public void Manager_Handles_Profiler_ResultsReady() { // arrange EventWaitHandle standardMessageReady = null; EventWaitHandle offloadComplete = new AutoResetEvent(false); using (var mcb = new MemoryManager.ManagedCommunicationBlock("Local", _key, 100, 1, Enumerable.Empty <string>())) using (var mmb = new MemoryManager.ManagedMemoryBlock("Local", _key, 100, 1, Enumerable.Empty <string>())) { Container.GetMock <ICommunicationManager>() .Setup(x => x.HandleCommunicationBlock(It.IsAny <IManagedCommunicationBlock>(), It.IsAny <Action <IManagedCommunicationBlock, IManagedMemoryBlock> >())) .Callback <IManagedCommunicationBlock, Action <IManagedCommunicationBlock, IManagedMemoryBlock> >((_, offload) => { standardMessageReady.Reset(); mcb.ProfilerRequestsInformation.Reset(); offload(mcb, mmb); offloadComplete.Set(); }); // act var dict = new StringDictionary(); RunProcess(dict, standardMessageDataReady => { standardMessageReady = standardMessageDataReady; }, () => { offloadComplete.WaitOne(); mcb.ProfilerRequestsInformation.Set(); offloadComplete.WaitOne(); }); } // assert Container.GetMock <ICommunicationManager>() .Verify(x => x.HandleCommunicationBlock(It.IsAny <IManagedCommunicationBlock>(), It.IsAny <Action <IManagedCommunicationBlock, IManagedMemoryBlock> >()), Times.Exactly(2)); }
public void Manager_Handles_Profiler_StandardMessageEvent() { // arrange EventWaitHandle standardMessageReady = null; using (EventWaitHandle offloadComplete = new AutoResetEvent(false)) { var blockHandled = new ManualResetEvent(false); Container.GetMock <ICommunicationManager>() .Setup(x => x.HandleMemoryBlock(It.IsAny <IManagedMemoryBlock>())) .Returns <IManagedMemoryBlock>(mmb => { mmb.ProfilerHasResults.Reset(); blockHandled.Set(); return(new byte[4]); }); using (var mcb = new MemoryManager.ManagedCommunicationBlock("Local", _key, 100, -5, Enumerable.Empty <string>())) using (var mmb = new MemoryManager.ManagedMemoryBlock("Local", _key, 100, -5, Enumerable.Empty <string>())) { Container.GetMock <ICommunicationManager>() .Setup(x => x.HandleCommunicationBlock(It.IsAny <IManagedCommunicationBlock>(), It.IsAny <Action <ManagedBufferBlock> >())) .Callback <IManagedCommunicationBlock, Action <ManagedBufferBlock> >((_, offload) => { standardMessageReady?.Reset(); offload(new ManagedBufferBlock { CommunicationBlock = mcb, MemoryBlock = mmb }); offloadComplete.Set(); }); // act var dict = new StringDictionary(); RunProcess(dict, standardMessageDataReady => { standardMessageReady = standardMessageDataReady; }, () => { offloadComplete.WaitOne(); mmb.ProfilerHasResults.Set(); blockHandled.WaitOne(); }); } } // assert Container.GetMock <ICommunicationManager>() .Verify(x => x.HandleMemoryBlock(It.IsAny <IManagedMemoryBlock>()), Times.Once()); }
public void HandleMemoryBlock_Returns_Block_Informs_Profiler_When_Read() { // arrange var mcb = new MemoryManager.ManagedMemoryBlock("Local", "XYZ", 100, 0); // act byte[] data = null; ThreadPool.QueueUserWorkItem(state => { data = Instance.HandleMemoryBlock(mcb); }); // assert Assert.IsTrue(mcb.ResultsHaveBeenReceived.WaitOne(new TimeSpan(0, 0, 0, 1)), "Profiler wasn't signalled"); Assert.AreEqual(100, data.Count()); }
public void HandleMemoryBlock_Returns_Block_Informs_Profiler_When_Read() { // arrange var wait = new AutoResetEvent(false); using (var mcb = new MemoryManager.ManagedMemoryBlock("Local", "XYZ", 100, 0, Enumerable.Empty <string>())) { // act byte[] data = null; ThreadPool.QueueUserWorkItem(state => { data = Instance.HandleMemoryBlock(mcb); wait.Set(); }); wait.WaitOne(); // assert Assert.IsTrue(mcb.ResultsHaveBeenReceived.WaitOne(new TimeSpan(0, 0, 0, 4)), "Profiler wasn't signalled"); Assert.AreEqual(100, data.Count()); } }
public void HandleMemoryBlock_Returns_Block_Informs_Profiler_When_Read() { // arrange using (var wait = new AutoResetEvent(false)) { using (var mcb = new MemoryManager.ManagedMemoryBlock("Local", "XYZ", 100, 0, Enumerable.Empty <string>())) { // act byte[] data = null; mcb.StreamAccessorResults.Seek(0, SeekOrigin.Begin); mcb.StreamAccessorResults.Write(BitConverter.GetBytes(24), 0, 4); // count + 24 entries == 100 bytes ThreadPool.QueueUserWorkItem(state => { data = Instance.HandleMemoryBlock(mcb); wait.Set(); }); wait.WaitOne(); // assert Assert.IsTrue(mcb.ResultsHaveBeenReceived.WaitOne(new TimeSpan(0, 0, 0, 4)), "Profiler wasn't signalled"); Assert.AreEqual(100, data.Count()); } } }
public void Manager_Sets_Service_ACLs_On_Events() { // arrange var networkServiceSid = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null); var networkServiceAccount = networkServiceSid.Translate(typeof(NTAccount)); var servicePrincipal = new[] { networkServiceAccount.ToString() }; var self = WindowsIdentity.GetCurrent().User; // act using (var mcb = new MemoryManager.ManagedCommunicationBlock("Local", _key, 100, 1, servicePrincipal)) using (var mmb = new MemoryManager.ManagedMemoryBlock("Local", _key, 100, 1, servicePrincipal)) { var phrRules = mmb.ProfilerHasResults.GetAccessControl().GetAccessRules(true, false, typeof(SecurityIdentifier)); var rhbrRules = mmb.ResultsHaveBeenReceived.GetAccessControl().GetAccessRules(true, false, typeof(SecurityIdentifier)); var priRules = mcb.ProfilerRequestsInformation.GetAccessControl().GetAccessRules(true, false, typeof(SecurityIdentifier)); var irfpRules = mcb.InformationReadyForProfiler.GetAccessControl().GetAccessRules(true, false, typeof(SecurityIdentifier)); var irbpRules = mcb.InformationReadByProfiler.GetAccessControl().GetAccessRules(true, false, typeof(SecurityIdentifier)); var rules = new[] { phrRules, rhbrRules, priRules, irfpRules, irbpRules }; // assert foreach (var ruleset in rules) { Assert.That(ruleset.Count, Is.EqualTo(2)); Assert.That(ruleset.Cast <AccessRule>().Any(r => r.IdentityReference == networkServiceSid)); Assert.That(ruleset.Cast <AccessRule>() .Where(r => r.IdentityReference == networkServiceSid) .Any(r => r.AccessControlType == AccessControlType.Allow)); Assert.That(ruleset.Cast <AccessRule>().Any(r => r.IdentityReference == self)); Assert.That(ruleset.Cast <AccessRule>() .Where(r => r.IdentityReference == self) .Any(r => r.AccessControlType == AccessControlType.Allow)); } } }
public void Manager_Handles_Profiler_StandardMessageEvent() { // arrange EventWaitHandle standardMessageReady = null; EventWaitHandle offloadComplete = new AutoResetEvent(false); IManagedCommunicationBlock mcb = new MemoryManager.ManagedCommunicationBlock("Local", _key, 100, -5); IManagedMemoryBlock mmb = new MemoryManager.ManagedMemoryBlock("Local", _key, 100, -5); Container.GetMock <ICommunicationManager>() .Setup(x => x.HandleCommunicationBlock(It.IsAny <IManagedCommunicationBlock>(), It.IsAny <Action <IManagedCommunicationBlock, IManagedMemoryBlock> >())) .Callback <IManagedCommunicationBlock, Action <IManagedCommunicationBlock, IManagedMemoryBlock> >((_, offload) => { if (standardMessageReady != null) { standardMessageReady.Reset(); } offload(mcb, mmb); offloadComplete.Set(); }); // act var dict = new StringDictionary(); RunProcess(dict, standardMessageDataReady => { standardMessageReady = standardMessageDataReady; }, () => { offloadComplete.WaitOne(); mmb.ProfilerHasResults.Set(); mmb.ProfilerHasResults.Reset(); }); // assert Container.GetMock <ICommunicationManager>() .Verify(x => x.HandleMemoryBlock(It.IsAny <IManagedMemoryBlock>()), Times.Once()); }