public void RequestIsValid()
        {
            var request = new ValidationRequest
            {
                HttpRequest = new HttpRequestMessage
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                    Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                    Content = new StringContent(GenericSuccessMessage)
                },
                RequestTime = DateTime.UtcNow
            };

            var speechlet = new EmptySpeechlet();
            var response = speechlet.OnRequestValidation(request);

            //Need to validate no errors except for InvalidSignature since SSL Cert not supplied <see cref="SignatureVerifierTests">
            Assert.True(
                    (response.ValidationResult & SpeechletRequestValidationResult.NoCertHeader) != SpeechletRequestValidationResult.NoCertHeader
                    &&
                    (response.ValidationResult & SpeechletRequestValidationResult.NoSignatureHeader) != SpeechletRequestValidationResult.NoSignatureHeader
                    &&
                    (response.ValidationResult & SpeechletRequestValidationResult.InvalidJson) != SpeechletRequestValidationResult.InvalidJson
                    &&
                    (response.ValidationResult & SpeechletRequestValidationResult.InvalidSpeechlet) != SpeechletRequestValidationResult.InvalidSpeechlet
                    &&
                    (response.ValidationResult & SpeechletRequestValidationResult.InvalidTimestamp) != SpeechletRequestValidationResult.InvalidTimestamp
                    &&
                    (response.ValidationResult & SpeechletRequestValidationResult.Error) != SpeechletRequestValidationResult.Error
                    );
        }
        public void TimestampRequestIsNotWithinTolerance()
        {
            var request = new ValidationRequest
            {
                HttpRequest = new HttpRequestMessage
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                    Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                    Content = new StringContent(OutdatedMessage)
                },
                RequestTime = DateTime.UtcNow
            };

            var speechlet = new EmptySpeechlet();
            var response = speechlet.OnRequestValidation(request);

            Assert.True((response.ValidationResult & SpeechletRequestValidationResult.InvalidTimestamp) ==
                            SpeechletRequestValidationResult.InvalidTimestamp);
        }
        public void RequestIsEmptyAlexaMessage()
        {
            var request = new ValidationRequest
            {
                HttpRequest = new HttpRequestMessage
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                    Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                    Content = new StringContent(string.Empty)
                }
            };

            var alexaBytes = AsyncHelpers.RunSync(() => request.HttpRequest.Content.ReadAsByteArrayAsync());

            var speechlet = new EmptySpeechlet();
            var response = new ValidationResponse
            {
                ValidationResult = SpeechletRequestValidationResult.OK
            };

            speechlet.GetRequest(alexaBytes, ref response);

            Assert.True((response.ValidationResult & SpeechletRequestValidationResult.InvalidSpeechlet) == SpeechletRequestValidationResult.InvalidSpeechlet);
        }
        public void HeaderContainsBlankSignatureFails()
        {
            var request = new ValidationRequest
            {
                HttpRequest = new HttpRequestMessage
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                    Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "" }
                        },
                    Content = new StringContent(GenericSuccessMessage)
                }
            };

            var speechlet = new EmptySpeechlet();
            var response = speechlet.OnRequestValidation(request);

            Assert.True((response.ValidationResult & SpeechletRequestValidationResult.NoSignatureHeader) ==
                            SpeechletRequestValidationResult.NoSignatureHeader);
        }