예제 #1
0
        public string ToText()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Header: " + ValidHeader.ToString());
            builder.AppendLine("Compile: " + CompileMessage);
            builder.AppendLine("Style: " + StyleMessage);
            builder.AppendLine("Score: " + (Grade * 10).ToString() + "%");

            return(builder.ToString());
        }
예제 #2
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));
            });
        }
예제 #3
0
        public void ValidHeaderTest(ValidHeader inputType, Method method)
        {
            var handler = new ConfigurationServiceManager("X-IDENTITY", ServiceContentMapping[inputType]);

            PrAssert.That(Response(handler, method), PrIs.SuccessfulResponse());
        }