Beispiel #1
0
        public void DeleteEventSourceMappingMarshallTest()
        {
            var operation = service_model.FindOperation("DeleteEventSourceMapping");

            var request    = InstantiateClassGenerator.Execute <DeleteEventSourceMappingRequest>();
            var marshaller = new DeleteEventSourceMappingRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("DeleteEventSourceMapping", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "x-amzn-RequestId", Guid.NewGuid().ToString() },
                    { "x-amz-crc32",      "0"                       }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString());
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = DeleteEventSourceMappingResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as DeleteEventSourceMappingResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
Beispiel #2
0
    static void Main(string[] args)
    {
        // Your Auth Token from twilio.com/console
        const string authToken = "your-secret";

        // Initialize the validator
        var validator = new RequestValidator(authToken);

        // The Twilio request URL
        const string url = "https://mycompany.com/myapp.php?foo=1&bar=2";

        // The X-Twilio-Signature header attached to the request
        const string twilioSignature = "GvWf1cFY/Q7PnoempGyD5oXAezc=";

        var parameters = new Dictionary <string, string>
        {
            { "CallSid", "CA1234567890ABCDE" },
            { "Caller", "+14158675310" },
            { "Digits", "1234" },
            { "From", "+14158675310" },
            { "To", "+18005551212" }
        };

        Console.WriteLine(validator.Validate(url, parameters, twilioSignature));
    }
        public void Validation_should_fail_when_supplying_request_body_with_head_method()
        {
            request = Request.Head(request.Url).WithContent(new Content(new byte[16]));

            RequestValidator.IsValid(request).Should().BeFalse();

            Console.Out.WriteLine(RequestValidator.Validate(request).Single());
        }
        public void Validation_should_fail_when_supplying_request_body_stream_with_get_method()
        {
            request = Request.Get(request.Url).WithContent(new StreamContent(Stream.Null, 123));

            RequestValidator.IsValid(request).Should().BeFalse();

            Console.Out.WriteLine(RequestValidator.Validate(request).Single());
        }
            private bool IsValidRequest(HttpRequest request)
            {
                var requestUrl = RequestRawUrl(request);
                var parameters = new Dictionary <string, string>();
                var signature  = request.Headers["X-Twilio-Signature"].FirstOrDefault();

                return(_requestValidator.Validate(requestUrl, parameters, signature));
            }
        public void Validation_procedures_should_pass_on_a_well_formed_https_request()
        {
            request = new Request(request.Method, new Uri("https://foo/bar"));

            RequestValidator.Validate(request).Should().BeEmpty();

            RequestValidator.IsValid(request).Should().BeTrue();
        }
        public void Validation_should_fail_if_request_has_an_url_with_non_http_scheme()
        {
            request = new Request(request.Method, new Uri("ftp://foo/bar"));

            RequestValidator.IsValid(request).Should().BeFalse();

            Console.Out.WriteLine(RequestValidator.Validate(request).Single());
        }
Beispiel #8
0
        private bool IsValidRequest(HttpRequest request)
        {
            var requestUrl = RequestRawUrl(request);
            var parameters = ToDictionary(request.Form);
            var signature  = request.Headers["X-Twilio-Signature"];

            return(_requestValidator.Validate(requestUrl, parameters, signature));
        }
Beispiel #9
0
        public void RequestsWithUnexpectedOwnerThrowException([ValueSource("UnexpectedOwnerRequests")] ApplicationLoadBalancerRequest request)
        {
            var options = Options.Create(new Config {
                GithubOwner = "Codertocat", GithubSigningSecret = "test_key"
            });
            var requestValidator = new RequestValidator(options);

            Assert.Throws(Is.InstanceOf <UnexpectedOwnerException>(), () => requestValidator.Validate(request));
        }
Beispiel #10
0
        private bool IsValidRequest(TwilioWebhookBindingModel twilioAuthenticationBindingModel)
        {
            var signature = twilioAuthenticationBindingModel.Headers[_twilioHeader];
            var form      = twilioAuthenticationBindingModel.Form;

            var requestUri = twilioAuthenticationBindingModel.DisplayUrl;

            return(_requestValidator.Validate(requestUri, form, signature));
        }
Beispiel #11
0
        public void DeleteCloudFrontOriginAccessIdentityMarshallTest()
        {
            var operation = service_model.FindOperation("DeleteCloudFrontOriginAccessIdentity");

            var request    = InstantiateClassGenerator.Execute <DeleteCloudFrontOriginAccessIdentityRequest>();
            var marshaller = new DeleteCloudFrontOriginAccessIdentityRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("DeleteCloudFrontOriginAccessIdentity", request, internalRequest, service_model);
        }
        public void PublishMarshallTest()
        {
            var operation = service_model.FindOperation("Publish");

            var request    = InstantiateClassGenerator.Execute <PublishRequest>();
            var marshaller = new PublishRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("Publish", request, internalRequest, service_model);
        }
Beispiel #13
0
        public void TagResourceMarshallTest()
        {
            var operation = service_model.FindOperation("TagResource");

            var request    = InstantiateClassGenerator.Execute <TagResourceRequest>();
            var marshaller = new TagResourceRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("TagResource", request, internalRequest, service_model);
        }
        public void RemovePermissionMarshallTest()
        {
            var operation = service_model.FindOperation("RemovePermission");

            var request    = InstantiateClassGenerator.Execute <RemovePermissionRequest>();
            var marshaller = new RemovePermissionRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("RemovePermission", request, internalRequest, service_model);
        }
