示例#1
0
        protected virtual async Task <(bool Result, string Body)> IsValid(RequestVerifier verifier, Microsoft.AspNetCore.Http.HttpRequest request)
        {
            long.TryParse(request.Headers[RequestVerifier.TimestampHeaderName], out var timestamp);
            if (RequireBodyRewind)
            {
                request.EnableBuffering();
            }

            using var sr = new StreamReader(request.Body);
            var bodyText = await sr.ReadToEndAsync();

            if (RequireBodyRewind)
            {
                request.Body.Position = 0;
            }
            var result = verifier.Verify(request.Headers[RequestVerifier.SignatureHeaderName], timestamp, bodyText);

            return(result, bodyText);
        }
示例#2
0
        public void VerifierFailsAlteredSig()
        {
            var verifier = new RequestVerifier(SigningSecret);

            Assert.False(verifier.Verify(ExpectedSig, Timestamp, Body));
        }
示例#3
0
        public void VerifierValidatesExpectedSig()
        {
            var verifier = new RequestVerifier(SigningSecret, TimeSpan.MaxValue);

            Assert.True(verifier.Verify(ExpectedSig, Timestamp, Body));
        }