-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(xtest): ztdf policy manipulation test (#212)
- Loading branch information
1 parent
88d6025
commit b47e5ca
Showing
4 changed files
with
114 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,67 +187,3 @@ jobs: | |
working-directory: otdftests/xtest | ||
env: | ||
PLATFORM_DIR: '../../${{ steps.run-platform.outputs.platform-working-dir }}' | ||
###### TODO: move these unbound tests to v2 platform | ||
# unbound-test-js: | ||
# timeout-minutes: 60 | ||
# runs-on: ubuntu-latest | ||
# defaults: | ||
# run: | ||
# working-directory: xtest | ||
# permissions: | ||
# contents: read | ||
# packages: read | ||
# strategy: | ||
# matrix: | ||
# kasversion: [ python-kas, go-kas ] | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# - name: Set kas-related environment variable | ||
# shell: bash | ||
# run: echo "KAS_VERSION=${{ matrix.kasversion }}" >> $GITHUB_ENV | ||
# - name: Set up Node 18 | ||
# uses: actions/setup-node@v3 | ||
# with: | ||
# node-version: "18.x" | ||
# registry-url: https://npm.pkg.github.com | ||
# - name: Set up Python 3.10 | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.10" | ||
# # todo: install and activate virtual env for python? | ||
# - name: update packages | ||
# run: |- | ||
# npm ci | ||
# npm install @opentdf/cli@${{ github.event.client_payload.version }} @opentdf/client@${{ github.event.client_payload.version }} | ||
# npm list | ||
# pip3 install -r requirements.txt | ||
# env: | ||
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# - uses: yokawasa/[email protected] | ||
# with: | ||
# setup-tools: | | ||
# kubectl | ||
# helm | ||
# tilt | ||
# # This should be in sync with the minikube-deployed kube version below | ||
# kubectl: "1.24.1" | ||
# helm: "3.9.2" | ||
# tilt: "0.31.2" | ||
# - run: | | ||
# kubectl version --client | ||
# kustomize version | ||
# tilt version | ||
# - name: start minikube | ||
# id: minikube | ||
# uses: medyagh/setup-minikube@master | ||
# with: | ||
# minikube-version: 1.26.0 | ||
# # This should be in sync with the setup-tools version above | ||
# kubernetes-version: 1.24.1 | ||
# - name: Run tilt | ||
# run: |- | ||
# [[ -z "${{github.event.inputs.backendVersion}}" ]] && export BACKEND_LATEST_VERSION=$(skopeo list-tags docker://ghcr.io/opentdf/charts/backend \ | ||
# | python3 -c "import sys, json; sys.stdout.write([tag for tag in json.load(sys.stdin)['Tags'] if not tag.endswith('.sig')][-1])") || export BACKEND_LATEST_VERSION="${{github.event.inputs.backendVersion}}" | ||
# echo "Testing Backend [$BACKEND_LATEST_VERSION]">>$GITHUB_STEP_SUMMARY | ||
# kubectl version | ||
# tilt ci -f Tiltfile.unbound-js-sdk |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import filecmp | ||
import os | ||
import subprocess | ||
|
||
import pytest | ||
|
||
|
@@ -11,10 +12,41 @@ | |
counter = 0 | ||
|
||
|
||
def test_tdf(encrypt_sdk, decrypt_sdk, pt_file, tmp_dir, container): | ||
def doEncryptWith( | ||
pt_file: str, encrypt_sdk: str, container: str, tmp_dir: str, use_ecdsa: bool | ||
) -> str: | ||
global counter | ||
counter = (counter or 0) + 1 | ||
c = counter | ||
container_id = f"{encrypt_sdk}-{container}" | ||
if container_id in cipherTexts: | ||
return cipherTexts[container_id] | ||
ct_file = f"{tmp_dir}test-{encrypt_sdk}-{c}.{container}" | ||
tdfs.encrypt( | ||
encrypt_sdk, | ||
pt_file, | ||
ct_file, | ||
mime_type="text/plain", | ||
fmt=container, | ||
use_ecdsa_binding=use_ecdsa, | ||
) | ||
if container == "ztdf": | ||
manifest = tdfs.manifest(ct_file) | ||
assert manifest.payload.isEncrypted | ||
elif container == "nano": | ||
with open(ct_file, "rb") as f: | ||
envelope = nano.parse(f.read()) | ||
assert envelope.header.version.version == 12 | ||
assert envelope.header.binding_mode.use_ecdsa_binding == use_ecdsa | ||
if envelope.header.kas.kid is not None: | ||
# from xtest/platform/opentdf.yaml | ||
expected_kid = b"ec1" + b"\0" * 5 | ||
assert envelope.header.kas.kid == expected_kid | ||
cipherTexts[container_id] = ct_file | ||
return ct_file | ||
|
||
|
||
def test_tdf(encrypt_sdk, decrypt_sdk, pt_file, tmp_dir, container): | ||
use_ecdsa = False | ||
if container == "nano-with-ecdsa": | ||
if not tdfs.supports(encrypt_sdk, "nano_ecdsa"): | ||
|
@@ -23,32 +55,31 @@ def test_tdf(encrypt_sdk, decrypt_sdk, pt_file, tmp_dir, container): | |
) | ||
container = "nano" | ||
use_ecdsa = True | ||
container_id = f"{encrypt_sdk}-{container}" | ||
if container_id not in cipherTexts: | ||
ct_file = f"{tmp_dir}test-{encrypt_sdk}-{c}.{container}" | ||
tdfs.encrypt( | ||
encrypt_sdk, | ||
pt_file, | ||
ct_file, | ||
mime_type="text/plain", | ||
fmt=container, | ||
use_ecdsa_binding=use_ecdsa, | ||
) | ||
if container == "ztdf": | ||
manifest = tdfs.manifest(ct_file) | ||
assert manifest.payload.isEncrypted | ||
elif container == "nano": | ||
with open(ct_file, "rb") as f: | ||
envelope = nano.parse(f.read()) | ||
assert envelope.header.version.version == 12 | ||
assert envelope.header.binding_mode.use_ecdsa_binding == use_ecdsa | ||
if envelope.header.kas.kid is not None: | ||
# from xtest/platform/opentdf.yaml | ||
expected_kid = b"ec1" + b"\0" * 5 | ||
assert envelope.header.kas.kid == expected_kid | ||
cipherTexts[container_id] = ct_file | ||
ct_file = cipherTexts[container_id] | ||
ct_file = doEncryptWith(pt_file, encrypt_sdk, container, tmp_dir, use_ecdsa) | ||
assert os.path.isfile(ct_file) | ||
rt_file = f"{tmp_dir}test-{c}.untdf" | ||
fname = os.path.basename(ct_file).split(".")[0] | ||
rt_file = f"{tmp_dir}test-{fname}.untdf" | ||
tdfs.decrypt(decrypt_sdk, ct_file, rt_file, container) | ||
assert filecmp.cmp(pt_file, rt_file) | ||
|
||
|
||
def breakBinding(manifest: tdfs.Manifest) -> tdfs.Manifest: | ||
# base64 decode policy from manifest.encryptionInformation.policy | ||
p = manifest.encryptionInformation.policy_object | ||
p.body.dataAttributes = [] | ||
p.body.dissem = ["[email protected]"] | ||
manifest.encryptionInformation.policy_object = p | ||
return manifest | ||
|
||
|
||
def test_tdf_with_unbound_policy(encrypt_sdk, decrypt_sdk, pt_file, tmp_dir): | ||
ct_file = doEncryptWith(pt_file, encrypt_sdk, "ztdf", tmp_dir, False) | ||
assert os.path.isfile(ct_file) | ||
b_file = tdfs.update_manifest("unbound_policy", ct_file, breakBinding) | ||
fname = os.path.basename(b_file).split(".")[0] | ||
rt_file = f"{tmp_dir}test-{fname}.untdf" | ||
try: | ||
tdfs.decrypt(decrypt_sdk, b_file, rt_file, "ztdf") | ||
assert False, "decrypt succeeded unexpectedly" | ||
except subprocess.CalledProcessError as exc: | ||
assert b"wrap" in exc.output |