Git Product home page Git Product logo

httptogrpcproxy's Introduction

Http To Grpc Proxy - POC

Solution intended to intercept communication with external services in integration tests.

Problem

Predictable and isolated integration testing of application like in diagram is complicated. usual flow

Solution

In the following diagram HttpToGrpcMock is service hosted in docker compose with external.service.one and external.service.two names assigned to it. Edge services will have those URL's resolved to proxy service and no communication to external world will happen at this point.

proxy flow

Sequence diagram may explain better how everyting works: test_flow

Runing in docker compose and docker build

Self signed certificates to show how proxy works with https have been added to repo. Steps 1 - 5 are described here for self reference only

1. Generate self signed certificate:

New-SelfSignedCertificate -NotBefore (Get-Date) `
                          -NotAfter (Get-Date).AddYears(10) `
                          -Subject "second.example.com" `
                          -KeyAlgorithm "RSA" `
                          -KeyLength 2048 `
                          -HashAlgorithm "SHA256" `
                          -CertStoreLocation "cert:\CurrentUser\My" `
                          -KeyUsage KeyEncipherment `
                          -FriendlyName "second.example.com certificate for sample integration tests" `
                          -TextExtension @("2.5.29.19={critical}{text}","2.5.29.37={critical}{text}1.3.6.1.5.5.7.3.1","2.5.29.17={critical}{text}DNS=second.example.com")

2. Export certificate to file system:

$password = ConvertTo-SecureString -String "1234" -Force -AsPlainText
Get-ChildItem -Path cert:\CurrentUser\My\< thumbprint > | Export-PfxCertificate -FilePath "< DockerComposeTests directory >\second.example.com.pfx" -Password $password

3. Export certificate to be trusted in linux:

$certificate = Get-ChildItem -Path "cert:\CurrentUser\My\< thumbprint >
$base64certificate = @"
-----BEGIN CERTIFICATE-----
$([Convert]::ToBase64String($certificate.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks))
-----END CERTIFICATE-----
"@
Set-Content -Path "< DockerComposeTests directory >\second.example.com.cer" -Value $base64certificate

4. Trust self signed certificate in client docker container (in last build step):

COPY ./second.example.com.cer ./second.example.com.crt
RUN cat ./second.example.com.crt >> /etc/ssl/certs/ca-certificates.crt

5. Pass .pfx (private and public) certificates to proxy container as shown in docker-compose.yml example

6. Build and start proxy and test app (which will be trying to call external urls)

docker compose -f .\DockerComposeTests\docker-compose-services.yml -f .\DockerComposeTests\docker-compose-proxy.yml build
docker compose -f .\DockerComposeTests\docker-compose-services.yml -f .\DockerComposeTests\docker-compose-proxy.yml -d up

7. Run tests in docker build

docker build -o . -f ./DockerComposeTests/TestApp.Tests/Dockerfile --build-arg CACHEBUST=$(date) .

Tests result xml file will be copied out of container into ./test_results folder

httptogrpcproxy's People

Contributors

madajevas avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.