diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89c98a0d7..dd95df872 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -264,102 +264,6 @@ jobs: - name: Build run: nr build - build-test-python: - name: Build and test Python - runs-on: ubuntu-latest - defaults: - run: - working-directory: packages/python - steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - with: - fetch-depth: 0 - - - name: pip update and add build package - run: bash proto2python.sh ~/pyvenv - - - name: Install dependencies - run: pip install "$(echo pkg/armonik*.whl)[tests]" - - - name: Generate certs - working-directory: packages/csharp/ - shell: bash - run: | - mkdir certs - cd certs - ../../../scripts/certs.sh - - name: Install certs - working-directory: packages/csharp/certs - run: | - sudo apt install ca-certificates - sudo mkdir -p /usr/local/share/ca-certificates/ - sudo cp server2-ca.pem /usr/local/share/ca-certificates/ca.crt - sudo update-ca-certificates - - - name: Build Mock server - working-directory: packages/csharp/ArmoniK.Api.Mock - shell: bash - run: | - dotnet publish -o ../out - [ -e ../out/ArmoniK.Api.Mock.exe ] || ln -s ArmoniK.Api.Mock ../out/ArmoniK.Api.Mock.exe - - - name: Test - working-directory: packages/python/ - shell: bash - run: | - set +e - set -x - export CertFolder="$PWD/../csharp/certs" - $PWD/../csharp/out/ArmoniK.Api.Mock.exe \ - grpc:port=5000 http:port=4999 logging:loglevel:default="Warning" \ - & notls_pid=$! - $PWD/../csharp/out/ArmoniK.Api.Mock.exe \ - grpc:port=5001 http:port=5001 logging:loglevel:default="Warning" \ - http:cert="$CertFolder/server1.pem" http:key="$CertFolder/server1.key" \ - & tls_pid=$! - $PWD/../csharp/out/ArmoniK.Api.Mock.exe \ - grpc:port=5002 http:port=5002 logging:loglevel:default="Warning" \ - http:cert="$CertFolder/server2.pem" http:key="$CertFolder/server2.key" \ - & tlsstore_pid=$! - $PWD/../csharp/out/ArmoniK.Api.Mock.exe \ - grpc:port=5003 http:port=5003 logging:loglevel:default="Warning" \ - http:cert="$CertFolder/server1.pem" http:key="$CertFolder/server1.key" http:clientcert="$CertFolder/client-ca.pem" \ - & mtls_pid=$! - $PWD/../csharp/out/ArmoniK.Api.Mock.exe \ - grpc:port=5004 http:port=5004 logging:loglevel:default="Warning" \ - http:cert="$CertFolder/server2.pem" http:key="$CertFolder/server2.key" http:clientcert="$CertFolder/client-ca.pem" \ - & mtlsstore_pid=$! - sleep 5 - set -e - Grpc__Endpoint=http://localhost:5000 Http__Endpoint=http://localhost:4999 pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing - Grpc__Endpoint=https://localhost:5001 Http__Endpoint=https://localhost:5001 Grpc__CaCert="$CertFolder/server1-ca.pem" pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append - Grpc__Endpoint=https://localhost:5002 Http__Endpoint=https://localhost:5002 pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append - Grpc__Endpoint=https://localhost:5003 Http__Endpoint=https://localhost:5003 Grpc__CaCert="$CertFolder/server1-ca.pem" Grpc__ClientCert="$CertFolder/client.pem" Grpc__ClientKey="$CertFolder/client.key" pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append - Grpc__Endpoint=https://localhost:5004 Http__Endpoint=https://localhost:5004 Grpc__ClientCert="$CertFolder/client.pem" Grpc__ClientKey="$CertFolder/client.key" pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append - Grpc__Endpoint=https://localhost:5004 Http__Endpoint=https://localhost:5004 Grpc__ClientCert="$CertFolder/client-client.pem" pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append - Grpc__Endpoint=https://localhost:5004 Http__Endpoint=https://localhost:5004 Grpc__ClientCert="$CertFolder/client.p12" pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append --cov-report xml:coverage.xml --cov-report html:coverage_report - set +e - kill $notls_pid $tls_pid $tlsstore_pid $mtls_pid $mtlsstore_pid - exit $ret - - - name: Get Cover - uses: orgoro/coverage@3f13a558c5af7376496aa4848bf0224aead366ac - with: - coverageFile: packages/python/coverage.xml - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Archive code coverage results html - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a - with: - name: code-coverage-report-html - path: packages/python/coverage_report - - - name: Archive code coverage results xml - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a - with: - name: code-coverage-report-xml - path: packages/python/coverage.xml - build-cpp-packages: strategy: fail-fast: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67351d933..1ee97ed19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,42 +11,80 @@ concurrency: cancel-in-progress: true jobs: - csharp: - name: Test C# + test: + name: Test API strategy: fail-fast: false matrix: - dotnet: - - version: '' - framework: net4.7 - - version: '' - framework: net4.8 - - version: 6.0 - framework: net6.0 - - version: 8.0 - framework: net8.0 - platform: + language: + - lang: C# + cmd: dotnet test -f net4.7 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: '' + env: {} + - lang: C# + cmd: dotnet test -f net4.7 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: '' + env: + GrpcClient__HttpMessageHandler: GrpcWebHandler + - lang: C# + cmd: dotnet test -f net4.8 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: '' + env: {} + - lang: C# + cmd: dotnet test -f net4.8 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: '' + env: + GrpcClient__HttpMessageHandler: GrpcWebHandler + - lang: C# + cmd: dotnet test -f net6.0 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: 6.0 + env: {} + - lang: C# + cmd: dotnet test -f net8.0 --logger "trx;LogFileName=test-results.trx" + dir: csharp/ArmoniK.Api.Client.Test + dotnet: 8.0 + env: {} + - lang: C++ + cmd: ./tools/run_test.sh + dir: cpp + env: {} + - lang: Python + cmd: pytest tests --cov=armonik --cov-config=.coveragerc --cov-report=term-missing --cov-append --cov-report xml:coverage.xml --cov-report html:coverage_report + dir: python + env: {} + plateform: - os: ubuntu-latest - runtime: linux-x64 + - os: windows-latest - os: windows-2019 - runtime: windows-x64 - - os: windows-2022 - runtime: windows-x64 - handler: - - '' - - GrpcWebHandler exclude: - - dotnet: - version: '' - platform: + - language: + lang: Python + plateform: + os: windows-latest + - language: + lang: C++ + plateform: + os: windows-latest + - language: + lang: C++ + plateform: + os: windows-2019 + - language: + lang: Python + plateform: + os: windows-2019 + - language: + lang: C# + dotnet: '' + plateform: os: ubuntu-latest - - dotnet: - version: 6.0 - handler: GrpcWebHandler - - dotnet: - version: 8.0 - handler: GrpcWebHandler - runs-on: ${{ matrix.platform.os }} + runs-on: ${{ matrix.plateform.os }} + env: ${{ matrix.language.env }} steps: - name: Checkout @@ -62,7 +100,7 @@ jobs: cd certs ../../../scripts/certs.sh - name: Install certs - if: ${{ matrix.platform.os == 'ubuntu-latest' }} + if: ${{ matrix.plateform.os == 'ubuntu-latest' }} working-directory: packages/csharp/certs run: | sudo apt install ca-certificates @@ -70,16 +108,38 @@ jobs: sudo cp server2-ca.pem /usr/local/share/ca-certificates/ca.crt sudo update-ca-certificates - name: Install certs - if: ${{ contains(matrix.platform.os, 'windows') }} + if: ${{ contains(matrix.plateform.os, 'windows') }} working-directory: packages/csharp/certs run: | certutil -addstore -f "ROOT" server2-ca.pem - name: Install .NET Core uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4 - if: ${{ matrix.dotnet.version }} != "" + if: ${{ matrix.language.dotnet }} != "" with: - dotnet-version: ${{ matrix.dotnet.version }} + dotnet-version: ${{ matrix.language.dotnet }} + + - name: Print language + run: | + echo "Current language: ${{ matrix.language.lang }}" + + - name: pip update and add build package + if: ${{ matrix.language.lang == 'Python' }} + working-directory: packages/python + run: bash proto2python.sh ~/pyvenv + + - name: Install python dependencies + if: ${{ matrix.language.lang == 'Python' }} + working-directory: packages/python + run: | + pwd + pip install "$(echo pkg/armonik*.whl)[tests]" + + - name: Build C++ package + if: ${{ matrix.language.lang == 'C++' }} + working-directory: packages/cpp + run: | + ./tools/build_test.sh - name: Build Mock server working-directory: packages/csharp/ArmoniK.Api.Mock @@ -88,172 +148,161 @@ jobs: dotnet publish -o ../out [ -e ../out/ArmoniK.Api.Mock.exe ] || ln -s ArmoniK.Api.Mock ../out/ArmoniK.Api.Mock.exe - - name: Test + - name: noTLS working-directory: packages/csharp/ shell: bash - env: - GrpcClient__HttpMessageHandler: ${{ matrix.handler }} run: | - set +e - set -x - export CertFolder="$PWD/certs" - ./out/ArmoniK.Api.Mock.exe \ - grpc:port=5000 http:port=4999 \ - & notls_pid=$! - ./out/ArmoniK.Api.Mock.exe \ - grpc:port=5001 http:port=5001 \ - http:cert="$CertFolder/server1.pem" http:key="$CertFolder/server1.key" \ - & tls_pid=$! - ./out/ArmoniK.Api.Mock.exe \ - grpc:port=5002 http:port=5002 \ - http:cert="$CertFolder/server2.pem" http:key="$CertFolder/server2.key" \ - & tlsstore_pid=$! - ./out/ArmoniK.Api.Mock.exe \ - grpc:port=5003 http:port=5003 \ - http:cert="$CertFolder/server1.pem" http:key="$CertFolder/server1.key" http:clientcert="$CertFolder/client-ca.pem" \ - & mtls_pid=$! - ./out/ArmoniK.Api.Mock.exe \ - grpc:port=5004 http:port=5004 \ - http:cert="$CertFolder/server2.pem" http:key="$CertFolder/server2.key" http:clientcert="$CertFolder/client-ca.pem" \ - & mtlsstore_pid=$! - sleep 5 - - cd ArmoniK.Api.Client.Test - dotnet test -f ${{ matrix.dotnet.framework }} --logger "trx;LogFileName=test-results.trx"; ret=$? - - kill $notls_pid $tls_pid $tlsstore_pid $mtls_pid $mtlsstore_pid - exit $ret - - - name: Test Report - uses: dorny/test-reporter@v1 - if: always() - with: - name: ConnectivityTests ${{ matrix.platform.os }} ${{ matrix.dotnet.framework }} ${{ matrix.handler }} - path: ./packages/csharp/ArmoniK.Api.Client.Test/TestResults/test-results.trx - reporter: dotnet-trx + export Grpc__Port=5000 + export Http__Port=4999 + export Grpc__Endpoint=http://localhost:5000 + export Http__Endpoint=http://localhost:4999 + export GrpcClient__Endpoint=http://localhost:5000 + export GrpcClient__AllowUnsafeConnection=true + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - cpp: - strategy: - fail-fast: false - matrix: - endpoint: - - mock_env: - Grpc__Port: 5000 - Http__Port: 4999 - test_env: - Grpc__Endpoint: http://localhost:5000 - Http__Endpoint: http://localhost:4999 - - mock_env: - Grpc__Port: 5001 - Http__Port: 5001 - Http__Cert: ../cpp/certs/server1.pem - Http__Key: ../cpp/certs/server1.key - test_env: - Grpc__Endpoint: https://localhost:5001 - Grpc__SSLValidation: enable - Grpc__CaCert: /app/source/certs/server1-ca.pem - - mock_env: - Grpc__Port: 5002 - Http__Port: 5002 - Http__Cert: ../cpp/certs/server2.pem - Http__Key: ../cpp/certs/server2.key - test_env: - Grpc__Endpoint: https://localhost:5002 - Grpc__SSLValidation: enable - - mock_env: - Grpc__Port: 5003 - Http__Port: 5003 - Http__Cert: ../cpp/certs/server1.pem - Http__Key: ../cpp/certs/server1.key - Http__ClientCert: ../cpp/certs/client-ca.pem - test_env: - Grpc__Endpoint: https://localhost:5003 - Grpc__SSLValidation: enable - Grpc__mTLS: true - Grpc__CaCert: /app/source/certs/server1-ca.pem - Grpc__ClientCert: /app/source/certs/client.pem - Grpc__ClientKey: /app/source/certs/client.key - - mock_env: - Grpc__Port: 5004 - Http__Port: 5004 - Http__Cert: ../cpp/certs/server2.pem - Http__Key: ../cpp/certs/server2.key - Http__ClientCert: ../cpp/certs/client-ca.pem - test_env: - Grpc__Endpoint: https://localhost:5004 - Grpc__SSLValidation: enable - Grpc__mTLS: true - Grpc__ClientCert: /app/source/certs/client.pem - Grpc__ClientKey: /app/source/certs/client.key - - name: Test C++ - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - with: - ref: ${{ github.ref }} - - - name: Generate certs - working-directory: packages/cpp/ + - name: TLS Insecure + if: ${{ matrix.language.lang == 'C#' }} + working-directory: packages/csharp/ shell: bash run: | - mkdir certs - cd certs - ../../../scripts/certs.sh + export Grpc__Port=5001 + export Http__Port=5001 + export Http__Cert=certs/server1.pem + export Http__Key=certs/server1.key + export Grpc__Endpoint=https://localhost:5001 + export Http__Endpoint=https://localhost:5001 + export Grpc__AllowUnsafeConnection=true + export GrpcClient__Endpoint=https://localhost:5001 + export GrpcClient__AllowUnsafeConnection=true + export Grpc__SSLValidation=enable + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - - name: Install certs - working-directory: packages/cpp/certs - run: | - sudo apt install ca-certificates - sudo mkdir -p /usr/local/share/ca-certificates/ - sudo cp server2-ca.pem /usr/local/share/ca-certificates/ca.crt - sudo update-ca-certificates - - - name: Install .NET Core - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 - with: - dotnet-version: 8.x - - - name: Build Mock server - working-directory: packages/csharp/ArmoniK.Api.Mock + - name: TLS secure + working-directory: packages/csharp/ shell: bash run: | - dotnet publish -o ../out - [ -e ../out/ArmoniK.Api.Mock.exe ] || ln -s ArmoniK.Api.Mock ../out/ArmoniK.Api.Mock.exe + export CertFolder="$PWD/certs" + export Grpc__Port=5001 + export Http__Port=5001 + export Http__Cert=certs/server1.pem + export Http__Key=certs/server1.key + export Grpc__Endpoint=https://localhost:5001 + export Http__Endpoint=https://localhost:5001 + export Grpc__CaCert=certs/server1-ca.pem + export GrpcClient__Endpoint=https://localhost:5001 + export GrpcClient__AllowUnsafeConnection=false + export GrpcClient__CaCert=$CertFolder/server1-ca.pem + export Grpc__SSLValidation=enable + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - - name: Run Mock servers + - name: TLS store working-directory: packages/csharp/ shell: bash - env: ${{ matrix.endpoint.mock_env }} run: | - export CertFolder="$PWD/../cpp/certs" - ./out/ArmoniK.Api.Mock.exe > mock.log 2>&1 & - echo "server_pid=$!" >> $GITHUB_ENV - sleep 5 + export Grpc__Port=5002 + export Http__Port=5002 + export Http__Cert=certs/server2.pem + export Http__Key=certs/server2.key + export Grpc__Endpoint=https://localhost:5002 + export Http__Endpoint=https://localhost:5002 + export GrpcClient__Endpoint=https://localhost:5002 + export GrpcClient__AllowUnsafeConnection=false + export Grpc__SSLValidation=enable + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - - name: Build Test - working-directory: packages/cpp + - name: mTLS Insecure + if: ${{ matrix.language.lang == 'C#' }} + working-directory: packages/csharp/ + shell: bash run: | - ./tools/run_test.sh + export CertFolder="$PWD/certs" + export Grpc__Port=5003 + export Http__Port=5003 + export Http__Cert=certs/server1.pem + export Http__Key=certs/server1.key + export Grpc__Endpoint=https://localhost:5003 + export Http__Endpoint=https://localhost:5003 + export Grpc__ClientCert=certs/client.pem + export Grpc__ClientKey=certs/client.key + export GrpcClient__Endpoint=https://localhost:5003 + export GrpcClient__AllowUnsafeConnection=true + export GrpcClient__CertPem=$CertFolder/client.pem + export GrpcClient__KeyPem=$CertFolder/client.key + export Grpc__SSLValidation=enable + export Grpc__mTLS=true + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - - name: Run Test - env: ${{ matrix.endpoint.test_env }} + - name: mTLS secure + working-directory: packages/csharp/ + shell: bash run: | - echo "$PWD/packages/cpp/certs" - docker run --rm -t --network host -v "$PWD/packages/cpp/certs:/app/source/certs" -v "/usr/local/share/ca-certificates/:/usr/local/share/ca-certificates" \ - -e Grpc__EndPoint="$Grpc__Endpoint" \ - -e Http__EndPoint="${Http__Endpoint:-$Grpc__Endpoint}" \ - ${Grpc__SSLValidation:+-e Grpc__SSLValidation="$Grpc__SSLValidation"} \ - ${Grpc__CaCert:+-e Grpc__CaCert="$Grpc__CaCert"} \ - ${Grpc__mTLS:+-e Grpc__mTLS="$Grpc__mTLS"} \ - ${Grpc__ClientCert:+-e Grpc__ClientCert="$Grpc__ClientCert"} \ - ${Grpc__ClientKey:+-e Grpc__ClientKey="$Grpc__ClientKey"} \ - "armonik-api-cpp:0.1.0" + export CertFolder="$PWD/certs" + export Grpc__Port=5003 + export Http__Port=5003 + export Http__Cert=certs/server1.pem + export Http__Key=certs/server1.key + export Http__ClientCert=certs/client-ca.pem + export Grpc__Endpoint=https://localhost:5003 + export Http__Endpoint=https://localhost:5003 + export Grpc__CaCert=certs/server1-ca.pem + export Grpc__ClientCert=certs/client.pem + export Grpc__ClientKey=certs/client.key + export GrpcClient__Endpoint=https://localhost:5003 + export GrpcClient__AllowUnsafeConnection=false + export GrpcClient__CaCert=$CertFolder/server1-ca.pem + export GrpcClient__CertPem=$CertFolder/client.pem + export GrpcClient__KeyPem=$CertFolder/client.key + export Grpc__SSLValidation=enable + export Grpc__mTLS=true + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' - - name: Stop Mock Server - if: always() + - name: mTLS store working-directory: packages/csharp/ + shell: bash run: | - kill $server_pid || true - cat mock.log + export CertFolder="$PWD/certs" + export Grpc__Port=5004 + export Http__Port=5004 + export Http__Cert=certs/server2.pem + export Http__Key=certs/server2.key + export Http__ClientCert=certs/client-ca.pem + export Grpc__Endpoint=https://localhost:5004 + export Http__Endpoint=https://localhost:5004 + export Grpc__ClientCert=certs/client.pem + export Grpc__ClientKey=certs/client.key + export GrpcClient__Endpoint=https://localhost:5004 + export GrpcClient__AllowUnsafeConnection=false + export GrpcClient__CertPem=$CertFolder/client.pem + export GrpcClient__KeyPem=$CertFolder/client.key + export Grpc__SSLValidation=enable + export Grpc__mTLS=true + ../../scripts/mock_test.sh ${{ matrix.language.dir }} '${{ matrix.language.cmd }}' + + - name: Test Report + uses: dorny/test-reporter@v1 + if: ${{ matrix.language.lang == 'C#' && always() }} + with: + name: ConnectivityTests ${{ matrix.plateform.os }} ${{ matrix.dotnet.framework }} ${{ matrix.language.handler }} + path: ./packages/csharp/ArmoniK.Api.Client.Test/TestResults/test-results.trx + reporter: dotnet-trx + + - name: Get Cover Python + uses: orgoro/coverage@3f13a558c5af7376496aa4848bf0224aead366ac + if: ${{ matrix.language.lang == 'Python' && always() }} + with: + coverageFile: packages/python/coverage.xml + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Archive code coverage results html + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a + if: ${{ matrix.language.lang == 'Python' && always() }} + with: + name: code-coverage-report-html + path: packages/python/coverage_report + + - name: Archive code coverage results xml + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a + if: ${{ matrix.language.lang == 'Python' && always() }} + with: + name: code-coverage-report-xml + path: packages/python/coverage.xml diff --git a/packages/cpp/tools/build_test.sh b/packages/cpp/tools/build_test.sh new file mode 100755 index 000000000..b829bad2e --- /dev/null +++ b/packages/cpp/tools/build_test.sh @@ -0,0 +1,7 @@ +#! /bin/sh + +script_path="$(dirname "${BASH_SOURCE:-$0}")" +working_dir="$(realpath "${script_path}/../../../" )" +dockerfile="${1:-"${working_dir}/packages/cpp/ArmoniK.Api.Tests/Dockerfile"}" +image_tag="${2:-"armonik-api-cpp:0.1.0"}" +docker build --rm -t "$image_tag" -f "$dockerfile" --progress plain "$working_dir" diff --git a/packages/cpp/tools/run_test.sh b/packages/cpp/tools/run_test.sh index b829bad2e..6715a22d5 100755 --- a/packages/cpp/tools/run_test.sh +++ b/packages/cpp/tools/run_test.sh @@ -1,7 +1,14 @@ #! /bin/sh +set -x script_path="$(dirname "${BASH_SOURCE:-$0}")" -working_dir="$(realpath "${script_path}/../../../" )" -dockerfile="${1:-"${working_dir}/packages/cpp/ArmoniK.Api.Tests/Dockerfile"}" -image_tag="${2:-"armonik-api-cpp:0.1.0"}" -docker build --rm -t "$image_tag" -f "$dockerfile" --progress plain "$working_dir" +CertFolder="$(realpath "$script_path/../../csharp/certs" )" +docker run --rm -t --network host -v "$CertFolder:/app/source/certs" -v "/usr/local/share/ca-certificates/:/usr/local/share/ca-certificates" \ + -e Grpc__EndPoint="$Grpc__Endpoint" \ + -e Http__EndPoint="${Http__Endpoint:-$Grpc__Endpoint}" \ + ${Grpc__SSLValidation:+-e Grpc__SSLValidation} \ + ${Grpc__CaCert:+-e Grpc__CaCert="/app/source/certs/server1-ca.pem"} \ + ${Grpc__mTLS:+-e Grpc__mTLS} \ + ${Grpc__ClientCert:+-e Grpc__ClientCert="/app/source/certs/client.pem"} \ + ${Grpc__ClientKey:+-e Grpc__ClientKey="/app/source/certs/client.key"} \ + "armonik-api-cpp:0.1.0" diff --git a/packages/csharp/ArmoniK.Api.Client.Test/ArmoniK.Api.Client.Tests.csproj b/packages/csharp/ArmoniK.Api.Client.Test/ArmoniK.Api.Client.Tests.csproj index b8f03cdc7..038ea58e2 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/ArmoniK.Api.Client.Tests.csproj +++ b/packages/csharp/ArmoniK.Api.Client.Test/ArmoniK.Api.Client.Tests.csproj @@ -20,17 +20,20 @@ - - - + + + + + + - + - + diff --git a/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityKind.cs b/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityKind.cs deleted file mode 100644 index d054313e3..000000000 --- a/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityKind.cs +++ /dev/null @@ -1,123 +0,0 @@ -// This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2024. All rights reserved. -// W. Kirschenmann -// J. Gurhem -// D. Dubuc -// L. Ziane Khodja -// F. Lemaitre -// S. Djebbar -// J. Fonseca -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using System; -using System.IO; -using System.Runtime.InteropServices; - -using ArmoniK.Api.Client.Options; -using ArmoniK.Api.Client.Submitter; - -using Grpc.Net.Client; - -namespace ArmoniK.Api.Client.Tests; - -public enum ConnectivityKind -{ - Unencrypted, - TlsInsecure, - TlsCert, - TlsStore, - MTlsInsecure, - MTlsCert, - MTlsStore, -} - -internal static class ConnectivityKindExt -{ - private static string CertFolder - => Environment.GetEnvironmentVariable("CertFolder") ?? "../../../../certs"; - - private static string MessageHandler - => Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - - internal static bool IsTls(this ConnectivityKind kind) - => kind switch - { - ConnectivityKind.Unencrypted => false, - _ => true, - }; - - internal static bool IsInsecure(this ConnectivityKind kind) - => kind switch - { - ConnectivityKind.Unencrypted or ConnectivityKind.TlsInsecure or ConnectivityKind.MTlsInsecure => true, - _ => false, - }; - - internal static bool IsMTls(this ConnectivityKind kind) - => kind switch - { - ConnectivityKind.MTlsInsecure => true, - ConnectivityKind.MTlsCert => true, - ConnectivityKind.MTlsStore => true, - _ => false, - }; - - internal static string? GetCaCertPath(this ConnectivityKind kind) - => kind switch - { - ConnectivityKind.TlsCert or ConnectivityKind.MTlsCert => Path.Combine(CertFolder, - "server1-ca.pem"), - _ => null, - }; - - internal static (string?, string?) GetClientCertPath(this ConnectivityKind kind) - => kind.IsMTls() - ? (Path.Combine(CertFolder, - "client.pem"), Path.Combine(CertFolder, - "client.key")) - : (null, null); - - internal static string GetEndpoint(this ConnectivityKind kind) - => kind switch - { - ConnectivityKind.Unencrypted => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler.ToLower() - .Contains("web") - ? "http://localhost:4999" - : "http://localhost:5000", - ConnectivityKind.TlsInsecure => "https://localhost:5001", - ConnectivityKind.TlsCert => "https://localhost:5001", - ConnectivityKind.TlsStore => "https://localhost:5002", - ConnectivityKind.MTlsInsecure => "https://localhost:5003", - ConnectivityKind.MTlsCert => "https://localhost:5003", - ConnectivityKind.MTlsStore => "https://localhost:5004", - _ => "http://localhost:4999", - }; - - internal static GrpcChannel GetChannel(this ConnectivityKind kind) - { - var (certPath, keyPath) = kind.GetClientCertPath(); - - return GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = kind.GetEndpoint(), - AllowUnsafeConnection = kind.IsInsecure(), - CertPem = certPath ?? "", - KeyPem = keyPath ?? "", - CaCert = kind.GetCaCertPath() ?? "", - HttpMessageHandler = MessageHandler, - }); - } -} diff --git a/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityTest.cs index 6552692a9..e60f8b101 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/ConnectivityTest.cs @@ -21,13 +21,19 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; +using ArmoniK.Api.Client.Options; +using ArmoniK.Api.Client.Submitter; using ArmoniK.Api.gRPC.V1; using ArmoniK.Api.gRPC.V1.Results; using ArmoniK.Utils; +using Microsoft.Extensions.Configuration; + using NUnit.Framework; namespace ArmoniK.Api.Client.Tests; @@ -35,10 +41,27 @@ namespace ArmoniK.Api.Client.Tests; [TestFixture] public class ConnectivityTests { + [SetUp] + public void SetUp() + { + var builder = new ConfigurationBuilder().AddEnvironmentVariables(); + var configuration = builder.Build(); + options_ = configuration.GetRequiredSection(GrpcClient.SettingSection) + .Get()!; + if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || options_.HttpMessageHandler.ToLower() + .Contains("web")) + { + options_!.Endpoint = Environment.GetEnvironmentVariable("Http__Endpoint"); + } + } + + private GrpcClient? options_; + [Test] - public void ResultsGetServiceConfiguration([Values] ConnectivityKind connectivityKind) + public void ResultsGetServiceConfiguration() { - var channel = connectivityKind.GetChannel(); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var resultClient = new Results.ResultsClient(channel); Assert.That(() => resultClient.GetServiceConfiguration(new Empty()), @@ -46,8 +69,7 @@ public void ResultsGetServiceConfiguration([Values] ConnectivityKind connectivit } [Test] - public async Task MultipleChannels([Values] ConnectivityKind connectivityKind, - [Values(1, + public async Task MultipleChannels([Values(1, 2, 10, 100)] @@ -56,7 +78,7 @@ public async Task MultipleChannels([Values] ConnectivityKind connectivityKind, var channels = await Enumerable.Range(0, concurrency) .ParallelSelect(new ParallelTaskOptions(-1), - i => Task.FromResult(connectivityKind.GetChannel())) + i => Task.FromResult(GrpcChannelFactory.CreateChannel(options_!))) .ToListAsync() .ConfigureAwait(false); diff --git a/scripts/mock_test.sh b/scripts/mock_test.sh new file mode 100755 index 000000000..06e32817c --- /dev/null +++ b/scripts/mock_test.sh @@ -0,0 +1,36 @@ +#! /bin/sh + +set -x + +if [ $# -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +script_path="$(dirname "${BASH_SOURCE:-$0}")" +working_dir="$(realpath "$script_path/../packages" )" + +TEST_DIR="${1:?Test dir is not set}" +TEST_COMMAND="${2:?Command is not set}" + +if [ -n "$Grpc__CaCert" ]; then + export Grpc__CaCert="$working_dir/csharp/$Grpc__CaCert" +fi +if [ -n "$Grpc__ClientCert" ]; then + export Grpc__ClientCert="$working_dir/csharp/$Grpc__ClientCert" +fi +if [ -n "$Grpc__ClientKey" ]; then + export Grpc__ClientKey="$working_dir/csharp/$Grpc__ClientKey" +fi + +"$working_dir/csharp/out/ArmoniK.Api.Mock.exe" & + server_pid=$! +sleep 5 + +cd "$working_dir/$TEST_DIR" + +$TEST_COMMAND || ret=$? + +echo $server_pid +kill $server_pid +exit $ret