public void Crypto_Bad_Keys(string compress) { var expected = Enumerable.Range(0, 10).Select(_ => new string (' ', 15)).ToArray(); var ms = new MemoryStream(); var meta = VolumeMetadataBuilder.Make("String archive", StringArchiveAppender.CONTENT_TYPE_STRING) .SetVersion(1, 0) .SetDescription("Testing string messages") .SetChannel(Atom.Encode("dvop")) .SetCompressionScheme(compress) .SetEncryptionScheme("aes1"); using (var volume = new DefaultVolume(CryptoMan, meta, ms)) using (var appender = new StringArchiveAppender(volume, NOPApplication.Instance.TimeSource, NOPApplication.Instance.AppId, "dima@zhaba")) { for (var i = 0; i < expected.Length; i++) { appender.Append(expected[i]); } } using (var app = new AzosApplication(null, APP_BAD_CRYPTO_CONF.AsLaconicConfig())) { using (var volume = new DefaultVolume(app.SecurityManager.Cryptography, ms))//different key set { var page = new Page(0); volume.ReadPage(0, page);//throws } } }
public void Corrupt_Volume_Read(string compress, int pgsz, int cnt) { var ms = new MemoryStream(); var meta = VolumeMetadataBuilder.Make("String archive", StringArchiveAppender.CONTENT_TYPE_STRING) .SetVersion(1, 0) .SetDescription("Testing string messages") .SetChannel(Atom.Encode("dvop")) .SetCompressionScheme(compress); var volume = new DefaultVolume(NOPApplication.Instance.SecurityManager.Cryptography, meta, ms) { PageSizeBytes = pgsz }; using (var appender = new StringArchiveAppender(volume, NOPApplication.Instance.TimeSource, new Atom(65), "*****@*****.**")) { for (var i = 0; i < cnt; i++) { appender.Append("string-data--------------------------------------------------------" + i.ToString()); } } "Volume size is {0:n0} bytes".SeeArgs(ms.Length); var reader = new StringArchiveReader(volume); var allCount = reader.All.Count(); Aver.AreEqual(cnt, allCount); reader.All.ForEach((s, i) => Aver.IsTrue(s.EndsWith("---" + i.ToString()))); var pageCount = reader.GetPagesStartingAt(0).Count(); Aver.IsTrue(pageCount > 0); "Before corruption: there are {0:n0} total records in {1:n0} pages".SeeArgs(allCount, pageCount); var midPoint = ms.Length / 2; ms.Position = midPoint; for (var j = 0; j < pgsz * 2; j++) { ms.WriteByte(0x00); //corruption } "-------------- corrupted {0:n0} bytes of {1:n0} total at {2:n0} position ----------- ".SeeArgs(pgsz * 2, ms.Length, midPoint); var allCount2 = reader.GetEntriesStartingAt(new Bookmark(), skipCorruptPages: true).Count(); Aver.IsTrue(allCount > allCount2); var pageCount2 = reader.GetPagesStartingAt(0, skipCorruptPages: true).Count(); Aver.IsTrue(pageCount > pageCount2); "After corruption: there are {0:n0} total records in {1:n0} pages".SeeArgs(allCount2, pageCount2); volume.Dispose(); }
public void Write_Read_Compare_PageSplit(int pc, int vsz, int pgsize, string compress, string encrypt, int count, int sz) { var expected = Enumerable.Range(0, count).Select(_ => new string(' ', sz)).ToArray(); var ms = new MemoryStream(); var meta = VolumeMetadataBuilder.Make("String archive", StringArchiveAppender.CONTENT_TYPE_STRING) .SetVersion(1, 0) .SetDescription("Testing string messages") .SetChannel(Atom.Encode("dvop")) .SetCompressionScheme(compress) .SetEncryptionScheme(encrypt); var volume = new DefaultVolume(CryptoMan, meta, ms); volume.PageSizeBytes = pgsize; using (var appender = new StringArchiveAppender(volume, NOPApplication.Instance.TimeSource, NOPApplication.Instance.AppId, "dima@zhaba")) { for (var i = 0; i < count; i++) { appender.Append(expected[i]); } } "Volume data stream is {0:n0} bytes".SeeArgs(ms.Length); Aver.IsTrue(ms.Length < vsz); // ms.GetBuffer().ToHexDump().See(); var reader = new StringArchiveReader(volume); // reader.Pages(0).Select(p => (p.State, p.Entries.Count())).See("PAGES/Entries: "); var pageCount = reader.GetPagesStartingAt(0).Count(); "Volume page count is: {0}".SeeArgs(pageCount); Aver.AreEqual(pc, pageCount); var got = reader.All.ToArray(); Aver.AreEqual(expected.Length, got.Length); for (int i = 0; i < count; i++) { Aver.AreEqual(expected[i], got[i]); } volume.Dispose(); }
public void Write_Read_Compare_Strings(bool ascii, int pgsize, string compress, int count, int min, int max) { var expected = ascii ? FakeLogMessage.BuildRandomASCIIStringArr(count, min, max) : FakeLogMessage.BuildRandomUnicodeStringArr(count, min, max); var ms = new MemoryStream(); var meta = VolumeMetadataBuilder.Make("String archive", StringArchiveAppender.CONTENT_TYPE_STRING) .SetVersion(1, 0) .SetDescription("Testing string messages") .SetChannel(Atom.Encode("dvop")); if (compress.IsNotNullOrWhiteSpace()) { meta.SetCompressionScheme(compress); } var volume = new DefaultVolume(NOPApplication.Instance.SecurityManager.Cryptography, meta, ms); volume.PageSizeBytes = pgsize; using (var appender = new StringArchiveAppender(volume, NOPApplication.Instance.TimeSource, NOPApplication.Instance.AppId, "dima@zhaba")) { for (var i = 0; i < count; i++) { appender.Append(expected[i]); } } "Volume data stream is {0:n0} bytes".SeeArgs(ms.Length); var reader = new StringArchiveReader(volume); var got = reader.GetEntriesStartingAt(new Bookmark()).ToArray(); Aver.AreEqual(expected.Length, got.Length); for (int i = 0; i < count; i++) { Aver.AreEqual(expected[i], got[i]); } volume.Dispose(); }
public void PageInfo_Walk(int count, int psz, bool remount, int strvar) { string makestr(int i) { return(strvar > 0 ? (new string(' ', i % strvar) + "text-string-" + i.ToString()) : ("text-string-" + i.ToString())); } var ms = new MemoryStream(); var meta = VolumeMetadataBuilder.Make("String archive", StringArchiveAppender.CONTENT_TYPE_STRING) .SetVersion(1, 0) .SetDescription("Testing string messages") .SetChannel(Atom.Encode("dvop")); var volume = new DefaultVolume(CryptoMan, meta, ms, ownsStream: false); volume.PageSizeBytes = psz; using (var appender = new StringArchiveAppender(volume, NOPApplication.Instance.TimeSource, NOPApplication.Instance.AppId, "dima@zhaba")) { for (var i = 0; i < count; i++) { appender.Append(makestr(i)); } } if (remount) { volume.Dispose(); volume = new DefaultVolume(CryptoMan, ms, ownsStream: false); } var pis = volume.ReadPageInfos(0); "Page infos: {0}".SeeArgs(pis.Count()); foreach (var pi in pis) { var one = volume.ReadPageInfo(pi.PageId); Aver.AreEqual(pi, one); } var total = 0; var reader = new StringArchiveReader(volume); foreach (var pi in pis) { var page = reader.GetOnePageAt(pi.PageId, true); foreach (var entry in page.Entries) { if (entry.State == Entry.Status.Valid) { Aver.AreEqual(makestr(total), reader.Materialize(entry)); total++; } } } Aver.AreEqual(count, total); volume.Dispose(); }