Ejemplo n.º 1
0
        /// <summary>Test stub for LogIn(String, String, Byte[])</summary>

        public void LogInTest(
            TestClient client,
            string user,
            string pass,
            byte[] key
            )
        {
            client.LogInAndConnect(user, pass, key);
            // If username not recognised, expect to be disconnected
            if (string.IsNullOrEmpty(user) || !Utility_Methods.CheckStringValid("combined", user) || !LogInManager.users.ContainsKey(user))
            {
                Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString());
                return;
            }
            // If password is incorrect, expect an error
            Tuple <byte[], byte[]> hashNsalt = LogInManager.users[user];

            byte[] hash;
            if (pass == null)
            {
                hash = null;
            }
            else
            {
                hash = LogInManager.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass), hashNsalt.Item2);
            }
            if (hash == null || !hashNsalt.Item1.SequenceEqual(hash) || key == null || key.Length < 5)
            {
                Assert.AreEqual("Disconnected", client.net.GetConnectionStatusString());
                Assert.IsFalse(Server.ContainsConnection(user));
            }
            else
            {
                // If the login was successful, expecting a ProtoLogin followed by a ProtoClient back
                Task <ProtoMessage> getReply = client.GetReply();
                getReply.Wait();
                ProtoMessage reply = getReply.Result;
                Assert.AreEqual(reply.GetType(), typeof(ProtoLogIn));
                while (!client.IsConnectedAndLoggedIn())
                {
                    Thread.Sleep(0);
                }
                // If login was successful, the client should be in the list of registered observers
                Assert.IsTrue(Globals_Game.IsObserver(Globals_Server.Clients[user]));
                Assert.IsTrue(Server.ContainsConnection(user));
            }
        }