QBackupTests/Tests.cs
/// <summary>
/// Test that backup won't be able to extract if the password isn't the same as the one that was used to compress.
/// </summary>
Test that backup won't be able to extract if the password isn't the same as the one that was used to compress.
Test that backup won ' t be able to extract if the password isn ' t the same as the one that was used to compress .
[Test]
        public static void TestCheckPassword()
        {
            var log = new LogLines();
            var t = new TestDir(InputDir);
            t.Create();
            var src = AnalyzedBackup.Create(t.Dirs[0], true, log);
            var archived_dir = src.Compress(OutputDir, Password, 256, log);
            var archived = ArchivedBackup.CreateFromPath(archived_dir, Password, log);
            QAssert.AreEqual(src, archived);
            var wrong_password = Password + " wrong password";
            try
            {
                ArchivedBackup.CreateFromPath(archived_dir, wrong_password, log);
            }
            catch (Exception e)
            {
                Assert.True(e.Message.Contains("password"));
            }
            var extracted_dir = archived.GetDestinationForExtraction(ExtractedDir);
            try
            {
                archived.Extract(ExtractedDir, wrong_password, log);
            }
            catch (Exception e)
            {
                Assert.True(e.Message.Contains("Invalid password for AES"));
            }
            finally
            {
                Directory.Delete(extracted_dir.Path, true);
            }
            Directory.Delete(src.Root.Path, true);
            Directory.Delete(archived_dir.Path, true);
        }
[ Test ] public static void TestCheckPassword ( ) { var log = new LogLines ( ) ; var t = new TestDir ( InputDir ) ; t . Create ( ) ; var src = AnalyzedBackup . Create ( t . Dirs [ 0 ] , true , log ) ; var archived_dir = src . Compress ( OutputDir , Password , 256 , log ) ; var archived = ArchivedBackup . CreateFromPath ( archived_dir , Password , log ) ; QAssert . AreEqual ( src , archived ) ; var wrong_password = Password + " " ; try { ArchivedBackup . CreateFromPath ( archived_dir , wrong_password , log ) ; } catch ( Exception e ) { Assert . True ( e . Message . Contains ( " " ) ) ; } var extracted_dir = archived . GetDestinationForExtraction ( ExtractedDir ) ; try { archived . Extract ( ExtractedDir , wrong_password , log ) ; } catch ( Exception e ) { Assert . True ( e . Message . Contains ( " " ) ) ; } finally { Directory . Delete ( extracted_dir . Path , true ) ; } Directory . Delete ( src . Root . Path , true ) ; Directory . Delete ( archived_dir . Path , true ) ; }
Test that backup won't be able to extract if the password isn't the same as the one that was used to compress.
Test that backup won ' t be able to extract if the password isn ' t the same as the one that was used to compress .