Ejemplo n.º 1
0
        public void SortedFileSearcher_FileInput()
        {
            string hashesFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(hashesFile, PwnedPasswordHashesOrderedByHash);
                using (var searcher = new SortedFileSearcher(hashesFile))
                {
                    // Find first
                    Assert.IsTrue(searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75"));

                    // Find last
                    Assert.IsTrue(searcher.FindString("1AE189A6FFF7DB51548F12F063491E36"));

                    // Find middle
                    Assert.IsTrue(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2"));

                    // Find non-existing
                    Assert.IsFalse(searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2"));
                }
            }
            finally
            {
                File.Delete(hashesFile);
            }
        }
Ejemplo n.º 2
0
 public void SortedFileSearcher_StreamInput_SingleLine()
 {
     byte[] binaryInput = Encoding.ASCII.GetBytes("Gamma");
     using (var stream = new MemoryStream(binaryInput))
     {
         using (var searcher = new SortedFileSearcher(stream))
         {
             Assert.IsTrue(searcher.FindString("Gamma"));
             Assert.IsFalse(searcher.FindString("Alpha"));
             Assert.IsFalse(searcher.FindString("Omega"));
         }
     }
 }
Ejemplo n.º 3
0
        public void SortedFileSearcher_StreamInput_UnsortedHashes()
        {
            // We just need to test that this does not end with an endless loop

            byte[] binaryInput = Encoding.ASCII.GetBytes(PwnedPasswordHashesOrderedByCount);
            using (var stream = new MemoryStream(binaryInput))
            {
                using (var searcher = new SortedFileSearcher(stream))
                {
                    searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75");
                    searcher.FindString("69CBE3ACBC48A3A289E8CDB000C2B7A8");
                    searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2");
                    searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2");
                }
            }
        }
Ejemplo n.º 4
0
        public void SortedFileSearcher_StreamInput_SortedHashes()
        {
            byte[] binaryInput = Encoding.ASCII.GetBytes(PwnedPasswordHashesOrderedByHash);
            using (var stream = new MemoryStream(binaryInput))
            {
                var searcher = new SortedFileSearcher(stream);

                // Find first
                Assert.IsTrue(searcher.FindString("1AE188AB6DF35626E09C77F2880CAD75"));

                // Find last
                Assert.IsTrue(searcher.FindString("1AE189A6FFF7DB51548F12F063491E36"));

                // Find middle
                Assert.IsTrue(searcher.FindString("1AE188FF3AF08946C275C9A7E2B894F2"));

                // Find non-existing
                Assert.IsFalse(searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2"));
            }
        }
Ejemplo n.º 5
0
 public void SortedFileSearcher_StreamInput_Empty()
 {
     byte[] input = new byte[0];
     using (var stream = new MemoryStream(input))
     {
         using (var searcher = new SortedFileSearcher(stream))
         {
             bool result = searcher.FindString("F7EB9C06FAFAA23C4BCF22BA6781C1E2");
             Assert.IsFalse(result);
         }
     }
 }
Ejemplo n.º 6
0
        public void SortedFileSearcher_StreamInput_Words()
        {
            byte[] binaryInput = Encoding.ASCII.GetBytes(PhoneticAlphabet);
            using (var stream = new MemoryStream(binaryInput))
            {
                var searcher = new SortedFileSearcher(stream);

                // Check that we can find all the words that are contained in the input
                string[] words = PhoneticAlphabet.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (string word in words)
                {
                    Assert.IsTrue(searcher.FindString(word));
                }

                // Test some non-existing words
                Assert.IsFalse(searcher.FindString("AAAA"));
                Assert.IsFalse(searcher.FindString("ZZZZ"));
                string[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Split();
                foreach (string letter in letters)
                {
                    Assert.IsFalse(searcher.FindString(letter));
                }
            }
        }