Exemplo n.º 1
0
        public static void decryption()
        {
            "Decrypting with the correct key returns the original text".Is(() =>
            {
                var ciphertext = ValidHeader.Concat(ValidCiphertext);
                var plaintext  = "TEST";

                var output = Decrypter.Decypt(ciphertext, ValidPassword);

                Assert.True(output == plaintext);
            });

            "Decryption fails when the header does not have 3 fields".Is(() =>
            {
                var invalidHeader = new[]
                {
                    "$ANSIBLE_VAULT;AES256",
                };

                var ciphertext = invalidHeader.Concat(ValidCiphertext);

                Assert.Throws(() => Decrypter.Decypt(ciphertext, ValidPassword));
            });

            "Decryption fails when not an ansible vault file".Is(() =>
            {
                var invalidHeader = new[]
                {
                    "$SOME_OTHER_FILE;1.1;AES256",
                };

                var ciphertext = invalidHeader.Concat(ValidCiphertext);

                Assert.Throws(() => Decrypter.Decypt(ciphertext, ValidPassword));
            });

            "Decryption fails when not the correct version".Is(() =>
            {
                var invalidHeader = new[]
                {
                    "$ANSIBLE_VAULT;0.0;AES256",
                };

                var ciphertext = invalidHeader.Concat(ValidCiphertext);

                Assert.Throws(() => Decrypter.Decypt(ciphertext, ValidPassword));
            });

            "Decryption fails when not the correct cipher".Is(() =>
            {
                var invalidHeader = new[]
                {
                    "$ANSIBLE_VAULT;1.1;BOB123",
                };

                var ciphertext = invalidHeader.Concat(ValidCiphertext);

                Assert.Throws(() => Decrypter.Decypt(ciphertext, ValidPassword));
            });

            "Decryption fails when the password is incorrect".Is(() =>
            {
                const string invalidPassword = "******";
                var ciphertext = ValidHeader.Concat(ValidCiphertext);

                Assert.Throws(() => Decrypter.Decypt(ciphertext, invalidPassword));
            });
        }