Example #1
0
        public bool Run()
        {
            // password: Hello (in $1$8b1a9953c4611296a827abf8c47804d7)
            // salt: World
            var authInfo = new UserAuthInfo
            {
                PasswordHash = "fd6224f938c9c333dfbeb2336c6640e7",
                PasswordSalt = "f5a7924e621e84c9280a9a27e1bcb7f6"
            };

            m_Log.Info("Testing predefined password data");
            try
            {
                m_Log.Info("- Old way");
                authInfo.CheckPassword("Hello");
                m_Log.Info("- Current way");
                authInfo.CheckPassword("$1$8b1a9953c4611296a827abf8c47804d7");
            }
            catch
            {
                return(false);
            }

            m_Log.Info("Testing predefined password data - wrong");
            try
            {
                m_Log.Info("- Old way");
                authInfo.CheckPassword("Hello2");
                return(false);
            }
            catch
            {
                /* only successful on error */
            }
            try
            {
                m_Log.Info("- Current way");
                authInfo.CheckPassword("$1$b83099b8ce596f31f2f60c8fd4d72826");
                return(false);
            }
            catch
            {
                /* only successful on error */
            }

            m_Log.Info("Setting password through property");
            authInfo.Password = "******";
            try
            {
                m_Log.Info("- Old way");
                authInfo.CheckPassword("Hello");
                m_Log.Info("- Current way");
                authInfo.CheckPassword("$1$8b1a9953c4611296a827abf8c47804d7");
            }
            catch
            {
                return(false);
            }

            m_Log.Info("Testing property set password data - wrong");
            try
            {
                m_Log.Info("- Old way");
                authInfo.CheckPassword("Hello2");
                return(false);
            }
            catch
            {
                /* only successful on error */
            }
            try
            {
                m_Log.Info("- Current way");
                authInfo.CheckPassword("$1$b83099b8ce596f31f2f60c8fd4d72826");
                return(false);
            }
            catch
            {
                /* only successful on error */
            }

            return(true);
        }
        public bool Run()
        {
            m_Log.Info("Testing that we get no data");
            UserAuthInfo authInfo;
            UserAuthInfo checkAuthInfo;

            try
            {
                authInfo = m_AuthInfoServiceBackend[m_UserID];
                return(false);
            }
            catch (KeyNotFoundException)
            {
                /* this happens here */
            }

            m_Log.Info("Testing predefined Auth Info");
            authInfo = new UserAuthInfo()
            {
                ID           = m_UserID,
                PasswordHash = "fd6224f938c9c333dfbeb2336c6640e7",
                PasswordSalt = "f5a7924e621e84c9280a9a27e1bcb7f6"
            };

            m_Log.InfoFormat("Hash={0} Salt={1}", authInfo.PasswordHash, authInfo.PasswordSalt);

            m_AuthInfoServiceBackend.Store(authInfo);

            m_Log.Info("Retrieving auth info");
            try
            {
                checkAuthInfo = m_AuthInfoServiceBackend[m_UserID];
            }
            catch
            {
                return(false);
            }

            m_Log.InfoFormat("Hash={0} Salt={1}", checkAuthInfo.PasswordHash, checkAuthInfo.PasswordSalt);

            if (checkAuthInfo.ID != authInfo.ID ||
                checkAuthInfo.PasswordHash != authInfo.PasswordHash ||
                checkAuthInfo.PasswordSalt != authInfo.PasswordSalt)
            {
                if (checkAuthInfo.ID != authInfo.ID)
                {
                    m_Log.Info("ID not equal");
                }
                if (checkAuthInfo.PasswordHash != authInfo.PasswordHash)
                {
                    m_Log.Info("PasswordHash not equal");
                }
                if (checkAuthInfo.PasswordSalt != authInfo.PasswordSalt)
                {
                    m_Log.Info("PasswordSalt not equal");
                }
                return(false);
            }

            m_Log.Info("Testing password check of original data");
            try
            {
                authInfo.CheckPassword("Hello");
            }
            catch
            {
                m_Log.InfoFormat("Hash={0} Salt={1}", authInfo.PasswordHash, authInfo.PasswordSalt);
                return(false);
            }

            m_Log.Info("Testing password check of copy data");
            try
            {
                checkAuthInfo.CheckPassword("Hello");
            }
            catch
            {
                m_Log.InfoFormat("Hash={0} Salt={1}", checkAuthInfo.PasswordHash, checkAuthInfo.PasswordSalt);
                return(false);
            }

            UUID sessionID = UUID.Random;

            m_Log.Info("Testing authenticate with old way");
            try
            {
                m_AuthInfoService.Authenticate(sessionID, m_UserID, "Hello", 30);
            }
            catch
            {
                return(false);
            }
            m_AuthInfoService.ReleaseTokenBySession(m_UserID, sessionID);

            m_Log.Info("Testing authenticate with new way");
            try
            {
                m_AuthInfoService.Authenticate(sessionID, m_UserID, "$1$8b1a9953c4611296a827abf8c47804d7", 30);
            }
            catch (Exception e)
            {
                m_Log.Debug("Exception", e);
                return(false);
            }

            return(true);
        }