public void ModificationUpdateTimestampTest()
        {
            // Arrange
            Note note = new Note("Some topic here", "Some text here, yes.");

            // Act
            var modificationTime1 = note.modificationTime;

            System.Threading.Thread.Sleep(1100);
            note.UpdateNote(note.GetNoteTitle(), "Some text here, yes. part 2");
            var modificationTime2 = note.modificationTime;

            // Assert
            Assert.AreNotEqual(modificationTime1, modificationTime2);
        }
        public void ChecksumChangesTest()
        {
            // Arrange
            DateTimeOffset dto   = DateTimeOffset.UtcNow;
            Note           note1 = new Note();
            Note           note2 = new Note("Some topic here", "Some text here, yes.", dto);
            Note           note3 = new Note("Some topic here", "Some text here, yes.", dto);

            // Act
            string checksum1 = note1.GetChecksumAsHex();
            string checksum2 = note2.GetChecksumAsHex();
            string checksum3 = note3.GetChecksumAsHex();

            string newContent = note3.GetNoteText() + "A";

            note3.UpdateNote(note3.GetNoteTitle(), newContent);
            string checksum4 = note3.GetChecksumAsHex();

            // Assert
            Assert.AreNotEqual(checksum1, checksum2);
            Assert.AreEqual(checksum3, checksum2);
            Assert.AreNotEqual(checksum3, checksum4);
        }
Exemple #3
0
        public void ReplaceNoteSecretTest()
        {
            // Arrange
            string kdfeIdentifier           = "somet!%&hinghere";
            string password                 = "******";
            KeyDerivationFunctionEntry kdfe = KeyDerivationFunctionEntry.CreateHMACSHA256KeyDerivationFunctionEntry(kdfeIdentifier);
            CommonSecretsContainer     csc  = new CommonSecretsContainer(kdfe);

            Note add1 = ContentGenerator.GenerateRandomNote();
            Note add2 = ContentGenerator.GenerateRandomNote();

            Note replace1 = ContentGenerator.GenerateRandomNote();
            Note replace2 = ContentGenerator.GenerateRandomNote();

            // Act
            var addResultSuccess1 = csc.AddNoteSecret(password, add1, kdfeIdentifier);
            var addResultSuccess2 = csc.AddNoteSecret(kdfe.GeneratePasswordBytes(password), add2, kdfeIdentifier);

            var replaceResultSuccess1 = csc.ReplaceNoteSecret(0, password, replace1, kdfeIdentifier);
            var replaceResultSuccess2 = csc.ReplaceNoteSecret(1, kdfe.GeneratePasswordBytes(password), replace2, kdfeIdentifier);

            var replaceResultFailure1 = csc.ReplaceNoteSecret(0, password, null, kdfeIdentifier);
            var replaceResultFailure2 = csc.ReplaceNoteSecret(0, password, ContentGenerator.GenerateRandomNote(), "not existing");
            var replaceResultFailure3 = csc.ReplaceNoteSecret(0, "", ContentGenerator.GenerateRandomNote(), kdfeIdentifier);
            var replaceResultFailure4 = csc.ReplaceNoteSecret(-1, password, replace1, kdfeIdentifier);
            var replaceResultFailure5 = csc.ReplaceNoteSecret(2, password, replace1, kdfeIdentifier);

            // Assert
            Assert.AreNotEqual(add1.GetNoteTitle(), replace1.GetNoteTitle(), "Make sure that random content do not match!");
            Assert.AreNotEqual(add2.GetNoteTitle(), replace2.GetNoteTitle(), "Make sure that random content do not match!");

            Assert.AreEqual(replace1.GetNoteTitle(), csc.noteSecrets[0].GetNoteTitle(kdfe.GeneratePasswordBytes(password)));
            Assert.AreEqual(replace2.GetNoteTitle(), csc.noteSecrets[1].GetNoteTitle(kdfe.GeneratePasswordBytes(password)));

            Assert.IsTrue(addResultSuccess1.success);
            Assert.AreEqual("", addResultSuccess1.possibleError);

            Assert.IsTrue(addResultSuccess2.success);
            Assert.AreEqual("", addResultSuccess2.possibleError);

            Assert.IsTrue(replaceResultSuccess1.success);
            Assert.AreEqual("", replaceResultSuccess1.possibleError);

            Assert.IsTrue(replaceResultSuccess2.success);
            Assert.AreEqual("", replaceResultSuccess2.possibleError);

            Assert.IsFalse(replaceResultFailure1.success);
            Assert.IsFalse(string.IsNullOrEmpty(replaceResultFailure1.possibleError));

            Assert.IsFalse(replaceResultFailure2.success);
            Assert.IsFalse(string.IsNullOrEmpty(replaceResultFailure2.possibleError));

            Assert.IsFalse(replaceResultFailure3.success);
            Assert.IsFalse(string.IsNullOrEmpty(replaceResultFailure3.possibleError));

            Assert.IsFalse(replaceResultFailure4.success);
            Assert.IsFalse(string.IsNullOrEmpty(replaceResultFailure4.possibleError));

            Assert.IsFalse(replaceResultFailure5.success);
            Assert.IsFalse(string.IsNullOrEmpty(replaceResultFailure5.possibleError));

            Assert.AreEqual(2, csc.noteSecrets.Count);
        }