示例#1
0
        unsafe void TestFail(string username, string password, ALRReason expectedFailReason)
        {
            using (MockClient client = new MockClient(45, TestUserIP))
            {
                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_80_Login packetIn = new MockClient_80_Login(client.Socket, username, password);
                client.Enqueue(packetIn);

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                try
                {
                    Packet80_LoginRequest packetOut = client.ProcessAndCheck(packetIn) as Packet80_LoginRequest;
                }
                catch (VerificationException ex)
                {
                    Assert.Fail(ex.Message);
                }

                Assert.AreEqual(0u, client.SocketDataLength, "Packet should have been removed.");

                MockServer_82_LoginDenied expectedPacketResponse = new MockServer_82_LoginDenied(expectedFailReason);
                string responce = ((MockPacketEngine)Server.PacketEngine).VerifySent(client, expectedPacketResponse.PacketData);
                Assert.IsTrue(string.IsNullOrEmpty(responce), "Failed to verify reject packet: {0}", responce);
            }
        }
示例#2
0
        unsafe public void Test_SocketObject_RemoveFirstPacket()
        {
            MockClient client = new MockClient(42, TestUserIP);

            string testusername1 = "foo";
            string testusername2 = "bar";
            string testpass      = "******";

            Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero after socket creation.");

            MockClient_80_Login packet1 = new MockClient_80_Login(client.Socket, testusername1, testpass);

            client.Enqueue(packet1);

            Assert.AreEqual(packet1.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

            MockClient_80_Login packet2 = new MockClient_80_Login(client.Socket, testusername2, testpass);

            client.Enqueue(packet2);

            Assert.AreEqual(packet1.Length + packet2.Length, client.SocketDataLength, "Socket should contain 2 packet, datalength should equal sum of packet lengths.");

            Server.PacketEngine.SocketObject_RemoveFirstPacket(client.Socket, packet1.Length);

            Assert.AreEqual(packet2.Length, client.SocketDataLength, "Data length should be length of packet2 after packet1 removal.");

            Packet80_LoginRequest packetOut = client.ProcessOnly(packet2) as Packet80_LoginRequest;

            Assert.AreEqual(testusername2, packetOut.Username, "Couldn't verify username for packet2.");

            Server.PacketEngine.SocketObject_RemoveFirstPacket(client.Socket, packet2.Length);

            Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero after both packets removed.");
        }
示例#3
0
        unsafe int TestSuccess(string username)
        {
            using (MockClient client = new MockClient(42, TestUserIP))
            {
                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_80_Login packetIn = new MockClient_80_Login(client.Socket, username, TestUserPass);
                client.Enqueue(packetIn);

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                Packet80_LoginRequest packetOut = null;
                try
                {
                    packetOut = client.ProcessAndCheck(packetIn) as Packet80_LoginRequest;
                }
                catch (VerificationException ex)
                {
                    Assert.Fail(ex.Message);
                }

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should still contain packet, as login should have been accepted.");

                int  accountID;
                bool UsernameIsAccountID = int.TryParse(packetOut.Username, out accountID);

                Assert.IsTrue(UsernameIsAccountID, "Expected username to be an account id.");
                Assert.IsTrue(string.IsNullOrEmpty(packetOut.Password), "Password should be empty.");

                Account account = Accounting.Get(accountID);
                Assert.AreEqual(username, account.Username);

                bool passwordIsCorrect = account.Login(TestUserPass, TestUserIP);
                Assert.IsTrue(passwordIsCorrect, "Password didn't work.");

                return(accountID);
            }
        }