Exemplo n.º 1
0
        public async Task CanIgnoreResponseValidation()
        {
            var server         = _host.GetTestServer();
            var messageHandler = new HttpSignatureDelegatingHandler(
                credential: GetSigningCredentials(),
                headerNames: new[] { "(request-target)", "(created)", "digest", "x-request-id" },
                innerHandler: server.CreateHandler()
                );

            messageHandler.IgnoreResponseValidation = true;
            var client = new HttpClient(messageHandler)
            {
                BaseAddress = server.BaseAddress
            };

            client.DefaultRequestHeaders.Add("X-Date", DateTimeOffset.UtcNow.AddDays(-2).ToString("r"));
            client.DefaultRequestHeaders.Add("X-Request-Id", Guid.NewGuid().ToString());
            var response = await client.GetAsync("/api/psd2/one/two/three");

            var json = await response.Content.ReadAsStringAsync();

            Assert.Equal(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}", json);
        }
Exemplo n.º 2
0
        public HttpTokenIntegrationTests()
        {
            var host = Host.CreateDefaultBuilder().ConfigureWebHostDefaults(webBuilder => {
                webBuilder.UseContentRoot(Directory.GetCurrentDirectory())
                .UseWebRoot(Directory.GetCurrentDirectory())
                .UseTestServer()
                .ConfigureServices(services => {
                    services.AddHttpSignatures(options => {
                        options.MapPath("/api/psd2", HeaderFieldNames.RequestTarget, HeaderFieldNames.Created, HttpDigest.HTTPHeaderName, "x-response-id");
                        options.IgnorePath("/api/psd2/payments/execute", HttpMethods.Get);
                        options.IgnorePath("/api/psd2/opendata", HttpMethods.Get);
                        options.IgnorePath("/api/psd2/other");
                        options.IgnorePath("/api/psd2/consents/{consentId}/status");
                        options.RequestValidation = true;
                        options.ResponseSigning   = true;
                    })
                    .AddSigningCredential(GetSigningCredentials());
                })
                .Configure(app => {
                    app.UseRouting();
                    app.UseHttpSignatures();
                    app.UseEndpoints(endpoints => {
                        endpoints.MapGet("/api/psd2/payments", async context => {
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapGet("/api/psd2/payments/execute", async context => {
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapGet("/api/psd2/opendata/branches", async context => {
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapGet("/api/psd2/other/sub", async context => {
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapGet("/api/psd2/consents/{consentId}/status", async context => {
                            var consentId = context.Request.RouteValues["consentId"];
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapPost("/api/psd2/consents/{consentId}/status", async context => {
                            var consentId = context.Request.RouteValues["consentId"];
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                        endpoints.MapGet("/api/psd2/one/two/three", async context => {
                            context.Response.Headers["Content-Type"] = "application/json;UTF-8";
                            await context.Response.WriteAsync(@"{""amount"":123.9,""date"":""2019-06-21T12:05:40.111Z""}");
                        });
                    });
                });
            })
                       .Build();

            _host = host;
            host.Start();
            var server         = host.GetTestServer();
            var messageHandler = new HttpSignatureDelegatingHandler(
                credential: GetSigningCredentials(),
                headerNames: new[] { "(request-target)", "(created)", "digest", "x-request-id" },
                innerHandler: server.CreateHandler()
                );

            messageHandler.IgnorePath("api/psd2/payments/EXECUTE", HttpMethods.Get);
            messageHandler.IgnorePath("/api/psd2/opendata", HttpMethods.Get);
            messageHandler.IgnorePath("/api/psd2/other");
            messageHandler.IgnorePath("/api/psd2/consents/{consentId}/status");
            _client = new HttpClient(messageHandler)
            {
                BaseAddress = server.BaseAddress
            };
        }