public void DefaultBehaviour() { var attempt = new ClientRequestingConnectionArgs<byte,byte> (null); Assert.IsFalse (attempt.Request.ShouldDeny); Assert.IsFalse (attempt.Request.ShouldAllow); Assert.IsTrue (attempt.Request.StillPending); }
public void NoHelloMessage() { var responseStream = new MemoryStream (); var stream = new TestStream (new MemoryStream (), responseStream); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock<IClient<byte,byte>> (); mockByteClient.Setup (x => x.Stream).Returns (stream); var byteClient = mockByteClient.Object; var server = new StreamServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse (eventArgs.Request.ShouldAllow); Assert.IsTrue (eventArgs.Request.ShouldDeny); Assert.AreEqual (0, responseStream.Length); }
public void AllowAndDeny() { var attempt = new ClientRequestingConnectionArgs<byte,byte> (null); attempt.Request.Allow (); attempt.Request.Deny (); Assert.IsTrue (attempt.Request.ShouldDeny); Assert.IsFalse (attempt.Request.ShouldAllow); Assert.IsFalse (attempt.Request.StillPending); }
public void OnClientRequestingConnection(object sender, ClientRequestingConnectionArgs args) { // Not open, so open the dialog if (!Visible) { Logger.WriteLine ("Asking player to allow/deny connection attempt..."); this.args = args; Open (); return; } // Already open for a different request, so ignore if (Visible && this.args.Client != args.Client) return; // Open, and we have a decision (must be the correct client at this point), to close the dialog if (Visible && !this.args.Request.StillPending) { if (this.args.Request.ShouldAllow) args.Request.Allow (); else args.Request.Deny (); Close (); } }
public void InvalidHelloMessageIdentifier() { helloMessage [15] = 0x00; var stream = new TestStream (new MemoryStream (helloMessage)); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock<IClient<byte,byte>> (); mockByteClient.Setup (x => x.Stream).Returns (stream); var byteClient = mockByteClient.Object; var server = new RPCServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse (eventArgs.Request.ShouldAllow); Assert.IsTrue (eventArgs.Request.ShouldDeny); }
public void ValidHelloMessage() { var responseStream = new MemoryStream (); var stream = new TestStream (new MemoryStream (helloMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var byteClient = new TestClient (stream); var server = new StreamServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue (eventArgs.Request.ShouldAllow); Assert.IsFalse (eventArgs.Request.ShouldDeny); server.Update (); Assert.AreEqual (1, server.Clients.Count ()); Assert.AreEqual (clientGuid, server.Clients.First ().Guid); byte[] bytes = responseStream.ToArray (); byte[] expectedBytes = { 0x4F, 0x4B }; Assert.IsTrue (expectedBytes.SequenceEqual (bytes)); }
public void ValidHelloMessageWithNoName() { for (int i = 12; i < helloMessage.Length; i++) { helloMessage [i] = 0x00; } var responseStream = new MemoryStream (); var stream = new TestStream (new MemoryStream (helloMessage), responseStream); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var byteClient = new TestClient (stream); var server = new RPCServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue (eventArgs.Request.ShouldAllow); Assert.IsFalse (eventArgs.Request.ShouldDeny); server.Update (); Assert.AreEqual (1, server.Clients.Count ()); Assert.AreEqual ("", server.Clients.First ().Name); byte[] bytes = responseStream.ToArray (); byte[] responseBytes = byteClient.Guid.ToByteArray (); Assert.IsTrue (responseBytes.SequenceEqual (bytes)); }
protected override void Closed() { args = null; }
public void ValidHelloMessage() { var stream = new TestStream (new MemoryStream (helloMessage)); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var byteClient = new TestClient (stream); var server = new RPCServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsTrue (eventArgs.Request.ShouldAllow); Assert.IsFalse (eventArgs.Request.ShouldDeny); server.Update (); Assert.AreEqual (1, server.Clients.Count ()); Assert.AreEqual ("Jebediah Kerman!!!", server.Clients.First ().Name); }
public void ShortHelloMessageIdentifier() { var shortHelloMessage = new byte[8 + 31]; byte[] header = { 0x48, 0x45, 0x4C, 0x4C, 0x4F, 0xBA, 0xDA, 0x55 }; Array.Copy (header, shortHelloMessage, header.Length); string identifier = "Jebediah Kerman!!!"; var encoder = new UTF8Encoding (false, true); byte[] identifierBytes = encoder.GetBytes (identifier); Array.Copy (identifierBytes, 0, shortHelloMessage, header.Length, identifierBytes.Length); var stream = new TestStream (new MemoryStream (shortHelloMessage)); // Create mock byte server and client var mockByteServer = new Mock<IServer<byte,byte>> (); var byteServer = mockByteServer.Object; var mockByteClient = new Mock<IClient<byte,byte>> (); mockByteClient.Setup (x => x.Stream).Returns (stream); var byteClient = mockByteClient.Object; var server = new RPCServer (byteServer); server.OnClientRequestingConnection += (sender, e) => e.Request.Allow (); server.Start (); // Fire a client connection event var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient); mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs); Assert.IsFalse (eventArgs.Request.ShouldAllow); Assert.IsTrue (eventArgs.Request.ShouldDeny); }