Skip to content

Commit

Permalink
test: move convert tests to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
ejoerns committed Nov 4, 2023
1 parent 9f905dd commit 42825ff
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 143 deletions.
16 changes: 16 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def have_openssl():
return exitcode == 0


def have_casync():
try:
out, err, exitcode = run("casync --version")
return exitcode == 0
except Exception:
return False


def have_desync():
try:
out, err, exitcode = run("desync --help")
return exitcode == 0
except Exception:
return False


ca_dev = "openssl-ca/dev"
ca_rel = "openssl-ca/rel"

Expand Down
143 changes: 0 additions & 143 deletions test/rauc.t
Original file line number Diff line number Diff line change
Expand Up @@ -264,149 +264,6 @@ test_expect_success FAKETIME "rauc sign bundle with valid certificate (encrypted
test -f ${TEST_TMPDIR}/out.raucb
"

test_expect_success CASYNC "rauc convert" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
rm -f casync.raucb &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
convert ${TEST_TMPDIR}/good-bundle.raucb casync.raucb &&
test -f casync.raucb
"

test_expect_success CASYNC "rauc convert (ignore-image)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
rm -f casync.raucb &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
convert \
--ignore-image appfs \
${TEST_TMPDIR}/good-bundle.raucb casync.raucb &&
test -f casync.raucb
"

test_expect_success CASYNC "rauc convert (output exists)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
touch casync.raucb &&
test_must_fail rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
convert ${TEST_TMPDIR}/good-bundle.raucb casync.raucb &&
test -f casync.raucb
"

test_expect_success CASYNC "rauc convert (error)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
rm -f casync.raucb &&
test_must_fail rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/rel/release-2018.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/rel/private/release-2018.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/rel-ca.pem \
convert ${TEST_TMPDIR}/good-bundle.raucb casync.raucb &&
test ! -f casync.raucb
"

test_expect_success CASYNC "rauc convert casync extra args" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
test_when_finished rm -rf ${TEST_TMPDIR}/casync-extra-args.raucb &&
test_when_finished rm -rf ${TEST_TMPDIR}/casync-extra-args.castr &&
rm -f casync-extra-args.raucb &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
convert \
--casync-args=\"--chunk-size=64000\" \
${TEST_TMPDIR}/good-bundle.raucb casync-extra-args.raucb &&
test -f casync-extra-args.raucb &&
test -d casync-extra-args.castr
"

test_expect_success CASYNC "rauc convert (verity)" "
test_when_finished rm -rf ${TEST_TMPDIR}/install-content &&
test_when_finished rm -f ${TEST_TMPDIR}/tmp-verity.raucb &&
test_when_finished rm -f ${TEST_TMPDIR}/casync-verity.raucb &&
test_when_finished rm -rf ${TEST_TMPDIR}/casync-verity.castr &&
cp -rL ${SHARNESS_TEST_DIRECTORY}/install-content ${TEST_TMPDIR}/ &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
bundle ${TEST_TMPDIR}/install-content/ ${TEST_TMPDIR}/tmp-verity.raucb &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
--trust-environment \
convert ${TEST_TMPDIR}/tmp-verity.raucb ${TEST_TMPDIR}/casync-verity.raucb &&
test -f ${TEST_TMPDIR}/casync-verity.raucb &&
test -d ${TEST_TMPDIR}/casync-verity.castr
"

test_expect_success DESYNC "rauc convert with desync" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
test_when_finished rm -f desync.raucb &&
test_when_finished rm -rf desync.castr &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
--conf $SHARNESS_TEST_DIRECTORY/minimal-desync-test.conf \
convert ${TEST_TMPDIR}/good-bundle.raucb desync.raucb &&
test -f desync.raucb &&
test -d desync.castr
"

test_expect_success DESYNC "rauc convert with desync (output exists)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
touch desync.raucb &&
test_must_fail rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
--conf $SHARNESS_TEST_DIRECTORY/minimal-desync-test.conf \
convert ${TEST_TMPDIR}/good-bundle.raucb desync.raucb &&
test -f desync.raucb
"

test_expect_success DESYNC "rauc convert with desync (error)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
rm -f desync.raucb &&
test_must_fail rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/rel/release-2018.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/rel/private/release-2018.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/rel-ca.pem \
--conf $SHARNESS_TEST_DIRECTORY/minimal-desync-test.conf \
convert ${TEST_TMPDIR}/good-bundle.raucb desync.raucb &&
test ! -f desync.raucb
"

