Skip to content

Commit

Permalink
refactor(xtest): Convert to pytest framework (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Jul 31, 2024
1 parent 1f2ee4c commit 803f921
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 1,782 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/xtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ jobs:
- name: build the js cli
run: |
make clean
cd lib
CLIENT_VERSION=$(npm pkg get version | tr -d \")
cd ..
CLIENT_VERSION=$(cd lib && npm pkg get version | tr -d \")
make lib/opentdf-client-$CLIENT_VERSION.tgz
rm -rf */node_modules
cd cli
Expand All @@ -132,8 +130,6 @@ jobs:
npm install ../../client-web/cli/opentdf-cli-*.tgz
npm list
working-directory: otdftests/xtest
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

######## CHECKOUT GO CLI #############
- name: Check out otdfctl
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ abacus-and-api-integration-tests/playwright-report/
abacus-and-api-integration-tests/.helm/
abacus-and-api-integration-tests/e2e/test-results
abacus-and-api-integration-tests/e2e/playwright-report
__pycache__/
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
# tests
Tests for OpenTDF
# Tests for OpenTDF

## [Cross-client compatibility tests](xtests)

1) `cd xtest`
2) `npm ci && npm i @opentdf/client@CLIENT_VERSION`
3) `pip3 install -r ./requirements.txt`
4) `tilt up`

### To use a Github Package Manager Version

Before doing theabove, [configure Github packages as the scope provider for opentdf](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-to-github-packages)

```
npm login --scope=@opentdf --registry=https://npm.pkg.github.com
```

## [Vulnerability](vulnerability)

Automated checks for vulnerabilities identified during penetration testing
> Automated checks for vulnerabilities identified during penetration testing
Place to run frontend and backend together locally.
Check Backend "Quick Start and Development" for [Prerequisites](https://github.com/opentdf/backend#prerequisites)

1) delete `ctlptl delete cluster kind-kind` and clear saved related images in docker if you've run integration tests locally from other folder
1) delete the cluster with `ctlptl delete cluster kind-kind`
and clear saved related images in docker
if you've run integration tests locally from other folder
2) run `ctlptl create cluster kind --registry=ctlptl-registry`
3) `cd vulnerability`
4) `tilt up`

If you are running locally on mac frontend 'npm run build' step may take too long. Possible solution is run this
command `npm run build` and change frontend/Dockerfile line `RUN npm run build` to `COPY build/ build/` so it won`t
run it inside docker. Be careful not to push this changes, we won't need that to CI machines that runs on linux.
If you are running locally on mac,
frontend 'npm run build' step may take too long.
A possible solution is to run `npm run build`
and change `frontend/Dockerfile` line `RUN npm run build` to `COPY build/ build/`
so it won't run it inside docker.
Be careful not to push these changes,
we won't need that to CI machines that runs on linux.

## [Abacus and API integration tests](abacus-and-api-integration-tests)

Automated Playwright tests for Abacus application run against the latest versions of frontend and backend together + API tests for OpenTDF backend services
> Automated Playwright tests for the Abacus application
> run against the latest versions of frontend and backend together
> with API tests for OpenTDF backend services.
Check Backend "Quick Start and Development" for [Prerequisites](https://github.com/opentdf/backend#prerequisites)

1) delete `ctlptl delete cluster kind-kind` and clear saved related images in docker if you've run integration tests locally from other folder
1) delete `ctlptl delete cluster kind-kind`
and clear saved related images in docker
if you've run integration tests locally from another folder
2) run `ctlptl create cluster kind --registry=ctlptl-registry`
3) `cd abacus-and-api-integration-tests`
4) `tilt up`

## Cross-client compatibility tests (xtests)
1) `cd xtest`
2) `npm ci && npm i @opentdf/client@CLIENT_VERSION`
3) `pip3 install -r ./requirements.txt`
4) `tilt up`

### To use a Github Package Manager Version

Before doing theabove, [configure Github packages as the scope provider for opentdf](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-to-github-packages)

```
npm login --scope=@opentdf --registry=https://npm.pkg.github.com
```
Empty file removed xtest/.npmrc
Empty file.
30 changes: 30 additions & 0 deletions xtest/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# x-test

> Compatibility tests for opentdf client libraries and tools.

Requirements:

- go 1.22.3
- node 20
- python 3.10
- jdk 11

## Bringing up the platform backend (macOS)

1. checkout platform (`git checkout https://github.com/opentdf/platform`)
2. switch to the the platform folder (`cd platform`)
3. configure and initialize the platform ()
a. `cp opentdf-dev.yaml opentdf.yaml` & edit the yaml if needed
b. `.github/scripts/init-temp-keys.sh`
c. `sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./keys/localhost.crt`
i. To remove, `sudo security delete-certificate -c "localhost"`
4. Bring up background services, `docker compose up`
5. Add sample users and realm to keycloak, `go run ./service provision keycloak`
6. Add sample attributes and metadata, `go run ./service provision fixtures`
7. start server in background, `go run ./service start`

## Testing with Released Software

```sh
pytest --sdks "js go" --container nano
```
62 changes: 62 additions & 0 deletions xtest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import pytest


def pytest_addoption(parser):
parser.addoption(
"--large",
action="store_true",
help="generate a large (greater than 4 GiB) file for testing",
)
parser.addoption(
"--sdks", help="select which sdks to run by default, unless overridden"
)
parser.addoption("--sdks-decrypt", help="select which sdks to run for decrypt only")
parser.addoption("--sdks-encrypt", help="select which sdks to run for encrypt only")
parser.addoption("--containers", help="which container formats to test")


def pytest_generate_tests(metafunc):
if "size" in metafunc.fixturenames:
metafunc.parametrize("size", ["large" if metafunc.config.getoption("large") else "small"])
if "encrypt_sdk" in metafunc.fixturenames:
if metafunc.config.getoption("--sdks-encrypt"):
encrypt_sdks = metafunc.config.getoption("--sdks-encrypt").split()
elif metafunc.config.getoption("--sdks"):
encrypt_sdks = metafunc.config.getoption("--sdks").split()
else:
encrypt_sdks = ["js", "go", "java"]
metafunc.parametrize("encrypt_sdk", encrypt_sdks)
if "decrypt_sdk" in metafunc.fixturenames:
if metafunc.config.getoption("--sdks-decrypt"):
decrypt_sdks = metafunc.config.getoption("--sdks-decrypt").split()
elif metafunc.config.getoption("--sdks"):
decrypt_sdks = metafunc.config.getoption("--sdks").split()
else:
decrypt_sdks = ["js", "go", "java"]
metafunc.parametrize("decrypt_sdk", decrypt_sdks)
if "container" in metafunc.fixturenames:
if metafunc.config.getoption("--containers"):
containers = metafunc.config.getoption("--container").split()
else:
containers = ["nano", "ztdf"]
metafunc.parametrize("container", containers)


@pytest.fixture
def pt_file(tmp_dir, size):
pt_file = f"{tmp_dir}test-plain-{size}.txt"
length = (5 * 2**30) if size == "large" else 128
with open(pt_file, "w") as f:
for i in range(0, length, 16):
f.write("{:15,d}\n".format(i))
return pt_file


@pytest.fixture
def tmp_dir():
dname = "tmp/"
isExist = os.path.exists(dname)
if not isExist:
os.makedirs(dname)
return dname
Loading

0 comments on commit 803f921

Please sign in to comment.