Beispiel #15
0
        private bool ValidateDataRequest()
        {
            RequestValidator requestValidator = new RequestValidator();

            FluentValidation.Results.ValidationResult dataValidationResult = requestValidator.Validate(requestService);
            IList <ValidationFailure> validationFailures = dataValidationResult.Errors;
            UserFeedback userFeedback = new UserFeedback(FormGrid, validationFailures);

            userFeedback.ShowFeedback();
            return(dataValidationResult.IsValid);
        }
        public void SetDefaultPolicyVersionMarshallTest()
        {
            var operation = service_model.FindOperation("SetDefaultPolicyVersion");

            var request    = InstantiateClassGenerator.Execute <SetDefaultPolicyVersionRequest>();
            var marshaller = new SetDefaultPolicyVersionRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("SetDefaultPolicyVersion", request, internalRequest, service_model);
        }
Beispiel #17
0
        public void ModifyMountTargetSecurityGroupsMarshallTest()
        {
            var operation = service_model.FindOperation("ModifyMountTargetSecurityGroups");

            var request    = InstantiateClassGenerator.Execute <ModifyMountTargetSecurityGroupsRequest>();
            var marshaller = new ModifyMountTargetSecurityGroupsRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("ModifyMountTargetSecurityGroups", request, internalRequest, service_model);
        }
        public void AddTagsToVaultMarshallTest()
        {
            var operation = service_model.FindOperation("AddTagsToVault");

            var request    = InstantiateClassGenerator.Execute <AddTagsToVaultRequest>();
            var marshaller = new AddTagsToVaultRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("AddTagsToVault", request, internalRequest, service_model);
        }
Beispiel #19
0
        public void SetCognitoEventsMarshallTest()
        {
            var operation = service_model.FindOperation("SetCognitoEvents");

            var request    = InstantiateClassGenerator.Execute <SetCognitoEventsRequest>();
            var marshaller = new SetCognitoEventsRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("SetCognitoEvents", request, internalRequest, service_model);
        }
Beispiel #20
0
        public void DeleteTagsMarshallTest()
        {
            var operation = service_model.FindOperation("DeleteTags");

            var request    = InstantiateClassGenerator.Execute <DeleteTagsRequest>();
            var marshaller = new DeleteTagsRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("DeleteTags", request, internalRequest, service_model);
        }
        public void AttachPrincipalPolicyMarshallTest()
        {
            var operation = service_model.FindOperation("AttachPrincipalPolicy");

            var request    = InstantiateClassGenerator.Execute <AttachPrincipalPolicyRequest>();
            var marshaller = new AttachPrincipalPolicyRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("AttachPrincipalPolicy", request, internalRequest, service_model);
        }
        public void RejectCertificateTransferMarshallTest()
        {
            var operation = service_model.FindOperation("RejectCertificateTransfer");

            var request    = InstantiateClassGenerator.Execute <RejectCertificateTransferRequest>();
            var marshaller = new RejectCertificateTransferRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("RejectCertificateTransfer", request, internalRequest, service_model);
        }
        public void CreateTopicRuleMarshallTest()
        {
            var operation = service_model.FindOperation("CreateTopicRule");

            var request    = InstantiateClassGenerator.Execute <CreateTopicRuleRequest>();
            var marshaller = new CreateTopicRuleRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("CreateTopicRule", request, internalRequest, service_model);
        }
        public void UpdateCertificateMarshallTest()
        {
            var operation = service_model.FindOperation("UpdateCertificate");

            var request    = InstantiateClassGenerator.Execute <UpdateCertificateRequest>();
            var marshaller = new UpdateCertificateRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("UpdateCertificate", request, internalRequest, service_model);
        }
        public void CompleteVaultLockMarshallTest()
        {
            var operation = service_model.FindOperation("CompleteVaultLock");

            var request    = InstantiateClassGenerator.Execute <CompleteVaultLockRequest>();
            var marshaller = new CompleteVaultLockRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("CompleteVaultLock", request, internalRequest, service_model);
        }
        public void AbortMultipartUploadMarshallTest()
        {
            var operation = service_model.FindOperation("AbortMultipartUpload");

            var request    = InstantiateClassGenerator.Execute <AbortMultipartUploadRequest>();
            var marshaller = new AbortMultipartUploadRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("AbortMultipartUpload", request, internalRequest, service_model);
        }
Beispiel #27
0
        public void NonPostRequestsThrowMethodNotAllowed([Values("GET", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS")] string method)
        {
            var request = new ApplicationLoadBalancerRequest {
                HttpMethod = method
            };
            var options = Options.Create(new Config {
                GithubOwner = "Codertocat", GithubSigningSecret = "test_key"
            });
            var requestValidator = new RequestValidator(options);

            Assert.Throws(Is.InstanceOf <MethodNotAllowedException>(), () => requestValidator.Validate(request));
        }
        public void TestRequestValidator(TestCase testCase)
        {
            var requestValidator = new RequestValidator();
            var response         = requestValidator.Validate(testCase.OriginalString);

            Assert.AreEqual(response.Success, testCase.Success);

            if (!response.Success)
            {
                Assert.AreEqual(response.Fault.Code, testCase.ErrorCode);
            }
        }
Beispiel #29
0
        public void PostRequestsDontThrowMethodNotAllowed()
        {
            var request = new ApplicationLoadBalancerRequest {
                HttpMethod = "POST"
            };

            var options = Options.Create(new Config {
                GithubOwner = "Codertocat", GithubSigningSecret = "test_key"
            });
            var requestValidator = new RequestValidator(options);

            Assert.Throws(Is.Not.InstanceOf <MethodNotAllowedException>(), () => requestValidator.Validate(request));
        }
Beispiel #30
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var data = await _requestDataProvider.GetRequestDataAsync();

            if (data.IsLocal || _requestValidator.Validate(data.Url, data.Parameters, data.Signature))
            {
                await next(context);
            }
            else
            {
                context.Response.StatusCode = 400; // BadRequest
            }
        }