test_expect_success DESYNC "rauc convert desync extra args" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
rm -f desync-extra-args.raucb &&
rauc \
--cert $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/autobuilder-1.cert.pem \
--key $SHARNESS_TEST_DIRECTORY/openssl-ca/dev/private/autobuilder-1.pem \
--keyring $SHARNESS_TEST_DIRECTORY/openssl-ca/dev-ca.pem \
--conf $SHARNESS_TEST_DIRECTORY/minimal-desync-test.conf \
convert \
--casync-args=\"--chunk-size=32:128:512\" \
${TEST_TMPDIR}/good-bundle.raucb desync-extra-args.raucb &&
test -f desync-extra-args.raucb
"

test_expect_success "rauc resign" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
Expand Down
181 changes: 181 additions & 0 deletions test/test_rauc_convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import os
import pytest

from helper import run
from conftest import have_casync
from conftest import have_desync


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert(tmp_path):
out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
f' convert good-bundle.raucb {tmp_path}/casync.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/casync.raucb')


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert_ignore_image(tmp_path):
out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' convert'
' --ignore-image appfs'
f' good-bundle.raucb {tmp_path}/casync.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/casync.raucb')


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert_output_exists(tmp_path):

open(f'{tmp_path}/casync.raucb', 'a').close()

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
f' convert good-bundle.raucb {tmp_path}/casync.raucb')

assert exitcode == 1
assert "already exists" in err

assert os.path.exists(f'{tmp_path}/casync.raucb')


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert_error(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/rel/release-2018.cert.pem'
' --key openssl-ca/rel/private/release-2018.pem'
' --keyring openssl-ca/rel-ca.pem'
f' convert good-bundle.raucb {tmp_path}/casync.raucb')

assert exitcode == 1

assert not os.path.exists(f'{tmp_path}/casync.raucb')


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert_casync_extra_args(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' convert'
' --casync-args=\"--chunk-size=64000\"'
f' good-bundle.raucb {tmp_path}/casync-extra-args.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/casync-extra-args.raucb')
assert os.path.isdir(f'{tmp_path}/casync-extra-args.castr')


@pytest.mark.skipif(not have_casync(), reason="Have no casync")
def test_rauc_convert_verity(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
f' bundle install-content/ {tmp_path}/tmp-verity.raucb')
assert exitcode == 0

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' --trust-environment'
f' convert {tmp_path}/tmp-verity.raucb {tmp_path}/casync-verity.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/casync-verity.raucb')
assert os.path.isdir(f'{tmp_path}/casync-verity.castr')


@pytest.mark.skipif(not have_desync(), reason="Have no desync")
def test_rauc_convert_desync(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' --conf minimal-desync-test.conf'
f' convert good-bundle.raucb {tmp_path}/desync.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/desync.raucb')
assert os.path.isdir(f'{tmp_path}/desync.castr')


@pytest.mark.skipif(not have_desync(), reason="Have no desync")
def test_rauc_convert_desync_output_exists(tmp_path):

open(f'{tmp_path}/desync.raucb', 'a').close()

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' --conf minimal-desync-test.conf'
f' convert good-bundle.raucb {tmp_path}/desync.raucb')

assert exitcode == 1
assert "already exists" in err

assert os.path.exists(f'{tmp_path}/desync.raucb')


@pytest.mark.skipif(not have_desync(), reason="Have no desync")
def test_rauc_convert_desync_error(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/rel/release-2018.cert.pem'
' --key openssl-ca/rel/private/release-2018.pem'
' --keyring openssl-ca/rel-ca.pem'
' --conf minimal-desync-test.conf'
f' convert good-bundle.raucb {tmp_path}/desync.raucb')

assert exitcode == 1

assert not os.path.exists(f'{tmp_path}/desync.raucb')


@pytest.mark.skipif(not have_desync(), reason="Have no desync")
def test_rauc_convert_desync_extra_args(tmp_path):

out, err, exitcode = run(
'rauc'
' --cert openssl-ca/dev/autobuilder-1.cert.pem'
' --key openssl-ca/dev/private/autobuilder-1.pem'
' --keyring openssl-ca/dev-ca.pem'
' --conf minimal-desync-test.conf'
' convert'
' --casync-args=\"--chunk-size=32:128:512\"'
f' good-bundle.raucb {tmp_path}/desync-extra-args.raucb')

assert exitcode == 0

assert os.path.exists(f'{tmp_path}/desync-extra-args.raucb')

0 comments on commit 42825ff

Please sign in to comment.