├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── ccpp.yml │ └── shellcheck-all.yml ├── .gitignore ├── COPYING ├── Makefile.am ├── README ├── README.md ├── autogen.sh ├── compile_flags.txt ├── config ├── configure.ac ├── continous.sh ├── data ├── swupd-update.service.in ├── swupd-update.timer └── verifytime.service ├── docker ├── Dockerfile └── dockerrun.sh ├── docs ├── Doxyfile ├── README.rst ├── how_to_contribute.md ├── swupd-alias.7.rst.in ├── swupd-update.service.4.rst ├── swupd-update.timer.4.rst ├── swupd.1.rst ├── swupd_signature_verification.md └── update-triggers.target.4.rst ├── how-to-make-a-release ├── scripts ├── build_and_run_tests.bash ├── check-lib-version.sh ├── findstatic.pl ├── flag_validator.bash ├── github_actions │ ├── build_ci.bash │ ├── build_ci_dependencies.bash │ ├── build_ci_style.bash │ ├── filter_bats_list.bash │ ├── run_check.bash │ └── weight_tests.bash └── shellcheck.bash ├── src ├── 3rd_party │ ├── 3rd_party.c │ ├── 3rd_party_add.c │ ├── 3rd_party_bundle_add.c │ ├── 3rd_party_bundle_info.c │ ├── 3rd_party_bundle_list.c │ ├── 3rd_party_bundle_remove.c │ ├── 3rd_party_check_update.c │ ├── 3rd_party_clean.c │ ├── 3rd_party_diagnose.c │ ├── 3rd_party_info.c │ ├── 3rd_party_list.c │ ├── 3rd_party_remove.c │ ├── 3rd_party_repair.c │ ├── 3rd_party_repos.c │ ├── 3rd_party_repos.h │ └── 3rd_party_update.c ├── cmds │ ├── autoupdate.c │ ├── bundle_add.c │ ├── bundle_info.c │ ├── bundle_list.c │ ├── bundle_remove.c │ ├── check_update.c │ ├── clean.c │ ├── info.c │ ├── os_install.c │ ├── repair.c │ ├── swupd_cmds.h │ ├── update.c │ └── verify.c ├── lib │ ├── README.md │ ├── archives.c │ ├── archives.h │ ├── comp_functions.c │ ├── comp_functions.h │ ├── config_file.c │ ├── config_file.h │ ├── formatter_json.c │ ├── formatter_json.h │ ├── hashmap.c │ ├── hashmap.h │ ├── int.c │ ├── int.h │ ├── list.c │ ├── list.h │ ├── log.c │ ├── log.h │ ├── macros.h │ ├── strings.c │ ├── strings.h │ ├── sys.c │ ├── sys.h │ ├── thread_pool.c │ ├── thread_pool.h │ ├── timelist.c │ └── timelist.h ├── main.c ├── swupd.h ├── swupd_build_opts.h ├── swupd_build_variant.h ├── swupd_exit_codes.h ├── swupd_lib │ ├── alias.c │ ├── alias.h │ ├── binary_loader.c │ ├── bundle.c │ ├── bundle.h │ ├── config_loader.c │ ├── config_loader.h │ ├── curl.c │ ├── curl_async.c │ ├── delta.c │ ├── extra_files.c │ ├── filedesc.c │ ├── fullfile.c │ ├── globals.c │ ├── globals.h │ ├── hash.c │ ├── hashdump.c │ ├── helpers.c │ ├── heuristics.c │ ├── heuristics.h │ ├── lock.c │ ├── manifest.c │ ├── manifest.h │ ├── manifest_parser.c │ ├── mirror.c │ ├── packs.c │ ├── progress.c │ ├── progress.h │ ├── scripts.c │ ├── scripts.h │ ├── search_file.c │ ├── signature.c │ ├── signature.h │ ├── statedir.c │ ├── statedir.h │ ├── stats.c │ ├── subscriptions.c │ ├── swupd_comp_functions.c │ ├── swupd_comp_functions.h │ ├── swupd_curl.h │ ├── swupd_curl_internal.h │ ├── swupd_progress.c │ ├── swupd_progress.h │ ├── target_root.c │ ├── target_root.h │ ├── telemetry.c │ ├── telemetry.h │ ├── version.c │ ├── xattrs.c │ └── xattrs.h └── verifytime │ ├── verifytime.c │ ├── verifytime.h │ └── verifytime_main.c ├── swupd.bash ├── swupd.zsh └── test ├── code_analysis ├── check_api_changes.bats ├── compliant.bats ├── shellcheck-all.bats ├── shellcheck.bats └── warning_functions.bats ├── functional ├── 3rd-party │ ├── 3rd-party-allow-http.bats │ ├── 3rd-party-bundle-add-basic.bats │ ├── 3rd-party-bundle-add-config-file.bats │ ├── 3rd-party-bundle-add-dangerous-flags.bats │ ├── 3rd-party-bundle-add-export-bin.bats │ ├── 3rd-party-bundle-add-multi-repo.bats │ ├── 3rd-party-bundle-add-state.bats │ ├── 3rd-party-bundle-add-symlink.bats │ ├── 3rd-party-bundle-info-basic.bats │ ├── 3rd-party-bundle-list-basic.bats │ ├── 3rd-party-bundle-list-deps.bats │ ├── 3rd-party-bundle-list-orphans.bats │ ├── 3rd-party-bundle-remove-basic.bats │ ├── 3rd-party-bundle-remove-exported-bin.bats │ ├── 3rd-party-bundle-remove-multi-repo.bats │ ├── 3rd-party-bundle-remove-orphans.bats │ ├── 3rd-party-check-update-basic.bats │ ├── 3rd-party-clean.bats │ ├── 3rd-party-diagnose-basic.bats │ ├── 3rd-party-info.bats │ ├── 3rd-party-json-output-multirepo.bats │ ├── 3rd-party-json-output.bats │ ├── 3rd-party-repair-basic.bats │ ├── 3rd-party-repair-exported-bin.bats │ ├── 3rd-party-repo-add-force.bats │ ├── 3rd-party-repo-add-negative.bats │ ├── 3rd-party-repo-add.bats │ ├── 3rd-party-repo-list.bats │ ├── 3rd-party-repo-remove-corrupt.bats │ ├── 3rd-party-repo-remove-negative.bats │ ├── 3rd-party-repo-remove.bats │ ├── 3rd-party-update-basic.bats │ ├── 3rd-party-update-dangerous-flags.bats │ ├── 3rd-party-update-export-template-multi-repo.bats │ ├── 3rd-party-update-export-template.bats │ ├── 3rd-party-update-exported-bin.bats │ └── 3rd-party-update-specific-version.bats ├── README.md ├── api │ ├── api-3rd-party-add.bats │ ├── api-3rd-party-bundle-add.bats │ ├── api-3rd-party-bundle-info.bats │ ├── api-3rd-party-bundle-list.bats │ ├── api-3rd-party-bundle-remove.bats │ ├── api-3rd-party-checkupdate.bats │ ├── api-3rd-party-clean.bats │ ├── api-3rd-party-diagnose.bats │ ├── api-3rd-party-info.bats │ ├── api-3rd-party-list.bats │ ├── api-3rd-party-remove.bats │ ├── api-3rd-party-repair.bats │ ├── api-3rd-party-update.bats │ ├── api-autoupdate.bats │ ├── api-bundle-add.bats │ ├── api-bundle-info.bats │ ├── api-bundle-list.bats │ ├── api-bundle-remove.bats │ ├── api-checkupdate.bats │ ├── api-clean.bats │ ├── api-diagnose.bats │ ├── api-hashdump.bats │ ├── api-info.bats │ ├── api-mirror.bats │ ├── api-os-install.bats │ ├── api-repair.bats │ ├── api-search-file.bats │ └── api-update.bats ├── autoupdate │ └── aup-basic.bats ├── bundleadd │ ├── add-alias-basic.bats │ ├── add-also-add-flag.bats │ ├── add-bad-hash-state.bats │ ├── add-bad-hash.bats │ ├── add-bad-manifest.bats │ ├── add-basics.bats │ ├── add-boot-file.bats │ ├── add-boot-skip.bats │ ├── add-directory.bats │ ├── add-experimental.bats │ ├── add-fall-back-to-fullfile.bats │ ├── add-include.bats │ ├── add-install-time.bats │ ├── add-json.bats │ ├── add-multiple.bats │ ├── add-no-signature.bats │ ├── add-overwrite-files.bats │ ├── add-skip-scripts.bats │ ├── add-uses-fullfile.bats │ ├── add-uses-zeropack.bats │ └── add-verify-fix-path.bats ├── bundleinfo │ ├── bundle-info-basic.bats │ ├── bundle-info-files.bats │ ├── bundle-info-includes.bats │ ├── bundle-info-optional.bats │ └── bundle-info-status.bats ├── bundlelist │ ├── list-all.bats │ ├── list-deps-flat.bats │ ├── list-deps-invalid-bundle.bats │ ├── list-deps-nested.bats │ ├── list-experimental.bats │ ├── list-flags.bats │ ├── list-has-dep-nested-not-installed.bats │ ├── list-has-dep-nested-server.bats │ ├── list-has-dep-nested.bats │ ├── list-installed.bats │ ├── list-json.bats │ ├── list-no-deps.bats │ ├── list-none-has-deps.bats │ ├── list-orphans.bats │ └── list-quiet.bats ├── bundleremove │ ├── remove-basics.bats │ ├── remove-boot-file.bats │ ├── remove-flags.bats │ ├── remove-include-nested.bats │ ├── remove-include.bats │ ├── remove-json.bats │ ├── remove-optional-bundles.bats │ ├── remove-orphans.bats │ ├── remove-os-core.bats │ ├── remove-parse-args.bats │ ├── remove-recursive.bats │ └── remove-with-dependency.bats ├── certattributes.cnf ├── check_ids.bash ├── checkupdate │ ├── chk-update-format-bump.bats │ ├── chk-update-json.bats │ ├── chk-update-new-version.bats │ ├── chk-update-no-server-content.bats │ ├── chk-update-no-target-content.bats │ ├── chk-update-slow-server.bats │ └── chk-update-version-match.bats ├── clean │ ├── clean-basic.bats │ ├── clean-grouped-manifests.bats │ └── clean-old-statedir.bats ├── diagnose │ ├── diagnose-also-add.bats │ ├── diagnose-basics.bats │ ├── diagnose-boot-file.bats │ ├── diagnose-bundles.bats │ ├── diagnose-directory-tree-deleted.bats │ ├── diagnose-flags.bats │ ├── diagnose-good.bats │ ├── diagnose-json.bats │ ├── diagnose-missing-file.bats │ ├── diagnose-path.bats │ ├── diagnose-picky-downgrade.bats │ ├── diagnose-picky-whitelist.bats │ └── diagnose-picky.bats ├── hashdump │ └── hashdump-file-hash.bats ├── ignore-list ├── info │ └── info-basic.bats ├── mirror │ ├── mirror-allow-http.bats │ ├── mirror-createdir-negative.bats │ ├── mirror-createdir.bats │ ├── mirror-json.bats │ ├── mirror-set-unset-invalid.bats │ └── mirror-set-unset.bats ├── only_in_ci_slow │ ├── update-non-responsive.bats │ └── update-slow-server.bats ├── only_in_ci_system │ ├── 3rd-party-repo-add-certificate.bats │ ├── add-client-certificate.bats │ ├── add-no-disk-space.bats │ ├── add-no-disk-space.ignore-list │ ├── api-3rd-party-add.bats │ ├── chk-update-client-certificate.bats │ ├── diagnose-client-certificate.bats │ ├── expired-certificate-latest.bats │ ├── expired-certificate-mom.bats │ ├── expired-certificate.bats │ ├── list-client-certificate.bats │ ├── list-no-disk-space.bats │ ├── pemfile │ ├── remove-client-certificate.bats │ ├── remove-no-disk-space.bats │ ├── repair-no-disk-space.bats │ ├── search-client-certificate.bats │ ├── search-no-disk-space.bats │ ├── update-client-certificate.bats │ ├── update-no-disk-space.bats │ └── usa-external-modules.bats ├── os-install │ ├── install-also-add.bats │ ├── install-bad.bats │ ├── install-basics.bats │ ├── install-download.bats │ ├── install-hardlink-symlink.bats │ ├── install-json.bats │ ├── install-latest-missing.bats │ ├── install-multiple.bats │ ├── install-no-also-add.bats │ ├── install-no-fullfile-fallback.bats │ ├── install-no-packs.bats │ ├── install-statedir-cache-offline.bats │ ├── install-statedir-cache.bats │ ├── install-var.bats │ └── install-version.bats ├── repair │ ├── repair-add-missing-include-old.bats │ ├── repair-add-missing-include.bats │ ├── repair-basics.bats │ ├── repair-boot-file-deleted.bats │ ├── repair-boot-file.bats │ ├── repair-boot-file.ignore-list │ ├── repair-boot-skip.bats │ ├── repair-bundles.bats │ ├── repair-deleted-include-manifest.bats │ ├── repair-directory-tree-deleted.bats │ ├── repair-empty-dir-deleted.bats │ ├── repair-error.bats │ ├── repair-flags.bats │ ├── repair-format-mismatch-overdrive.bats │ ├── repair-format-mismatch.bats │ ├── repair-ghosted.bats │ ├── repair-ignore-also-add.bats │ ├── repair-json.bats │ ├── repair-missing-file.bats │ ├── repair-path.bats │ ├── repair-picky-downgrade.bats │ ├── repair-picky-ghosted-missing.bats │ ├── repair-picky-ghosted.bats │ ├── repair-picky.bats │ ├── repair-skip-scripts.bats │ ├── repair-type-changed-system.bats │ ├── repair-unsafe-to-delete.bats │ ├── repair-version-mismatch-overdrive.bats │ └── repair-version-mismatch.bats ├── search │ ├── search-content-check-negative.bats │ ├── search-content-check-positive.bats │ ├── search-experimental.bats │ ├── search-json.bats │ ├── search-sort.bats │ └── search-version.bats ├── server.py ├── signature │ ├── alt-key-rotation.bats │ ├── cert-chain.bats │ ├── corrupted-certificate.bats │ ├── corrupted-signature.bats │ ├── invalid-certificate.bats │ ├── key-rotation.bats │ ├── no-signature.bats │ ├── permission-incorrect.bats │ ├── valid-certificate.bats │ └── version-sig-check.bats ├── testlib.bash ├── update │ ├── update-3rd-party.bats │ ├── update-attr-change.bats │ ├── update-boot-file.bats │ ├── update-boot-file.ignore-list │ ├── update-boot-manager.bats │ ├── update-boot-skip.bats │ ├── update-bundle-removed.bats │ ├── update-deleted-include-manifest.bats │ ├── update-download.bats │ ├── update-fail-to-get-mom.bats │ ├── update-ignore-also-add.bats │ ├── update-include-old-bundle-with-tracked-file.bats │ ├── update-include-old-bundle.bats │ ├── update-include.bats │ ├── update-incremental.bats │ ├── update-json.bats │ ├── update-manifest-delta-recover.bats │ ├── update-manifest-delta.bats │ ├── update-minversion.bats │ ├── update-missing-os-core.bats │ ├── update-newest-added.bats │ ├── update-newest-deleted.bats │ ├── update-newest-ghosted.bats │ ├── update-older-server-version.bats │ ├── update-re-update-bad-os-release.bats │ ├── update-re-update-required.bats │ ├── update-rename-ghosted.bats │ ├── update-rename.bats │ ├── update-search-file-index.bats │ ├── update-show-time.bats │ ├── update-skip-scripts.bats │ ├── update-skip-verified-fullfiles.bats │ ├── update-statedir-bad-hash.bats │ ├── update-status-no-server-content.bats │ ├── update-status-no-target-content.bats │ ├── update-status.bats │ ├── update-to-same-version.bats │ ├── update-type-changes-dir-to-file.bats │ ├── update-type-changes-file-to-recursive-symlink.bats │ ├── update-type-changes-file-to-symlink.bats │ ├── update-type-changes-symlink-to-file.bats │ ├── update-unusual-file-names.bats │ ├── update-use-full-file.bats │ ├── update-use-pack.bats │ ├── update-verify-fix-path-hash-mismatch.bats │ ├── update-verify-fix-path-missing-dir.bats │ ├── update-verify-fullfile-hash.bats │ ├── update-with-mirror-signature.bats │ ├── update-with-mirror.bats │ ├── update-with-old-mirror.bats │ └── update-with-slightly-old-mirror.bats ├── usability │ ├── usa-cachedir-with-symlink.bats │ ├── usa-completion-basic.bats │ ├── usa-config-file.bats │ └── usa-download-retries.bats └── verify-legacy │ ├── verify-bundle.bats │ └── verify-flags.bats ├── installation └── test.bats ├── real_content ├── real_content_lib.bash ├── swupd_repair_fullfiles.bats ├── swupd_update.bats └── swupd_update_jump.bats └── unit ├── data ├── config_noocsp_critical.cnf ├── config_ocsp.cnf ├── config_ocsp_critical.cnf ├── mom1 ├── mom2 ├── mom_invalid1 └── mom_invalid2 ├── test_helper.h ├── test_heuristics.c ├── test_int.c ├── test_list.c ├── test_manifest.c ├── test_signature.c ├── test_strings.c └── test_sys.c /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug_triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Environment (please complete the following information):** 20 | - Clear Linux OS Version: [swupd info] 21 | - Platform: [hardware, docker, vm information ] 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/workflows/shellcheck-all.yml: -------------------------------------------------------------------------------- 1 | name: Shellcheck 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | RUNNING_IN_CI: true 7 | 8 | jobs: 9 | shellcheck-all: 10 | runs-on: ubuntu-latest 11 | timeout-minutes: 120 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: build_dependencies 16 | run: sudo apt-get install bats 17 | 18 | - name: shellcheck-all 19 | run: bats -t test/code_analysis/shellcheck-all.bats 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.kdev4 2 | *.lo 3 | *.o 4 | *.trs 5 | *~ 6 | .*.swp 7 | .cproject 8 | .deps 9 | .dirstamp 10 | .libs/ 11 | .project 12 | DEADJOE 13 | GPATH 14 | GRTAGS 15 | GTAGS 16 | Makefile 17 | Makefile.in 18 | aclocal.m4 19 | ar-lib 20 | autom4te.cache/ 21 | compile 22 | config.* 23 | configure 24 | coverage/ 25 | cscope.* 26 | data/swupd-update.service 27 | docs/*.1 28 | docs/*.4 29 | docs/*.7 30 | docs/swupd-alias.7.rst 31 | depcomp 32 | functional-tests.log 33 | fuzzout/ 34 | install-sh 35 | kw* 36 | libswupd* 37 | libtool 38 | ltmain.sh 39 | m4/*.m4 40 | missing 41 | regression/*.out 42 | src/*.gcda 43 | src/*.gcno 44 | stamp-h1 45 | swupd 46 | swupd-client*tar.gz 47 | tap-driver.sh 48 | test-driver 49 | test-suite.log 50 | test/*.gcno 51 | test/documentation/manpages/test.log 52 | Swupd_Root.pem 53 | private.pem 54 | test/**/*.log 55 | test/unit/test_*.test 56 | /verifytime 57 | unit_tests.log 58 | html/ 59 | xml/ 60 | doc-coverage.info 61 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The swupd-client package provides a reference implementation of a software 2 | update client which performs file level updates of an OS, preferentially 3 | using binary deltas whenever possible for efficiency under an assumption 4 | that the OS develops with a release process aimed at rapidly deploying 5 | small incremental changes. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swupd Client 2 | 3 | ![Shellcheck](https://github.com/clearlinux/swupd-client/workflows/Shellcheck/badge.svg) 4 | ![Swupd tests](https://github.com/clearlinux/swupd-client/workflows/Swupd%20tests/badge.svg) 5 | 6 | swupd is an OS-level software update program that applies updates to a Clear Linux OS. 7 | More information on how to use swupd can be found in the [official documentation](https://clearlinux.org/documentation/clear-linux/guides/maintenance/swupd-guide), [swupd command man page](docs/swupd.1.rst) and other documents on [docs directory](docs/). 8 | 9 | ## Reporting problems 10 | 11 | Use github issue report tool (https://github.com/clearlinux/swupd-client/issues) to report bugs, issues and feature requests. 12 | 13 | To help us to reproduce a bug reported, please attach the swupd command line, the command output, swupd version ('swupd -v' output) and clear linux version ('swupd info' output). 14 | 15 | For other questions, contact us in Clear Linux mailing list (dev@lists.clearlinux.org) or IRC channel ( #clearlinux on Freenode). 16 | 17 | ## How to contribute 18 | 19 | Swupd client is open for contributions, so we are more than willing to review your patches! 20 | For more information take a look on the [how to contribute guide](docs/how_to_contribute.md) 21 | 22 | ## Reporting Security Concerns 23 | 24 | If you have discovered potential security vulnerability in Swupd, please visit https://01.org/security for best practices on reporting security issues and to report your concern. 25 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | autoreconf --force --install --symlink --warnings=all 6 | 7 | # The client certificate tests are skipped by default, but require an 8 | # alternative trust store for the test web server's public key. To enable 9 | # the trust store for the client certificate tests, the SCRIPT_PATH variable 10 | # must be uncommented and the following configuration argument must be added 11 | # to args: 12 | # 13 | # --with-fallback-capaths=$SCRIPT_PATH/swupd_test_certificates 14 | # 15 | #SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 16 | args="\ 17 | --sysconfdir=/etc \ 18 | --localstatedir=/var \ 19 | --prefix=/usr \ 20 | --enable-silent-rules" 21 | 22 | ./configure "$args" "$@" 23 | make clean 24 | -------------------------------------------------------------------------------- /compile_flags.txt: -------------------------------------------------------------------------------- 1 | -Isrc 2 | -Isrc/lib 3 | -Isrc/swupd_lib 4 | 5 | -------------------------------------------------------------------------------- /continous.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This file is part of swupd-client. 4 | # 5 | # Copyright © 2017-2025 Intel Corporation 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, version 2 or later of the License. 10 | # 11 | 12 | DIRN="$(basename $(pwd))" 13 | PROJ_NAME="swupd-client" 14 | PROJ_CI_NAME="docker-ci-${PROJ_NAME}" 15 | 16 | # Check docker is available 17 | if ! type docker &>/dev/null; then 18 | echo "Please ensure docker is installed first" 19 | exit 1 20 | fi 21 | 22 | # Check docker is running 23 | if ! docker version &>/dev/null; then 24 | echo "Docker is not running" 25 | exit 1 26 | fi 27 | 28 | # Check we're in the right directory 29 | if [[ "${DIRN}" != "${PROJ_NAME}" ]]; then 30 | echo "Please run from the root ${PROJ_NAME} directory" 31 | exit 1 32 | fi 33 | 34 | # Check that docker-ci image is installed 35 | if ! docker inspect "${PROJ_CI_NAME}" &>/dev/null; then 36 | echo "${PROJ_CI_NAME} not installed, building docker image.." 37 | echo "....Please wait, this may take some time." 38 | docker build -t "${PROJ_CI_NAME}" docker/ || exit 1 39 | fi 40 | 41 | # Build the current tree through bind mount within the docker image 42 | echo "Beginning build of ${PROJ_NAME}..." 43 | exec docker run -ti -v $(pwd):/source:ro --rm "${PROJ_CI_NAME}" 44 | -------------------------------------------------------------------------------- /data/swupd-update.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Update Software content 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=@prefix@/bin/swupd update --no-progress 7 | ExecStartPost=@prefix@/bin/swupd 3rd-party update --no-progress --assume=no 8 | -------------------------------------------------------------------------------- /data/swupd-update.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Automatically Install Software Updates 3 | Documentation=man:swupd_update 4 | 5 | [Timer] 6 | OnBootSec=45min 7 | OnUnitActiveSec=45min 8 | AccuracySec=300 9 | RandomizedDelaySec=2700 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /data/verifytime.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Check that system time is sane; update to more correct time if needed 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=/usr/bin/verifytime 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of swupd-client. 3 | # 4 | # Copyright © 2017-2025 Intel Corporation 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 2 or later of the License. 9 | # 10 | # 11 | 12 | # Build with the following: 13 | # docker build -t swupd-ci -f docker/Dockerfile . 14 | 15 | FROM clearlinux:latest 16 | RUN swupd bundle-add os-core-update-dev sysadmin-basic os-testsuite c-basic haskell-basic 17 | RUN pip install coverxygen && stack install ShellCheck && mv /root/.local/bin/shellcheck /usr/bin/ 18 | RUN useradd tester && usermod -aG wheelnopw tester 19 | COPY . /build 20 | RUN chown -R tester /build 21 | USER tester 22 | WORKDIR /build 23 | 24 | # Requires docker run with: --cap-add LINUX_IMMUTABLE 25 | CMD ["/build/docker/dockerrun.sh"] 26 | -------------------------------------------------------------------------------- /docs/swupd-update.service.4.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | swupd-update.service 3 | ==================== 4 | 5 | --------------------- 6 | Performs an OS update 7 | --------------------- 8 | 9 | :Copyright: \(C) 2017-2025 Intel Corporation, CC-BY-SA-3.0 10 | :Manual section: 4 11 | 12 | 13 | SYNOPSIS 14 | ======== 15 | 16 | ``swupd-update.service`` 17 | 18 | ``/usr/lib/systemd/system/swupd-update.service`` 19 | 20 | 21 | DESCRIPTION 22 | =========== 23 | 24 | Instructs the ``systemd``\(1) system daemon how to start and control the 25 | ``swupd`` service to perform an update. 26 | 27 | When this unit runs, the output will be sent to the systemd journal, and 28 | it can be inspected with the ``journalctl``\(1) command. 29 | 30 | The user can disable all background updates (either started through 31 | timers or not) by executing the following command: 32 | 33 | ``systemctl mask swupd-update.service`` 34 | 35 | 36 | ENVIRONMENT 37 | =========== 38 | 39 | This unit is a ``systemd``\(1) unit file. 40 | 41 | 42 | SEE ALSO 43 | ======== 44 | 45 | ``swupd``\(1), ``swupd-update.timer``\(4) 46 | 47 | -------------------------------------------------------------------------------- /docs/swupd-update.timer.4.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | swupd-update.timer 3 | ================== 4 | 5 | ---------------------------- 6 | Schedules periodical updates 7 | ---------------------------- 8 | 9 | :Copyright: \(C) 2017-2025 Intel Corporation, CC-BY-SA-3.0 10 | :Manual section: 4 11 | 12 | 13 | SYNOPSIS 14 | ======== 15 | 16 | ``swupd-update.timer`` 17 | 18 | ``/usr/lib/systemd/system/swupd-update.timer`` 19 | 20 | 21 | DESCRIPTION 22 | =========== 23 | 24 | Instructs the ``systemd``\(1) system daemon when to periodically start a 25 | system software update. The update itself may not execute if the 26 | ``swupd-update.service``\(4) is disabled. See that manual page for 27 | information on how to disable that unit. 28 | 29 | 30 | ENVIRONMENT 31 | =========== 32 | 33 | This unit is a ``systemd``\(1) unit file. 34 | 35 | 36 | SEE ALSO 37 | ======== 38 | 39 | ``swupd``\(1), ``swupd-update.service``\(4) 40 | 41 | -------------------------------------------------------------------------------- /docs/update-triggers.target.4.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | update-triggers.target 3 | ====================== 4 | 5 | ---------------------------------------- 6 | Provides post OS software-update actions 7 | ---------------------------------------- 8 | 9 | :Copyright: \(C) 2017-2025 Intel Corporation, CC-BY-SA-3.0 10 | :Manual section: 4 11 | 12 | 13 | SYNOPSIS 14 | ======== 15 | 16 | ``update-triggers.target`` 17 | 18 | ``/usr/lib/systemd/system/update-triggers.target`` 19 | 20 | 21 | DESCRIPTION 22 | =========== 23 | 24 | Instructs the ``systemd``\(1) system daemon what units needed to be 25 | started as part of the software update process. After the main software 26 | update content is applied to the OS, the ``swupd``\(1) program starts 27 | this *systemd* target. 28 | 29 | The main function of this target is to allow optional corrections and 30 | adjustments to be made after installation that can not easily be made 31 | through static file installation methods. This usually applies to things 32 | like cached lists, dynamic configuration files and similar volatile 33 | databases that are regularly altered and may contain user data. 34 | 35 | One example is the dynamic loader cache which needs to be updated when 36 | ever there are modifications to the system installed dynamic libraries. 37 | 38 | The user is not intended to execute these scripts and plugin units 39 | directly. If however so this is desired, one can execute the following 40 | command to re-execute all the actions: 41 | 42 | ``systemctl start update-triggers.target`` 43 | 44 | 45 | ENVIRONMENT 46 | =========== 47 | 48 | This unit is a ``systemd``\(1) target file. 49 | 50 | 51 | SEE ALSO 52 | ======== 53 | 54 | ``swupd``\(1) 55 | 56 | -------------------------------------------------------------------------------- /how-to-make-a-release: -------------------------------------------------------------------------------- 1 | 1) update configure.ac with new version 2 | 2) commit and tag new version with configure.ac changes 3 | 3) make dist && make distcheck 4 | 4) push to mirror, github and upload dist tar 5 | 6 | -------------------------------------------------------------------------------- /scripts/github_actions/build_ci.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Install all dependencies available on ubuntu-latest from github actions to 3 | # build swupd and run all tests. 4 | # Builds swupd with configuration needed to run swupd tests 5 | 6 | set -e 7 | CORES=2 8 | 9 | # Install dependencies from ubuntu 10 | sudo apt-get install python3-docutils 11 | sudo apt-get install check 12 | sudo apt-get install bats 13 | 14 | # Use rst2man from python3 15 | sudo ln -s /usr/bin/rst2man /usr/bin/rst2man.py 16 | 17 | # Build Swupd 18 | autoreconf --verbose --warnings=none --install --force 19 | ./configure CFLAGS="$CFLAGS -fsanitize=address -Werror" --prefix=/usr --with-fallback-capaths="$PWD"/swupd_test_certificates --with-systemdsystemunitdir=/usr/lib/systemd/system --with-config-file-path="$PWD"/testconfig --enable-debug 20 | make -j$CORES 21 | 22 | # Needed to initialize the host for auto-update. Without these steps auto-update 23 | # within a --path would just not work 24 | sudo mkdir -p /usr/lib/systemd/system/ 25 | sudo cp data/swupd-update.service /usr/lib/systemd/system/ 26 | sudo cp data/swupd-update.timer /usr/lib/systemd/system/ 27 | sudo systemctl enable swupd-update.timer 28 | sudo systemctl restart swupd-update.timer 29 | -------------------------------------------------------------------------------- /scripts/github_actions/build_ci_dependencies.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build all custom dependencies needed by swupd: 3 | # - Curl 4 | # - Bsdiff 5 | # - libarchive 6 | # 7 | # As process is slow, it can be cached. If directory dependencies exists, 8 | # just install already build dependencies. 9 | 10 | set -e 11 | CORES=2 12 | 13 | sudo apt install libbz2-dev liblzma-dev 14 | 15 | # If alread exists, reuse 16 | if [ -d dependencies ]; then 17 | pushd dependencies 18 | for i in *; do 19 | if [ -d "$i" ]; then 20 | pushd "$i" 21 | sudo make install 22 | popd 23 | fi 24 | done 25 | 26 | popd 27 | exit 28 | fi 29 | 30 | mkdir dependencies 31 | pushd dependencies 32 | 33 | # build bsdiff 34 | wget https://github.com/clearlinux/bsdiff/releases/download/v1.0.2/bsdiff-1.0.2.tar.xz 35 | tar -xvf bsdiff-1.0.2.tar.xz 36 | pushd bsdiff-1.0.2 && ./configure --prefix=/usr --disable-tests && make -j"$CORES" && sudo make install && popd 37 | 38 | ## build curl 39 | wget https://curl.haxx.se/download/curl-7.64.0.tar.gz 40 | tar -xvf curl-7.64.0.tar.gz 41 | pushd curl-7.64.0 && ./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu && make -j"$CORES" && sudo make install && popd 42 | 43 | # build libarchive 44 | wget https://github.com/libarchive/libarchive/archive/v3.3.1.tar.gz 45 | tar -xvf v3.3.1.tar.gz 46 | pushd libarchive-3.3.1 && autoreconf -fi && ./configure --prefix=/usr && make -j"$CORES" && sudo make install && popd 47 | 48 | popd 49 | -------------------------------------------------------------------------------- /scripts/github_actions/build_ci_style.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Calls build_ci to install dependencies and build swupd. 3 | # Install dependencies needed to run compliance check, documentation check and 4 | # bash shell check 5 | 6 | set -e 7 | ./scripts/github_actions/build_ci.bash 8 | 9 | # Install dependencies from ubuntu 10 | sudo apt-get install shellcheck 11 | sudo apt-get install doxygen 12 | sudo apt-get install clang-format 13 | sudo pip install coverxygen 14 | -------------------------------------------------------------------------------- /scripts/github_actions/filter_bats_list.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Filter a list of jobs 3 | # Parameter 1: Job number 4 | # Parameter 2: Number of jobs 5 | # 6 | # To test if any test is missing: 7 | # for i in $(seq $NUM_JOBS); do 8 | # ./scripts/filter_bats_list.bash $i $NUM_JOBS >> list; 9 | # done 10 | 11 | JOB_NUM=$1 12 | NUM_JOBS=$2 13 | DEFAULT_WEIGHT=6 14 | 15 | TEST_LIST=$(find test/functional/ -name "*.bats" \( ! -path "*only_in_ci*" \) | sort) 16 | 17 | TOTAL_WEIGHT=0 18 | for t in $TEST_LIST; do 19 | WEIGHT=$(sed -n -e 's/^#WEIGHT=//p' "$t") 20 | if [ -z "$WEIGHT" ]; then 21 | WEIGHT="$DEFAULT_WEIGHT" 22 | fi 23 | TOTAL_WEIGHT=$((TOTAL_WEIGHT + WEIGHT)) 24 | done 25 | 26 | NUM_TESTS="$((TOTAL_WEIGHT/(NUM_JOBS)))" 27 | START="$(((JOB_NUM - 1) * NUM_TESTS + 1))" 28 | END="$((JOB_NUM * NUM_TESTS))" 29 | 30 | COUNT=0 31 | for t in $TEST_LIST; do 32 | WEIGHT=$(sed -n -e 's/^#WEIGHT=//p' "$t") 33 | if [ -z "$WEIGHT" ]; then 34 | WEIGHT="$DEFAULT_WEIGHT" 35 | fi 36 | 37 | COUNT=$((COUNT + WEIGHT)) 38 | 39 | if [ "$JOB_NUM" -ne "$NUM_JOBS" ] && [ $COUNT -gt $END ]; then 40 | break 41 | fi 42 | 43 | if [ $COUNT -ge $START ]; then 44 | echo "$t" 45 | fi 46 | 47 | done 48 | -------------------------------------------------------------------------------- /scripts/github_actions/run_check.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | JOB_NUMBER="$1" 5 | NUM_JOBS="$2" 6 | 7 | FILES=$(scripts/github_actions/filter_bats_list.bash "$JOB_NUMBER" "$NUM_JOBS") 8 | NUM_FILES=$(echo "$FILES" | tr ' ' '\n' | wc -l) 9 | echo "Running $NUM_FILES tests" 10 | # shellcheck disable=SC2116 11 | # shellcheck disable=SC2086 12 | # Weird, but we really need this 13 | env TESTS="$(echo $FILES)" make -e -j2 check 14 | 15 | echo "$FILES" > job-"$JOB_NUMBER" 16 | -------------------------------------------------------------------------------- /scripts/github_actions/weight_tests.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | MAX_WEIGHT=40 3 | 4 | if [ -z "$1" ]; then 5 | TESTS=$(find test/functional/ -name "*.bats" \( ! -path "*only_in_ci*" \)) 6 | else 7 | TESTS="$*" 8 | fi 9 | 10 | for t in $TESTS; do 11 | echo "Running $t" 12 | WEIGHT=$(($(/usr/bin/time -f %e "$t" 2>&1 |tail -n 1 |cut -d '.' -f 1)+1)) 13 | echo "$WEIGHT" 14 | if [ $WEIGHT -gt "$MAX_WEIGHT" ]; then 15 | WEIGHT="$MAX_WEIGHT" 16 | fi 17 | 18 | sed -i "/#WEIGHT/d" "$t" 19 | echo "#WEIGHT=$WEIGHT" >> "$t" 20 | done 21 | -------------------------------------------------------------------------------- /scripts/shellcheck.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Wrapper to run shellcheck with configurations used by swupd project and 4 | # doing necessary changes to validate bats files 5 | 6 | # Ignored checks: 7 | # - SC1008: This shebang was unrecognized. 8 | # We need to skip this check when processing bats tests because the shebang 9 | # is not a shell. 10 | # - SC2119: Use foo "$@" if function's $1 should mean script's $1. 11 | # We need to skip this check because in many ocassions we use functions 12 | # that are not expecting arguments, but still shellcheck will detect this 13 | # as error because the show_help which is called from all functions uses $@ 14 | 15 | if [ "$#" -ne 1 ]; then 16 | cat <<-EOM 17 | Invalid number of arguments 18 | 19 | Usage: 20 | ./scripts/shellcheck.bash 21 | EOM 22 | exit 1 23 | fi 24 | 25 | file="$1" 26 | 27 | if [[ "${file/*./}" == "bats" ]]; then 28 | sed 's/^@.*/func() {/' "$file" | 29 | sed 's/^load.*/source test\/functional\/testlib.bash/' | 30 | shellcheck -s bash -x -e SC1008,SC2119,SC2317 /dev/stdin 31 | else 32 | shellcheck -x "$file" -e SC2119 33 | fi 34 | -------------------------------------------------------------------------------- /src/lib/README.md: -------------------------------------------------------------------------------- 1 | Swupd generic library 2 | ===================== 3 | 4 | Library created to group implementation of generic data types, helpers and 5 | system interaction used by swupd, but without any swupd specific code or 6 | swupd.h dependency. 7 | -------------------------------------------------------------------------------- /src/lib/archives.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCHIVES__ 2 | #define __ARCHIVES__ 3 | 4 | /** 5 | * @file 6 | * @brief Tarball extraction functions. 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /** 14 | * @brief Extracts tar archive tarfile to outputdir. 15 | * 16 | * @param tarfile The tarball to be extracted. 17 | * @param outputdir The directory to extract to. 18 | * 19 | * Refuses to extract any object whose final location would be altered by a 20 | * symlink on disk. 21 | */ 22 | int archives_extract_to(const char *tarfile, const char *outputdir); 23 | 24 | /** 25 | * @brief Check if this tarball is valid and if it contains only one file with the 26 | * specified name. 27 | * 28 | * Trailing '/' is ignored for directories on the tarball, so 29 | * don't include that on file. 30 | */ 31 | int archives_check_single_file_tarball(const char *tarfilename, const char *file); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/lib/comp_functions.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Software Updater - client side 3 | * 4 | * Copyright © 2012-2025 Intel Corporation. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, version 2 or later of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | #include 21 | 22 | #include "comp_functions.h" 23 | #include "strings.h" 24 | 25 | /** 26 | * All comparison functions in this file should match this type definition: 27 | * typedef int (*comparison_fn_t)(const void *a, const void *b); 28 | * 29 | * They should behave like this (similar to str_cmp): 30 | * - return 0 if a is equal to b 31 | * - return any number "< 0" if a is lower than b 32 | * - return any number "> 0" if a is bigger than b 33 | */ 34 | 35 | int str_cmp_wrapper(const void *a, const void *b) 36 | { 37 | return str_cmp((const char *)a, (const char *)b); 38 | } 39 | -------------------------------------------------------------------------------- /src/lib/comp_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMP_FUNCTIONS_H 2 | #define __COMP_FUNCTIONS_H 3 | 4 | /** 5 | * @file 6 | * @brief Compare like functions. 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /** 14 | * Definition of a funtion type to compare two elements 15 | */ 16 | typedef int (*comparison_fn_t)(const void *a, const void *b); 17 | 18 | /** 19 | * @brief str_cmp wrapper casting void * to char *. 20 | */ 21 | int str_cmp_wrapper(const void *a, const void *b); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /src/lib/formatter_json.h: -------------------------------------------------------------------------------- 1 | #ifndef __FORMATTER_JSON__ 2 | #define __FORMATTER_JSON__ 3 | 4 | /** 5 | * @file 6 | * @brief Format the output to print using JSON format. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * @brief Generates the initial message of a JSON stream 18 | */ 19 | void json_start(const char *); 20 | 21 | /** 22 | * @brief Generates the final message of a JSON stream 23 | */ 24 | void json_end(const char *, int); 25 | 26 | /** 27 | * @brief Log message using Json format 28 | */ 29 | void log_json(FILE *out, const char *file, int line, const char *label, const char *format, va_list args_list); 30 | 31 | /** 32 | * @brief Prints the progress of a given step into the JSON stream 33 | */ 34 | void json_progress(const char *, int, int, int); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /src/lib/thread_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef __THREAD_POOL__ 2 | #define __THREAD_POOL__ 3 | 4 | /** 5 | * @file 6 | * @brief Really simple and small thread pool implementation for swupd. 7 | */ 8 | 9 | #include 10 | 11 | /** @brief Internal information about the thread pool. */ 12 | struct tp; 13 | 14 | /** 15 | * Thread task function type definition. 16 | */ 17 | typedef void (*tp_task_run_t)(void *data); 18 | 19 | /** 20 | * Create a new thread pool. 21 | * 22 | * @param num_threads The number of threads to be created. 23 | * 24 | * @note Free thread pool data with tp_free() 25 | */ 26 | struct tp *tp_start(int num_threads); 27 | 28 | /** 29 | * @brief Schedule a task to be run in this thread pool. 30 | * 31 | * @param tp The thread pool 32 | * @param run Callback to be executed in a new thread. 33 | * @param data Data informed to callback. 34 | */ 35 | int tp_task_schedule(struct tp *tp, tp_task_run_t run, void *data); 36 | 37 | /** 38 | * @brief Wait for all scheduled tasks to be completed, finishes all threads and 39 | * release all memory used by the thread pool. 40 | */ 41 | void tp_complete(struct tp *tp); 42 | 43 | /** 44 | * @brief Get the number of threads created by this thread pool. 45 | */ 46 | int tp_get_num_threads(struct tp *tp); 47 | 48 | // TODO: Implement a tp_wait() function 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/lib/timelist.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIME_H__ 2 | #define __TIME_H__ 3 | 4 | /** 5 | * @file 6 | * @brief Measure time functions take to execute. 7 | */ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * @brief A timelist object 17 | */ 18 | typedef TAILQ_HEAD(timelist, time) timelist; 19 | 20 | /** 21 | * @brief Create a new timelist that should be freed with timelist_free() 22 | */ 23 | timelist *timelist_new(void); 24 | 25 | /** 26 | * @brief Start recording time of a task and append that information in the timelist. 27 | * 28 | * Time recording should be stopped using timelist_timer_stop(). 29 | */ 30 | void timelist_timer_start(timelist *list, const char *name); 31 | 32 | /** 33 | * @brief Stop recording time for last running task in timelist 34 | */ 35 | void timelist_timer_stop(timelist *list); 36 | 37 | /** 38 | * @brief Print time statistics recorded using timelist_timer_start and timelist_timer_stop 39 | */ 40 | void timelist_print_stats(timelist *list); 41 | 42 | /** 43 | * @brief Free timelist and all data from the list 44 | */ 45 | void timelist_free(timelist *head); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/swupd_build_variant.h: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_GUARD_SWUPD_BUILD_VARIANT_H 2 | #define __INCLUDE_GUARD_SWUPD_BUILD_VARIANT_H 3 | 4 | #include 5 | #include 6 | 7 | #include "lib/list.h" 8 | #include "swupd.h" 9 | 10 | #ifdef SWUPD_WITH_BSDTAR 11 | 12 | /* bsdtar always includes xattrs, without needing special parameters 13 | * for it. This has been tested in Ostro OS in combination with IMA 14 | * and Smack, but not with SELinux. 15 | */ 16 | #define TAR_COMMAND "/usr/bin/bsdtar" 17 | 18 | #else /* SWUPD_WITH_BSDTAR */ 19 | 20 | /* GNU tar requires special options, depending on how the OS uses xattrs. 21 | * This has been tested in Clear Linux OS in combination with SELinux. 22 | */ 23 | #define TAR_COMMAND "/usr/bin/tar" 24 | 25 | #ifdef SWUPD_WITH_XATTRS 26 | 27 | #ifdef SWUPD_TAR_SELINUX 28 | #define TAR_XATTR_ARGS "--xattrs --xattrs-include='*' --selinux" 29 | #else /* SWUPD_TAR_SELINUX */ 30 | #define TAR_XATTR_ARGS "--xattrs --xattrs-include='*'" 31 | #endif /* SWUPD_TAR_SELINUX */ 32 | 33 | #endif /* SWUPD_WITH_XATTRS */ 34 | 35 | #endif /* SWUPD_WITH_BSDTAR */ 36 | 37 | #define TAR_PERM_ATTR_ARGS "--preserve-permissions" 38 | 39 | #endif /* __INCLUDE_GUARD_SWUPD_BUILD_VARIANT_H */ 40 | -------------------------------------------------------------------------------- /src/swupd_lib/alias.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALIAS__ 2 | #define __ALIAS__ 3 | 4 | /** 5 | * @file 6 | * @brief Bundle alias functions. 7 | */ 8 | 9 | #include "lib/list.h" 10 | 11 | /** 12 | * @brief Deep free on alias_lookup structs 13 | */ 14 | void free_alias_lookup(void *lookup); 15 | 16 | /** 17 | * @brief Get bundles for a given alias but if the alias is 18 | * not actually an alias, return a list with just the 19 | * bundle name 20 | */ 21 | struct list *get_alias_bundles(struct list *alias_definitions, char *alias); 22 | 23 | /** 24 | * @brief Parse an alias definition file for a list of bundles 25 | * it specifies 26 | * 27 | * Example file: 28 | * alias1 b1 b2 29 | * alias2 b3 b4 30 | * 31 | * If two files provide the same alias, the first one that 32 | * is parsed is the one that will be used. 33 | */ 34 | struct list *get_alias_definitions(void); 35 | 36 | #endif /* __ALIAS__ */ 37 | -------------------------------------------------------------------------------- /src/swupd_lib/config_loader.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_LOADER__ 2 | #define __CONFIG_LOADER__ 3 | 4 | /** 5 | * @file 6 | * @brief Load options from a configuration file 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | 15 | /** 16 | * @brief Type of function that sets options for a section based on parsed values 17 | */ 18 | typedef bool (*parse_opt_fn_t)(int opt, char *optarg); 19 | 20 | /** 21 | * @brief Data structed used by config_loader_set_opt() 22 | */ 23 | struct config_loader_data { 24 | /** @brief Swupd subcommand being executed */ 25 | char *command; 26 | /** @brief Array with available opts. */ 27 | const struct option *available_opts; 28 | /** @brief Function to parse global options */ 29 | parse_opt_fn_t parse_global_opt; 30 | /** @brief Function to parse subcommand specific options */ 31 | parse_opt_fn_t parse_command_opt; 32 | }; 33 | 34 | /** 35 | * Process parser config file and call apropriate function in struct config_loader_data 36 | * informed on data 37 | */ 38 | bool config_loader_set_opt(char *section, char *key, char *value, void *data); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /src/swupd_lib/heuristics.h: -------------------------------------------------------------------------------- 1 | #ifndef __HEURISTICS__ 2 | #define __HEURISTICS__ 3 | 4 | /** 5 | * @file 6 | * @brief Heuristics system to define which scripts to run and which files to 7 | * ignore on installation time. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "swupd.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /** 20 | * @brief Use heuristics to define which files should be updated and which 21 | * scripts should be executed. 22 | * 23 | * Use the path and properties of the file to define it's type and by that 24 | * define if the file should be set with a do_not_update flag or is_boot flag. 25 | * Also use that information to check if the bootloader or systemd update 26 | * scripts should be executed. 27 | * 28 | * @param files The list of struct file objects where swupd heuristics will be 29 | * applied. 30 | */ 31 | void heuristics_apply(struct list *files); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/swupd_lib/scripts.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCRIPTS__ 2 | #define __SCRIPTS__ 3 | 4 | /** 5 | * @file 6 | * @brief Scripts execution functions. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * @brief Run post-update scripts. 18 | * 19 | * @param block If true wait for the script to finish before returning. 20 | */ 21 | void scripts_run_post_update(bool block); 22 | 23 | /** 24 | * @brief Run pre-update scripts. 25 | * 26 | * @param manifests MoM that includes the pre-update script to be run. 27 | * 28 | * Pre update scripts are executed only if they are found and if the hash 29 | * matches. In the case of failures, update will continue. 30 | */ 31 | void scripts_run_pre_update(struct manifest *manifest); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/swupd_lib/stats.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Software Updater - client side 3 | * 4 | * Copyright © 2012-2025 Intel Corporation. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, version 2 or later of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Authors: 19 | * Arjan van de Ven 20 | * 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "swupd.h" 29 | 30 | int swupd_stats[8]; 31 | 32 | void print_statistics(int version1, int version2) 33 | { 34 | info("\n"); 35 | info("Statistics for going from version %i to version %i:\n\n", version1, version2); 36 | info(" changed bundles : %i\n", swupd_stats[5]); 37 | info(" new bundles : %i\n", swupd_stats[3]); 38 | info(" deleted bundles : %i\n\n", swupd_stats[4]); 39 | info(" changed files : %i\n", swupd_stats[2]); 40 | info(" new files : %i\n", swupd_stats[0]); 41 | info(" deleted files : %i\n", swupd_stats[1]); 42 | info("\n"); 43 | } 44 | -------------------------------------------------------------------------------- /src/swupd_lib/swupd_progress.h: -------------------------------------------------------------------------------- 1 | #ifndef __SWUPD_PROGRESS__ 2 | #define __SWUPD_PROGRESS__ 3 | 4 | /** 5 | * @file 6 | * @brief Progress callback functions used by fullfile and packs. 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include "swupd.h" 14 | 15 | /** 16 | * @brief struct to hold information about the overall download progress (including many files). 17 | */ 18 | struct download_progress { 19 | /** @brief total number of bytes to download. */ 20 | uint64_t total_download_size; 21 | /** @brief total of bytes downloaded so far. */ 22 | long downloaded; 23 | }; 24 | 25 | /** @brief struct to hold information about one file download progress. */ 26 | struct file_progress { 27 | /** @brief file size. */ 28 | long file_size; 29 | /** @brief downloaded. */ 30 | long downloaded; 31 | /** @brief pointer to a struct holding information about the overall progress. */ 32 | struct download_progress *overall_progress; 33 | }; 34 | 35 | /** 36 | * @brief Callback function called periodically by CURL to report how many bytes 37 | * it has downloaded. 38 | */ 39 | int swupd_progress_callback(void *clientp, int64_t dltotal, int64_t dlnow, int64_t UNUSED_PARAM ultotal, int64_t UNUSED_PARAM ulnow); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /src/swupd_lib/target_root.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_ROOT__ 2 | #define __SYSTEM_ROOT__ 3 | 4 | /** 5 | * @file 6 | * @brief Module that handles installation and removal of files from system root 7 | */ 8 | 9 | #include "lib/list.h" 10 | #include "swupd.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * @brief Install files from 'files' into the system. 18 | * 19 | * @param files The list of files to be installed. 20 | * @param mom MoM to be used to create missing directories 21 | */ 22 | enum swupd_code target_root_install_files(struct list *files, struct manifest *mom); 23 | 24 | /** 25 | * @brief Install a single file into the system. 26 | * 27 | * @param file The file to be installed 28 | * @param mom MoM to be used to create missing directories 29 | */ 30 | enum swupd_code target_root_install_single_file(struct file *file, struct manifest *mom); 31 | 32 | /** 33 | * @brief Remove from the system all files in list. 34 | * 35 | * @param The files to be removed 36 | */ 37 | int target_root_remove_files(struct list *files); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/swupd_lib/telemetry.h: -------------------------------------------------------------------------------- 1 | #ifndef __TELEMETRY__ 2 | #define __TELEMETRY__ 3 | 4 | /** 5 | * @file 6 | * @brief Module to handle telemetry report entries 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /** 14 | * Severity of a telemetry record 15 | */ 16 | enum telemetry_severity { 17 | /** @brief Temetry severity Low */ 18 | TELEMETRY_LOW = 1, 19 | /** @brief Temetry severity Medium */ 20 | TELEMETRY_MED = 2, 21 | /** @brief Temetry severity High */ 22 | TELEMETRY_HIGH = 3, 23 | /** @brief Temetry severity Critical */ 24 | TELEMETRY_CRIT = 4, 25 | }; 26 | 27 | /** 28 | * @brief Disables telemetry reports. 29 | */ 30 | void telemetry_disable(void); 31 | 32 | /** 33 | * @brief Create a telemetry record to be reported if telemetrics is enabled. 34 | */ 35 | void telemetry(enum telemetry_severity level, const char *class, const char *fmt, ...); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/verifytime/verifytime.h: -------------------------------------------------------------------------------- 1 | #ifndef __VERIFYTIME__ 2 | #define __VERIFYTIME__ 3 | 4 | /** 5 | * @file 6 | * @brief Verify and correct sytem time if incorrect. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * @brief Verify system time and correct if needed. 18 | * 19 | * @param path_prefix The path where the system is installed. 20 | * @param system_time To be set with the current time 21 | * @param clear_time To be set with the timestamp of the clear release 22 | * 23 | * Function uses timestamp in system path to check if the current system time 24 | * diverged. If so, update current system time with timestamp. If timestamp is 25 | * not found in path_prefix, file is also looked on '/'. 26 | * 27 | * @return 0 if the time is correct, -ENOENT if the timestamp in the system is 28 | * not available and -ETIME if time is out of sync. 29 | */ 30 | int verify_time(char *path_prefix, time_t *system_time, time_t *clear_time); 31 | 32 | /** 33 | * @brief Helper Convert time_t to a human readable string. 34 | */ 35 | char *time_to_string(time_t t); 36 | 37 | /** 38 | * @brief Set system time to mtime 39 | */ 40 | bool set_time(time_t mtime); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/verifytime/verifytime_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Software Updater - client side 3 | * 4 | * Copyright © 2017-2025 Intel Corporation. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, version 2 or later of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | #include "verifytime.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | int main() 26 | { 27 | time_t clear_time = 0, system_time = 0; 28 | int err; 29 | char *system_time_str; 30 | char *clear_time_str; 31 | 32 | err = verify_time(NULL, &system_time, &clear_time); 33 | if (err == 0) { 34 | return 0; // Success 35 | } 36 | 37 | if (err == -ENOENT) { 38 | fprintf(stderr, "Failed to read system timestamp file\n"); 39 | return 1; // Error 40 | } 41 | 42 | system_time_str = time_to_string(system_time); 43 | clear_time_str = time_to_string(clear_time); 44 | if (system_time_str && clear_time_str) { 45 | printf("Fixing outdated system time from '%s' to '%s'\n", system_time_str, clear_time_str); 46 | } 47 | free(system_time_str); 48 | free(clear_time_str); 49 | 50 | if (set_time(clear_time)) { 51 | return 0; // Success 52 | } 53 | 54 | fprintf(stderr, "Failed to update system time\n"); 55 | return 1; // Error 56 | } 57 | -------------------------------------------------------------------------------- /test/code_analysis/check_api_changes.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | @test "ANL005: swupd --quiet output has not changed" { 7 | 8 | run git diff --name-only --exit-code origin/master HEAD test/functional/api/ 9 | 10 | # shellcheck disable=SC2154 11 | # SC2154: var is referenced but not assigned 12 | if [ "$status" -ne 0 ]; then 13 | echo "The following --quiet tests changed:" 14 | echo "$output" 15 | return 1 16 | fi 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/code_analysis/compliant.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | check_sort_makefile() 7 | { 8 | start_str="$1" 9 | export LC_COLLATE=en_US.UTF-8 10 | START=$(grep "$start_str" Makefile.am --line-number -m 1| cut -f1 -d:) 11 | START=$((START + 1)) 12 | END=$(tail +"$START" Makefile.am | grep -e '^$' --line-number -m 1 | cut -f1 -d:) 13 | END=$((END - 1)) 14 | tail -n +$START Makefile.am | head -n $END | sort -c 15 | } 16 | 17 | @test "ANL003: Compliant code style check" { 18 | run git diff --quiet --exit-code src 19 | # shellcheck disable=SC2154 20 | # output and status variable is being assigned and exported by bats 21 | if [ "$status" -ne 0 ]; then 22 | echo "Error: can only check code style when src/ is clean." 23 | echo "Stash or commit your changes and try again." 24 | return "$status" 25 | fi 26 | 27 | run git grep if\ \(.*\)$ -- '*.c' 28 | if [ "$status" -eq 0 ]; then 29 | echo "Missing brackets in single line if:" 30 | # shellcheck disable=SC2154 31 | # output and status variable is being assigned and exported by bats 32 | echo "$output" 33 | return 1 34 | fi 35 | 36 | run grep -r '[[:blank:]]$' test/ src/ -l --include \*.bats --include \*.c --include \*.h 37 | if [ "$status" -eq 0 ]; then 38 | echo "Trailing whitespaces in files:" 39 | echo "$output" 40 | return 1 41 | fi 42 | 43 | check_sort_makefile swupd_SOURCES 44 | check_sort_makefile "TESTS =" 45 | } 46 | -------------------------------------------------------------------------------- /test/code_analysis/shellcheck-all.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | @test "ANL002: Shellcheck on all files" { 7 | local error=0 8 | status=0 9 | output="" 10 | TESTS=$(find . -regex ".*\\.bats\\|.*\\.bash" | sort) 11 | for i in $TESTS; do 12 | echo checking "$i" >&3 13 | 14 | run "$BATS_TEST_DIRNAME"/../../scripts/shellcheck.bash "$i" 15 | echo "Result: $status" >&3 16 | if [ ! "$status" -eq "0" ]; then 17 | echo "$output" >&3 18 | error=1 19 | fi 20 | echo >&3 21 | 22 | done 23 | 24 | [ "$error" -eq "0" ] 25 | } 26 | -------------------------------------------------------------------------------- /test/code_analysis/shellcheck.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | @test "ANL001: Shellcheck on changed files" { 7 | for i in $(git diff --name-only origin/master HEAD | grep -E "\.bats|\.bash"); do 8 | echo checking "$i" >&3 9 | 10 | "$BATS_TEST_DIRNAME"/../../scripts/shellcheck.bash "$i" 11 | done 12 | } 13 | -------------------------------------------------------------------------------- /test/functional/3rd-party/3rd-party-info.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | create_third_party_repo -a "$TEST_NAME" 10 1 repo1 13 | create_bundle -n test-bundle1 -f /foo/file_1 -u repo1 "$TEST_NAME" 14 | URL1=$ABS_TP_URL 15 | 16 | create_third_party_repo -a "$TEST_NAME" 20 5 repo2 17 | create_bundle -n test-bundle2 -f /foo/file_2 -u repo2 "$TEST_NAME" 18 | URL2=$ABS_TP_URL 19 | 20 | } 21 | 22 | @test "TPR076: Check 3rd-party info verbose" { 23 | 24 | run sudo sh -c "$SWUPD 3rd-party info $SWUPD_OPTS --verbose" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | _____________________________ 29 | 3rd-Party Repository: repo1 30 | _____________________________ 31 | Distribution: Swupd Test Distro 32 | Installed version: 10 (format 1) 33 | Version URL: file://$URL1 34 | Content URL: file://$URL1 35 | _____________________________ 36 | 3rd-Party Repository: repo2 37 | _____________________________ 38 | Distribution: Swupd Test Distro 39 | Installed version: 20 (format 5) 40 | Version URL: file://$URL2 41 | Content URL: file://$URL2 42 | EOM 43 | ) 44 | assert_is_output "$expected_output" 45 | 46 | } 47 | 48 | @test "TPR077: Check 3rd-party info basic for a specific repo" { 49 | 50 | run sudo sh -c "$SWUPD 3rd-party info $SWUPD_OPTS --repo repo2" 51 | 52 | assert_status_is "$SWUPD_OK" 53 | expected_output=$(cat <<-EOM 54 | Distribution: Swupd Test Distro 55 | Installed version: 20 56 | Version URL: file://$URL2 57 | Content URL: file://$URL2 58 | EOM 59 | ) 60 | assert_is_output "$expected_output" 61 | 62 | } 63 | #WEIGHT=12 64 | -------------------------------------------------------------------------------- /test/functional/3rd-party/3rd-party-repo-list.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Karthik Prabhu Vinod 4 | # Email: karthik.prabhu.vinod@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup(){ 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | contents=$(cat <<- EOM 13 | [test1] 14 | url=https://www.abc.com 15 | 16 | [test2] 17 | url=https://www.efg.com 18 | 19 | [test4] 20 | url=https://www.pqr.com 21 | 22 | [test5] 23 | url=ERROR 24 | 25 | [test5] 26 | url=https://www.lmn.com 27 | \n 28 | EOM 29 | ) 30 | 31 | repo_config_file="$ABS_TARGET_DIR"/"$TP_ROOT_DIR"/repo.ini 32 | run sudo sh -c "mkdir -p $STATE_DIR/3rd-party/" 33 | run sudo sh -c "mkdir -p $ABS_TARGET_DIR/$TP_BUNDLES_DIR/{test1,test2,test3,test4,test5}" 34 | write_to_protected_file -a "$repo_config_file" "$contents" 35 | 36 | } 37 | 38 | @test "TPR007: Basic List of third-party entire repositories" { 39 | 40 | run sudo sh -c "$SWUPD 3rd-party list $SWUPD_OPTS" 41 | assert_status_is "$SWUPD_OK" 42 | expected_output=$(cat <<-EOM 43 | Swupd 3rd-party repositories: 44 | - test1: https://www.abc.com 45 | - test2: https://www.efg.com 46 | - test4: https://www.pqr.com 47 | - test5: https://www.lmn.com 48 | 49 | Total: 4 50 | EOM 51 | ) 52 | assert_is_output --identical "$expected_output" 53 | 54 | } 55 | #WEIGHT=1 56 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-add.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_third_party_repo "$TEST_NAME" 10 staging repo1 12 | export repo1="$ABS_TP_URL" 13 | 14 | } 15 | 16 | @test "API071: 3rd-party add --certpath CERTIFICATE" { 17 | 18 | run sudo sh -c "$SWUPD 3rd-party add $SWUPD_OPTS my-repo file://$repo1 --quiet" 19 | 20 | assert_status_is "$SWUPD_OK" 21 | assert_output_is_empty 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-bundle-add.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_third_party_repo -a "$TEST_NAME" 10 1 repo1 12 | create_bundle -n test-bundle1 -f /file_1 -u repo1 "$TEST_NAME" 13 | create_bundle -n test-bundle2 -f /file_2a -u repo1 "$TEST_NAME" 14 | create_third_party_repo -a "$TEST_NAME" 10 1 repo2 15 | create_bundle -n test-bundle2 -f /file_2b -u repo2 "$TEST_NAME" 16 | 17 | } 18 | 19 | @test "API021: 3rd-party bundle-add" { 20 | 21 | run sudo sh -c "$SWUPD 3rd-party bundle-add test-bundle1 $SWUPD_OPTS --quiet" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | assert_output_is_empty 25 | 26 | } 27 | 28 | @test "API022: 3rd-party bundle-add with --repo" { 29 | 30 | run sudo sh -c "$SWUPD 3rd-party bundle-add test-bundle1 $SWUPD_OPTS --repo repo1 --quiet" 31 | 32 | assert_status_is "$SWUPD_OK" 33 | assert_output_is_empty 34 | 35 | } 36 | #WEIGHT=14 37 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-bundle-remove.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_third_party_repo -a "$TEST_NAME" 10 1 repo1 12 | create_third_party_repo -a "$TEST_NAME" 10 1 repo2 13 | create_bundle -L -t -n test-bundle1 -f /file_1 -u repo1 "$TEST_NAME" 14 | create_bundle -L -n test-bundle2 -f /file_2 -u repo1 "$TEST_NAME" 15 | 16 | } 17 | 18 | @test "API018: 3rd-party bundle-remove" { 19 | 20 | run sudo sh -c "$SWUPD 3rd-party bundle-remove test-bundle1 $SWUPD_OPTS --quiet" 21 | 22 | assert_status_is "$SWUPD_OK" 23 | assert_output_is_empty 24 | 25 | } 26 | 27 | @test "API019: 3rd-party bundle-remove with --repo" { 28 | 29 | run sudo sh -c "$SWUPD 3rd-party bundle-remove test-bundle1 $SWUPD_OPTS --repo repo1 --quiet" 30 | 31 | assert_status_is "$SWUPD_OK" 32 | assert_output_is_empty 33 | 34 | } 35 | 36 | @test "API081: 3rd-party bundle-remove --orphans" { 37 | 38 | run sudo sh -c "$SWUPD 3rd-party bundle-remove $SWUPD_OPTS --orphans --quiet" 39 | 40 | assert_status_is "$SWUPD_OK" 41 | expected_output=$(cat <<-EOM 42 | [repo1] 43 | [repo2] 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | 48 | } 49 | 50 | @test "API082: 3rd-party bundle-remove --orphans --repo REPOSITORY" { 51 | 52 | run sudo sh -c "$SWUPD 3rd-party bundle-remove $SWUPD_OPTS --orphans --repo repo1 --quiet" 53 | 54 | assert_status_is "$SWUPD_OK" 55 | assert_output_is_empty 56 | 57 | } 58 | 59 | #WEIGHT=10 60 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-checkupdate.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | create_third_party_repo -a "$TEST_NAME" 10 staging repo1 13 | create_bundle -L -t -n test-bundle1 -f /foo/file_1 -u repo1 "$TEST_NAME" 14 | create_version -p "$TEST_NAME" 20 10 staging repo1 15 | update_bundle "$TEST_NAME" test-bundle1 --update /foo/file_1 repo1 16 | 17 | create_third_party_repo -a "$TEST_NAME" 10 staging repo2 18 | create_bundle -L -t -n test-bundle2 -f /bar/file_2 -u repo2 "$TEST_NAME" 19 | 20 | } 21 | 22 | @test "API009: 3rd-party checkupdate" { 23 | 24 | run sudo sh -c "$SWUPD 3rd-party check-update $SWUPD_OPTS --quiet" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | [repo1] 29 | 20 30 | [repo2] 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | 37 | @test "API010: 3rd-party checkupdate (update available) with --repo" { 38 | 39 | run sudo sh -c "$SWUPD 3rd-party check-update $SWUPD_OPTS --repo repo1 --quiet" 40 | 41 | assert_status_is "$SWUPD_OK" 42 | expected_output=$(cat <<-EOM 43 | 20 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | 48 | } 49 | 50 | @test "API011: 3rd-party checkupdate (up to date) with --repo" { 51 | 52 | run sudo sh -c "$SWUPD 3rd-party check-update $SWUPD_OPTS --repo repo2 --quiet" 53 | 54 | assert_status_is "$SWUPD_NO" 55 | assert_output_is_empty 56 | 57 | } 58 | #WEIGHT=21 59 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-info.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | create_third_party_repo -a "$TEST_NAME" 60 1 repo1 13 | create_third_party_repo -a "$TEST_NAME" 20 5 repo2 14 | 15 | } 16 | 17 | @test "API002: 3rd-party info" { 18 | 19 | run sudo sh -c "$SWUPD 3rd-party info $SWUPD_OPTS --quiet" 20 | 21 | assert_status_is "$SWUPD_OK" 22 | expected_output=$(cat <<-EOM 23 | [repo1] 24 | 60 25 | [repo2] 26 | 20 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | 33 | @test "API003: 3rd-party info with --repo" { 34 | 35 | run sudo sh -c "$SWUPD 3rd-party info $SWUPD_OPTS --quiet --repo repo1" 36 | 37 | assert_status_is "$SWUPD_OK" 38 | expected_output=$(cat <<-EOM 39 | 60 40 | EOM 41 | ) 42 | assert_is_output "$expected_output" 43 | 44 | } 45 | #WEIGHT=9 46 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-list.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_third_party_repo -a "$TEST_NAME" 10 1 repo1 12 | export repo1="$ABS_TP_URL" 13 | create_third_party_repo -a "$TEST_NAME" 10 1 repo2 14 | export repo2="$ABS_TP_URL" 15 | 16 | } 17 | 18 | @test "API073: 3rd-party list" { 19 | 20 | run sudo sh -c "$SWUPD 3rd-party list $SWUPD_OPTS --quiet" 21 | 22 | assert_status_is "$SWUPD_OK" 23 | expected_output=$(cat <<-EOM 24 | repo1: file://$repo1 25 | repo2: file://$repo2 26 | EOM 27 | ) 28 | assert_is_output "$expected_output" 29 | 30 | } 31 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-remove.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_third_party_repo -a "$TEST_NAME" 10 1 repo1 12 | 13 | } 14 | 15 | @test "API072: 3rd-party remove" { 16 | 17 | run sudo sh -c "$SWUPD 3rd-party remove $SWUPD_OPTS repo1 --quiet" 18 | 19 | assert_status_is "$SWUPD_OK" 20 | assert_output_is_empty 21 | 22 | } 23 | -------------------------------------------------------------------------------- /test/functional/api/api-3rd-party-update.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 11 | create_third_party_repo -a "$TEST_NAME" 10 staging repo1 12 | create_third_party_repo -a "$TEST_NAME" 10 staging repo2 13 | create_bundle -L -t -n test-bundle1 -f /foo/file_1 -u repo1 "$TEST_NAME" 14 | create_bundle -L -t -n test-bundle2 -f /bar/file_2 -u repo2 "$TEST_NAME" 15 | create_version "$TEST_NAME" 20 10 staging repo1 16 | update_bundle "$TEST_NAME" test-bundle1 --update /foo/file_1 repo1 17 | 18 | } 19 | 20 | @test "API014: 3rd-party update" { 21 | 22 | run sudo sh -c "$SWUPD 3rd-party update $SWUPD_OPTS --quiet" 23 | 24 | assert_status_is "$SWUPD_OK" 25 | expected_output=$(cat <<-EOM 26 | [repo1] 27 | [repo2] 28 | EOM 29 | ) 30 | assert_is_output "$expected_output" 31 | 32 | } 33 | 34 | @test "API015: 3rd-party update with --repo" { 35 | 36 | run sudo sh -c "$SWUPD 3rd-party update $SWUPD_OPTS --repo repo1 --quiet" 37 | 38 | assert_status_is "$SWUPD_OK" 39 | assert_output_is_empty 40 | 41 | } 42 | 43 | @test "API016: 3rd-party update with --repo (no update available)" { 44 | 45 | run sudo sh -c "$SWUPD 3rd-party update $SWUPD_OPTS --repo repo2 --quiet" 46 | 47 | assert_status_is "$SWUPD_OK" 48 | assert_output_is_empty 49 | 50 | } 51 | #WEIGHT=24 52 | -------------------------------------------------------------------------------- /test/functional/api/api-autoupdate.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | sudo mkdir -p "$ABS_TARGET_DIR"/etc/systemd/system 12 | 13 | } 14 | 15 | @test "API004: autoupdate" { 16 | 17 | run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --quiet" 18 | 19 | assert_status_in "$SWUPD_NO" "$SWUPD_SUBPROCESS_ERROR" 20 | assert_output_is_empty 21 | 22 | } 23 | 24 | @test "API005: autoupdate --enable" { 25 | 26 | # create mask files manually 27 | sudo ln -s /dev/null "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.service 28 | sudo ln -s /dev/null "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.timer 29 | 30 | run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --enable --quiet" 31 | 32 | assert_status_is "$SWUPD_OK" 33 | assert_output_is_empty 34 | # check mask files don't exist 35 | assert_file_not_exists "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.service 36 | assert_file_not_exists "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.timer 37 | 38 | } 39 | 40 | @test "API006: autoupdate --disable" { 41 | 42 | run sudo sh -c "$SWUPD autoupdate $SWUPD_OPTS --disable --quiet" 43 | 44 | if [ "$(systemd-detect-virt)" = "docker" ] ; then 45 | assert_status_is "$SWUPD_SUBPROCESS_ERROR" 46 | else 47 | assert_status_is "$SWUPD_OK" 48 | fi 49 | assert_output_is_empty 50 | # check mask files don't exist 51 | assert_symlink_exists "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.service 52 | assert_symlink_exists "$ABS_TARGET_DIR"/etc/systemd/system/swupd-update.timer 53 | 54 | } 55 | 56 | #WEIGHT=3 57 | -------------------------------------------------------------------------------- /test/functional/api/api-bundle-add.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle1 -f /foo/file_1 "$TEST_NAME" 12 | 13 | } 14 | 15 | @test "API020: bundle-add" { 16 | 17 | run sudo sh -c "$SWUPD bundle-add test-bundle1 $SWUPD_OPTS --quiet" 18 | 19 | assert_status_is "$SWUPD_OK" 20 | assert_output_is_empty 21 | 22 | } 23 | #WEIGHT=2 24 | -------------------------------------------------------------------------------- /test/functional/api/api-bundle-remove.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -t -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_bundle -L -n test-bundle2 -f /file_2 "$TEST_NAME" 13 | 14 | } 15 | 16 | @test "API017: bundle-remove" { 17 | 18 | run sudo sh -c "$SWUPD bundle-remove test-bundle1 $SWUPD_OPTS --quiet" 19 | 20 | assert_status_is "$SWUPD_OK" 21 | assert_output_is_empty 22 | 23 | } 24 | 25 | @test "API080: bundle-remove --orphans" { 26 | 27 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS --orphans --quiet" 28 | 29 | assert_status_is "$SWUPD_OK" 30 | assert_output_is_empty 31 | 32 | } 33 | 34 | #WEIGHT=2 35 | -------------------------------------------------------------------------------- /test/functional/api/api-checkupdate.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_version "$TEST_NAME" 20 12 | 13 | } 14 | 15 | @test "API007: checkupdate (update available)" { 16 | 17 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS --quiet" 18 | 19 | assert_status_is "$SWUPD_OK" 20 | expected_output=$(cat <<-EOM 21 | 20 22 | EOM 23 | ) 24 | assert_is_output "$expected_output" 25 | 26 | } 27 | 28 | @test "API008: checkupdate (up to date)" { 29 | 30 | # set current version to 20 so there are no updates available 31 | set_current_version "$TEST_NAME" 20 32 | 33 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS --quiet" 34 | 35 | assert_status_is "$SWUPD_NO" 36 | assert_output_is_empty 37 | 38 | } 39 | #WEIGHT=3 40 | -------------------------------------------------------------------------------- /test/functional/api/api-clean.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | sudo mkdir "$ABS_MANIFEST_DIR"/10 12 | sudo touch "$ABS_MANIFEST_DIR"/10/Manifest.test{1..3} 13 | sudo touch "$ABS_CACHE_DIR"/pack-test{1..2}-from-0.tar 14 | 15 | } 16 | 17 | @test "API063: clean" { 18 | 19 | run sudo sh -c "$SWUPD clean $SWUPD_OPTS --quiet" 20 | 21 | assert_status_is "$SWUPD_OK" 22 | assert_output_is_empty 23 | 24 | } 25 | 26 | @test "API064: clean --dry-run" { 27 | 28 | run sudo sh -c "$SWUPD clean $SWUPD_OPTS --dry-run --quiet" 29 | 30 | assert_status_is "$SWUPD_OK" 31 | expected_output=$(cat <<-EOM 32 | $ABS_CACHE_DIR/pack-test.-from-0.tar 33 | $ABS_CACHE_DIR/pack-test.-from-0.tar 34 | $ABS_DELTA_DIR 35 | $ABS_DOWNLOAD_DIR 36 | $ABS_STAGED_DIR 37 | $ABS_TEMP_DIR 38 | $ABS_MANIFEST_DIR/10/Manifest.test. 39 | $ABS_MANIFEST_DIR/10/Manifest.test. 40 | $ABS_MANIFEST_DIR/10/Manifest.test. 41 | EOM 42 | ) 43 | assert_regex_is_output "$expected_output" 44 | 45 | } 46 | #WEIGHT=2 47 | -------------------------------------------------------------------------------- /test/functional/api/api-diagnose.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment -r "$TEST_NAME" 10 1 11 | add_os_core_update_bundle "$TEST_NAME" 12 | create_bundle -L -n test-bundle1 -f /foo/file_1,/bar/file_2 "$TEST_NAME" 13 | create_version "$TEST_NAME" 20 10 1 14 | update_bundle -p "$TEST_NAME" test-bundle1 --update /foo/file_1 15 | update_bundle -p "$TEST_NAME" test-bundle1 --delete /bar/file_2 16 | update_bundle "$TEST_NAME" test-bundle1 --add /baz/file_3 17 | 18 | } 19 | 20 | teardown_file() { 21 | 22 | destroy_test_environment --force "$TEST_NAME" 23 | 24 | } 25 | 26 | @test "API053: diagnose (no issues found)" { 27 | 28 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS --picky --quiet" 29 | 30 | assert_status_is "$SWUPD_OK" 31 | assert_output_is_empty 32 | 33 | } 34 | 35 | @test "API054: diagnose (issues found)" { 36 | 37 | # set the current version of the target system as if it is already 38 | # at version 20 so diagnose find issues 39 | set_current_version "$TEST_NAME" 20 40 | # adding an untracked file into /usr 41 | sudo touch "$TARGET_DIR"/usr/untracked_file3 42 | 43 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS --picky --quiet" 44 | 45 | assert_status_is "$SWUPD_NO" 46 | expected_output=$(cat <<-EOM 47 | $ABS_TARGET_DIR/baz 48 | $ABS_TARGET_DIR/baz/file_3 49 | $ABS_TARGET_DIR/foo/file_1 50 | $ABS_TARGET_DIR/usr/lib/os-release 51 | $ABS_TARGET_DIR/bar/file_2 52 | $ABS_TARGET_DIR/usr/untracked_file3 53 | EOM 54 | ) 55 | assert_is_output "$expected_output" 56 | 57 | } 58 | #WEIGHT=6 59 | -------------------------------------------------------------------------------- /test/functional/api/api-hashdump.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | } 13 | 14 | teardown_file() { 15 | 16 | destroy_test_environment --force "$TEST_NAME" 17 | 18 | } 19 | 20 | @test "API068: hashdump" { 21 | 22 | run sudo sh -c "$SWUPD hashdump $TARGET_DIR/etc/swupd --quiet" 23 | 24 | assert_status_is "$SWUPD_OK" 25 | expected_output=$(cat <<-EOM 26 | 6c27df6efcd6fc401ff1bc67c970b83eef115f6473db4fb9d57e5de317eba96e 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | #WEIGHT=1 33 | -------------------------------------------------------------------------------- /test/functional/api/api-info.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 30123 20 11 | 12 | } 13 | 14 | @test "API001: info" { 15 | 16 | run sudo sh -c "$SWUPD info $SWUPD_OPTS --quiet" 17 | 18 | assert_status_is "$SWUPD_OK" 19 | expected_output=$(cat <<-EOM 20 | 30123 21 | EOM 22 | ) 23 | assert_is_output "$expected_output" 24 | 25 | } 26 | #WEIGHT=1 27 | -------------------------------------------------------------------------------- /test/functional/api/api-mirror.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | } 13 | 14 | teardown_file() { 15 | 16 | destroy_test_environment --force "$TEST_NAME" 17 | 18 | } 19 | 20 | @test "API074: mirror (same URL)" { 21 | 22 | run sudo sh -c "$SWUPD mirror $SWUPD_OPTS --quiet" 23 | 24 | assert_status_is "$SWUPD_OK" 25 | expected_output=$(cat <<-EOM 26 | file://$ABS_TEST_DIR/web-dir 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | 33 | @test "API075: mirror (different URL)" { 34 | 35 | set_content_url "$TEST_NAME" https://some.url 36 | 37 | run sudo sh -c "$SWUPD mirror $SWUPD_OPTS --quiet" 38 | 39 | assert_status_is "$SWUPD_OK" 40 | expected_output=$(cat <<-EOM 41 | file://$ABS_TEST_DIR/web-dir 42 | https://some.url 43 | EOM 44 | ) 45 | assert_is_output "$expected_output" 46 | 47 | } 48 | 49 | @test "API076: mirror --set URL" { 50 | 51 | run sudo sh -c "$SWUPD mirror $SWUPD_OPTS --set https://some.url --quiet" 52 | 53 | assert_status_is "$SWUPD_OK" 54 | assert_output_is_empty 55 | 56 | } 57 | 58 | @test "API059: mirror --unset" { 59 | 60 | run sudo sh -c "$SWUPD mirror $SWUPD_OPTS --unset --quiet" 61 | 62 | assert_status_is "$SWUPD_OK" 63 | assert_output_is_empty 64 | 65 | } 66 | -------------------------------------------------------------------------------- /test/functional/api/api-os-install.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -f /core "$TEST_NAME" 12 | 13 | } 14 | 15 | teardown_file() { 16 | 17 | destroy_test_environment --force "$TEST_NAME" 18 | 19 | } 20 | 21 | @test "API062: os-install" { 22 | 23 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS_NO_PATH $TARGET_DIR --quiet" 24 | 25 | assert_status_is "$SWUPD_OK" 26 | assert_output_is_empty 27 | 28 | } 29 | #WEIGHT=1 30 | -------------------------------------------------------------------------------- /test/functional/api/api-repair.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 10 1 11 | add_os_core_update_bundle "$TEST_NAME" 12 | create_bundle -L -n test-bundle1 -f /foo/file_1,/bar/file_2 "$TEST_NAME" 13 | create_version "$TEST_NAME" 20 10 1 14 | update_bundle -p "$TEST_NAME" test-bundle1 --update /foo/file_1 15 | update_bundle -p "$TEST_NAME" test-bundle1 --delete /bar/file_2 16 | update_bundle "$TEST_NAME" test-bundle1 --add /baz/bat/file_3 17 | 18 | } 19 | 20 | test_teardown() { 21 | 22 | # return the files to mutable state 23 | if [ -e "$TARGET_DIR"/usr/untracked_file ]; then 24 | sudo chattr -i "$TARGET_DIR"/usr/untracked_file 25 | fi 26 | if [ -e "$TARGET_DIR"/baz ]; then 27 | sudo chattr -i "$TARGET_DIR"/baz 28 | fi 29 | 30 | } 31 | 32 | @test "API057: repair (nothing to repair)" { 33 | 34 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --picky --quiet" 35 | 36 | assert_status_is "$SWUPD_OK" 37 | assert_output_is_empty 38 | 39 | } 40 | 41 | @test "API058: repair" { 42 | 43 | # add things to be repaired 44 | set_current_version "$TEST_NAME" 20 45 | sudo touch "$TARGET_DIR"/usr/untracked_file 46 | 47 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --picky --quiet" 48 | 49 | assert_status_is "$SWUPD_OK" 50 | expected_output=$(cat <<-EOM 51 | $ABS_TARGET_DIR/baz -> fixed 52 | $ABS_TARGET_DIR/baz/bat -> fixed 53 | $ABS_TARGET_DIR/baz/bat/file_3 -> fixed 54 | $ABS_TARGET_DIR/foo/file_1 -> fixed 55 | $ABS_TARGET_DIR/usr/lib/os-release -> fixed 56 | $ABS_TARGET_DIR/bar/file_2 -> deleted 57 | $ABS_TARGET_DIR/usr/untracked_file -> deleted 58 | EOM 59 | ) 60 | assert_is_output --identical "$expected_output" 61 | 62 | } 63 | #WEIGHT=17 64 | -------------------------------------------------------------------------------- /test/functional/api/api-search-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle1 -f /common,/foo/file1,/foo/file3,/usr/bin/test-bin,/usr/lib/test-lib32 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /common,/bar/file2,/bar/file3,/usr/lib64/test-lib64 "$TEST_NAME" 13 | 14 | } 15 | 16 | teardown_file() { 17 | 18 | destroy_test_environment --force "$TEST_NAME" 19 | 20 | } 21 | 22 | @test "API050: search-file BUNDLE" { 23 | 24 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS test-bundle1 --quiet" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | [test-bundle1] 29 | /usr/share/clear/bundles/test-bundle1 30 | EOM 31 | ) 32 | assert_is_output "$expected_output" 33 | 34 | } 35 | 36 | @test "API051: search-file FILE" { 37 | 38 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS common --quiet" 39 | 40 | assert_status_is "$SWUPD_OK" 41 | expected_output=$(cat <<-EOM 42 | [test-bundle1] 43 | /common 44 | [test-bundle2] 45 | /common 46 | EOM 47 | ) 48 | assert_is_output "$expected_output" 49 | 50 | } 51 | 52 | @test "API052: search-file FILE --library --binary" { 53 | 54 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS test- --library --binary --quiet" 55 | 56 | assert_status_is "$SWUPD_OK" 57 | expected_output=$(cat <<-EOM 58 | [test-bundle1] 59 | /usr/lib/test-lib32 60 | /usr/bin/test-bin 61 | [test-bundle2] 62 | /usr/lib64/test-lib64 63 | EOM 64 | ) 65 | assert_is_output "$expected_output" 66 | 67 | } 68 | #WEIGHT=4 69 | -------------------------------------------------------------------------------- /test/functional/api/api-update.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -t -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_version "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" test-bundle1 --update /file_1 14 | 15 | } 16 | 17 | @test "API012: Update" { 18 | 19 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --quiet" 20 | 21 | assert_status_is "$SWUPD_OK" 22 | assert_output_is_empty 23 | 24 | } 25 | 26 | @test "API013: Update (no update available)" { 27 | 28 | # set current version to 20 so there are no updates available 29 | set_current_version "$TEST_NAME" 20 30 | 31 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --quiet" 32 | 33 | assert_status_is "$SWUPD_OK" 34 | assert_output_is_empty 35 | 36 | } 37 | #WEIGHT=5 38 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-bad-hash-state.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -f /usr/bin/test-file "$TEST_NAME" 9 | # set up state directory with bad hash file and pack hint 10 | file_hash=$(get_hash_from_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle /usr/bin/test-file) 11 | sudo sh -c "echo \"test file MODIFIED\" > $ABS_STAGED_DIR/$file_hash" 12 | sudo touch "$ABS_CACHE_DIR"/pack-test-bundle-from-0-to-10.tar 13 | 14 | } 15 | 16 | @test "ADD017: Try adding a bundle with a bad hash in the state directory" { 17 | 18 | # since one of the files needed to install the bundle is already in the state/staged 19 | # directory, in theory this one should be used instead of downloading it again... 20 | # however since the hash of this file is wrong it should be deleted and re-downloaded 21 | hash_before=$(sudo "$SWUPD" hashdump "$ABS_STAGED_DIR"/"$file_hash") 22 | 23 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 24 | 25 | assert_status_is 0 26 | hash_after=$(sudo "$SWUPD" hashdump "$ABS_STAGED_DIR"/"$file_hash") 27 | assert_file_exists "$TARGET_DIR"/usr/bin/test-file 28 | assert_not_equal "$hash_before" "$hash_after" 29 | expected_output=$(cat <<-EOM 30 | Loading required manifests... 31 | No packs need to be downloaded 32 | Validate downloaded files 33 | Starting download of remaining update content. This may take a while... 34 | Installing files... 35 | Calling post-update helper scripts 36 | Successfully installed 1 bundle 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | 41 | } 42 | #WEIGHT=2 43 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-bad-hash.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -f /usr/bin/file1 "$TEST_NAME" 9 | # modify the hash from the file with an incorrect one and re-create the file's tar 10 | manifest="$TEST_NAME"/web-dir/10/Manifest.test-bundle 11 | real_hash=$(get_hash_from_manifest "$manifest" "/usr/bin/file1") 12 | bad_hash="e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3" 13 | sudo mv "$TEST_NAME"/web-dir/10/files/"$real_hash" "$TEST_NAME"/web-dir/10/files/"$bad_hash" 14 | sudo rm "$TEST_NAME"/web-dir/10/files/"$real_hash".tar 15 | create_tar "$TEST_NAME"/web-dir/10/files/"$bad_hash" 16 | # also modify it in the bundle manifest and re-create the manifest's tar 17 | update_manifest "$manifest" file-hash "$real_hash" "$bad_hash" 18 | 19 | } 20 | 21 | @test "ADD015: Try adding a bundle containing a file with different hash from what is listed in manifest" { 22 | 23 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 24 | 25 | # downloaded fullfile had a bad hash - immediately fatal with a 1 return code 26 | assert_status_is 1 27 | # the bad hash file should not exist on the system 28 | assert_file_not_exists "$TARGET_DIR"/usr/bin/file1 29 | expected_output=$(cat <<-EOM 30 | Loading required manifests... 31 | No packs need to be downloaded 32 | Validate downloaded files 33 | Starting download of remaining update content. This may take a while... 34 | Error: File content hash mismatch for $ABS_STAGED_DIR/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 (bad server data?) 35 | EOM 36 | ) 37 | assert_is_output "$expected_output" 38 | 39 | } 40 | #WEIGHT=2 41 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-bad-manifest.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -f /usr/bin/test-file "$TEST_NAME" 9 | # Modify the filecount of the bundle manifest (and its tar) to be wrong 10 | manifest="$TEST_NAME"/web-dir/10/Manifest.test-bundle 11 | sudo sed -i "s/filecount:.*/filecount:\\t9000000/" "$manifest" 12 | sudo rm "$TEST_NAME"/web-dir/10/Manifest.test-bundle.tar 13 | create_tar "$TEST_NAME"/web-dir/10/Manifest.test-bundle 14 | 15 | create_tar "$TEST_NAME"/web-dir/10/Manifest.test-bundle 16 | update_hashes_in_mom "$TEST_NAME"/web-dir/10/Manifest.MoM 17 | 18 | } 19 | 20 | @test "ADD016: Try adding a bundle with invalid number of files in manifest" { 21 | 22 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 23 | assert_status_is_not 0 24 | expected_output=$(cat <<-EOM 25 | Loading required manifests... 26 | Error: Preposterous (9000000) number of files in test-bundle Manifest, more than 4 million skipping 27 | Warning: Removing corrupt Manifest.test-bundle artifacts and re-downloading... 28 | Error: Preposterous (9000000) number of files in test-bundle Manifest, more than 4 million skipping 29 | Error: Failed to load 10 test-bundle manifest 30 | Failed to install 1 of 1 bundles 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | #WEIGHT=2 37 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-boot-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # create a bundle with a boot file (in /usr/lib/kernel) 9 | create_bundle -n test-bundle -f /usr/lib/kernel/test-file "$TEST_NAME" 10 | 11 | } 12 | 13 | @test "ADD014: Adding a bundle containing a boot file" { 14 | 15 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 16 | 17 | assert_status_is 0 18 | assert_file_exists "$TARGET_DIR/usr/lib/kernel/test-file" 19 | expected_output=$(cat <<-EOM 20 | Loading required manifests... 21 | No packs need to be downloaded 22 | Validate downloaded files 23 | Starting download of remaining update content. This may take a while... 24 | Installing files... 25 | Calling post-update helper scripts 26 | Successfully installed 1 bundle 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | #WEIGHT=2 33 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-boot-skip.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # create a bundle with a boot file (in /usr/lib/kernel) 9 | create_bundle -n test-bundle -f /usr/lib/kernel/test-file "$TEST_NAME" 10 | 11 | } 12 | 13 | @test "ADD028: Adding a bundle containing a boot file without updating the boot files" { 14 | 15 | run sudo sh -c "$SWUPD bundle-add -b $SWUPD_OPTS test-bundle" 16 | 17 | assert_status_is 0 18 | assert_file_exists "$TARGET_DIR/usr/lib/kernel/test-file" 19 | expected_output=$(cat <<-EOM 20 | Loading required manifests... 21 | No packs need to be downloaded 22 | Validate downloaded files 23 | Starting download of remaining update content. This may take a while... 24 | Installing files... 25 | Calling post-update helper scripts 26 | Warning: boot files update skipped due to --no-boot-update argument 27 | Successfully installed 1 bundle 28 | EOM 29 | ) 30 | assert_is_output "$expected_output" 31 | 32 | } 33 | #WEIGHT=2 34 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-directory.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -d /usr/bin/test "$TEST_NAME" 9 | 10 | } 11 | 12 | @test "ADD012: Adding a bundle containing a directory" { 13 | 14 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 15 | 16 | assert_status_is 0 17 | assert_dir_exists "$TARGET_DIR"/usr/bin/test 18 | expected_output=$(cat <<-EOM 19 | Loading required manifests... 20 | No packs need to be downloaded 21 | Validate downloaded files 22 | Starting download of remaining update content. This may take a while... 23 | Installing files... 24 | Calling post-update helper scripts 25 | Successfully installed 1 bundle 26 | EOM 27 | ) 28 | assert_is_output "$expected_output" 29 | 30 | } 31 | #WEIGHT=2 32 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-experimental.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -e -n test-bundle1 -f /file_1,/foo/file_2 "$TEST_NAME" 12 | 13 | } 14 | 15 | @test "ADD032: Add an experimental bundle" { 16 | 17 | # Experimental bundles are added normally but the user gets warned about it 18 | 19 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" 20 | 21 | assert_status_is 0 22 | expected_output=$(cat <<-EOM 23 | Loading required manifests... 24 | Warning: Bundle test-bundle1 is experimental 25 | No packs need to be downloaded 26 | Validate downloaded files 27 | Starting download of remaining update content. This may take a while... 28 | Installing files... 29 | Calling post-update helper scripts 30 | Successfully installed 1 bundle 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | #WEIGHT=2 37 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-install-time.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n bundle1 -f /file1,/file2 "$TEST_NAME" 9 | 10 | } 11 | 12 | @test "ADD030: Add a bundle showing detailed installation time" { 13 | 14 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS bundle1 -t" 15 | 16 | assert_status_is 0 17 | 18 | expected_output=$(cat <<-EOM 19 | Loading required manifests... 20 | Starting download of remaining update content. This may take a while... 21 | Installing bundle\\(s\\) files... 22 | Calling post-update helper scripts 23 | Successfully installed 1 bundle 24 | Raw elapsed time stats: 25 | .* ms: Total execution time 26 | .* ms: |-- Prepend bundles to list 27 | .* ms: |-- Install bundles 28 | .* ms: |-- Add bundles and recurse 29 | .* ms: |-- Consolidate files from bundles 30 | .* ms: |-- Check disk space availability 31 | .* ms: |-- Download packs 32 | .* ms: |-- Download missing files 33 | .* ms: |-- Installing bundle\\(s\\) files onto filesystem 34 | .* ms: |-- Run Scripts 35 | CPU process time stats: 36 | .* ms: Total execution time 37 | .* ms: |-- Prepend bundles to list 38 | .* ms: |-- Install bundles 39 | .* ms: |-- Add bundles and recurse 40 | .* ms: |-- Consolidate files from bundles 41 | .* ms: |-- Check disk space availability 42 | .* ms: |-- Download packs 43 | .* ms: |-- Download missing files 44 | .* ms: |-- Installing bundle\\(s\\) files onto filesystem 45 | .* ms: |-- Run Scripts 46 | EOM 47 | ) 48 | 49 | assert_regex_is_output "$expected_output" 50 | 51 | } 52 | #WEIGHT=2 53 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-multiple.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | test_files=/usr/bin/1,/usr/bin/2,/usr/bin/3,/usr/bin/4,/usr/bin/5,/usr/bin/6,/usr/bin/7,/usr/bin/8,/usr/bin/9,/usr/bin/10 9 | create_bundle -n test-bundle1 -f "$test_files" "$TEST_NAME" 10 | create_bundle -n test-bundle2 -f /media/lib/file2 "$TEST_NAME" 11 | 12 | } 13 | 14 | @test "ADD020: Adding multiple bundles using packs" { 15 | 16 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1 test-bundle2" 17 | 18 | assert_status_is 0 19 | assert_dir_exists "$TARGET_DIR/usr/bin" 20 | assert_dir_exists "$TARGET_DIR/media/lib" 21 | assert_file_exists "$TARGET_DIR/usr/bin/10" 22 | assert_file_exists "$TARGET_DIR/media/lib/file2" 23 | expected_output=$(cat <<-EOM 24 | Loading required manifests... 25 | No packs need to be downloaded 26 | Validate downloaded files 27 | Starting download of remaining update content. This may take a while... 28 | Installing files... 29 | Calling post-update helper scripts 30 | Successfully installed 2 bundles 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | #WEIGHT=4 37 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-no-signature.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -f /test-file "$TEST_NAME" 9 | sudo rm "$WEB_DIR"/10/Manifest.MoM.sig 10 | 11 | } 12 | 13 | @test "ADD026: Try adding a bundle without a MoM signature" { 14 | 15 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 16 | 17 | assert_status_is "$SWUPD_COULDNT_LOAD_MOM" 18 | expected_output=$(cat <<-EOM 19 | Warning: Removing corrupt Manifest.MoM artifacts and re-downloading... 20 | Error: Signature verification failed for manifest version 10 21 | Error: Cannot load official manifest MoM for version 10 22 | Failed to install 1 of 1 bundles 23 | EOM 24 | ) 25 | assert_is_output "$expected_output" 26 | assert_file_not_exists "$TARGET_DIR"/test-file 27 | 28 | } 29 | 30 | @test "ADD027: Force adding a bundle without a MoM signature" { 31 | 32 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS --nosigcheck test-bundle" 33 | 34 | assert_status_is 0 35 | expected_output=$(cat <<-EOM 36 | Warning: The --nosigcheck flag was used and this compromises the system security 37 | Warning: THE SIGNATURE OF file://$ABS_TEST_DIR/web-dir/10/Manifest.MoM WILL NOT BE VERIFIED 38 | Loading required manifests... 39 | No packs need to be downloaded 40 | Validate downloaded files 41 | Starting download of remaining update content. This may take a while... 42 | Installing files... 43 | Calling post-update helper scripts 44 | Successfully installed 1 bundle 45 | EOM 46 | ) 47 | assert_in_output "$expected_output" 48 | assert_file_exists "$TARGET_DIR"/test-file 49 | 50 | } 51 | #WEIGHT=4 52 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-skip-scripts.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # create a bundle with a boot file (in /usr/lib/kernel) 9 | create_bundle -n test-bundle -f /usr/lib/kernel/test-file "$TEST_NAME" 10 | 11 | } 12 | 13 | @test "ADD029: Adding a bundle without running the post-update scripts" { 14 | 15 | run sudo sh -c "$SWUPD bundle-add --no-scripts $SWUPD_OPTS test-bundle" 16 | assert_status_is 0 17 | assert_file_exists "$TARGET_DIR/usr/lib/kernel/test-file" 18 | expected_output=$(cat <<-EOM 19 | Loading required manifests... 20 | No packs need to be downloaded 21 | Validate downloaded files 22 | Starting download of remaining update content. This may take a while... 23 | Installing files... 24 | Warning: post-update helper scripts skipped due to --no-scripts argument 25 | Successfully installed 1 bundle 26 | EOM 27 | ) 28 | assert_is_output "$expected_output" 29 | 30 | } 31 | #WEIGHT=2 32 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-uses-fullfile.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | 10 | } 11 | 12 | @test "ADD018: When adding a bundle with less than 10 files, fullfiles should be used" { 13 | 14 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" 15 | 16 | assert_status_is 0 17 | # validate file is installed in target 18 | assert_file_exists "$TARGET_DIR"/foo 19 | # validate zero pack was not downloaded 20 | assert_file_not_exists "$STATE_DIR"/pack-test-bundle1-from-0-to-10.tar 21 | expected_output=$(cat <<-EOM 22 | Loading required manifests... 23 | No packs need to be downloaded 24 | Validate downloaded files 25 | Starting download of remaining update content. This may take a while... 26 | Installing files... 27 | Calling post-update helper scripts 28 | Successfully installed 1 bundle 29 | EOM 30 | ) 31 | assert_is_output "$expected_output" 32 | 33 | } 34 | #WEIGHT=2 35 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-uses-zeropack.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | test_files=/file1,/file2,/file3,/file4,/file5,/file6,/file7,/file8,/file9,/file10,/file11 9 | create_bundle -n test-bundle1 -f "$test_files" "$TEST_NAME" 10 | 11 | } 12 | 13 | @test "ADD019: When adding a bundle with more than 10 files, zero packs should be used" { 14 | 15 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" 16 | 17 | assert_status_is 0 18 | # validate files are installed in target 19 | assert_file_exists "$TARGET_DIR"/file1 20 | assert_file_exists "$TARGET_DIR"/file2 21 | assert_file_exists "$TARGET_DIR"/file3 22 | assert_file_exists "$TARGET_DIR"/file4 23 | assert_file_exists "$TARGET_DIR"/file5 24 | assert_file_exists "$TARGET_DIR"/file6 25 | assert_file_exists "$TARGET_DIR"/file7 26 | assert_file_exists "$TARGET_DIR"/file8 27 | assert_file_exists "$TARGET_DIR"/file9 28 | assert_file_exists "$TARGET_DIR"/file10 29 | assert_file_exists "$TARGET_DIR"/file11 30 | # validate zero pack was downloaded 31 | assert_file_exists "$ABS_CACHE_DIR"/pack-test-bundle1-from-0-to-10.tar 32 | expected_output=$(cat <<-EOM 33 | Loading required manifests... 34 | Downloading packs for: 35 | - test-bundle1 36 | Finishing packs extraction... 37 | Validate downloaded files 38 | No extra files need to be downloaded 39 | Installing files... 40 | Calling post-update helper scripts 41 | Successfully installed 1 bundle 42 | EOM 43 | ) 44 | assert_is_output "$expected_output" 45 | 46 | } 47 | #WEIGHT=3 48 | -------------------------------------------------------------------------------- /test/functional/bundleadd/add-verify-fix-path.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo/bar/test-file1 "$TEST_NAME" 9 | create_bundle -L -n test-bundle2 -d /foo,/foo/bar "$TEST_NAME" 10 | # bundles created with the testlib add all needed directories to the 11 | # manifest by default, so we need to remove the directory from test-bundle1 12 | # so its missing the path to the file. 13 | remove_from_manifest "$WEB_DIR"/10/Manifest.test-bundle1 /foo 14 | remove_from_manifest "$WEB_DIR"/10/Manifest.test-bundle1 /foo/bar 15 | # since test-bundle2 is already installed, both directories defined 16 | # there already exist, so we need to delete one of the /foo/bar so it 17 | # can be fixed using verify_fix_path 18 | sudo rm -rf "$TARGET_DIR"/foo/bar 19 | 20 | } 21 | 22 | @test "ADD022: When adding a bundle and a path is missing on the fs, bundle-add fixes it" { 23 | 24 | assert_dir_not_exists "$TARGET_DIR"/foo/bar 25 | 26 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1" 27 | 28 | assert_status_is "$SWUPD_OK" 29 | expected_output=$(cat <<-EOM 30 | Loading required manifests... 31 | No packs need to be downloaded 32 | Validate downloaded files 33 | Starting download of remaining update content. This may take a while... 34 | Installing files... 35 | Calling post-update helper scripts 36 | Successfully installed 1 bundle 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | assert_file_exists "$TARGET_DIR"/foo/bar/test-file1 41 | 42 | } 43 | #WEIGHT=3 44 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-all.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /bar "$TEST_NAME" 10 | create_bundle -L -n test-bundle3 -f /baz "$TEST_NAME" 11 | create_bundle -L -t -n test-bundle4 -f /bat "$TEST_NAME" 12 | 13 | } 14 | 15 | teardown_file() { 16 | 17 | destroy_test_environment --force "$TEST_NAME" 18 | 19 | } 20 | 21 | @test "LST002: List all available bundles" { 22 | 23 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --all" 24 | 25 | assert_status_is 0 26 | expected_output=$(cat <<-EOM 27 | All available bundles: 28 | - os-core 29 | - test-bundle1 30 | - test-bundle2 31 | - test-bundle3 32 | - test-bundle4 33 | 34 | Total: 5 35 | EOM 36 | ) 37 | assert_is_output --identical "$expected_output" 38 | 39 | } 40 | 41 | @test "LST026: List all available bundles and their installation status" { 42 | 43 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --all --status" 44 | 45 | assert_status_is 0 46 | expected_output=$(cat <<-EOM 47 | All available bundles: 48 | - os-core (installed) 49 | - test-bundle1 50 | - test-bundle2 51 | - test-bundle3 (installed) 52 | - test-bundle4 (explicitly installed) 53 | 54 | Total: 5 55 | EOM 56 | ) 57 | assert_is_output --identical "$expected_output" 58 | 59 | } 60 | #WEIGHT=8 61 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-deps-flat.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /foo "$TEST_NAME" 10 | create_bundle -n test-bundle3 -f /foo "$TEST_NAME" 11 | # add bundle2 and 3 as dependencies of bundle1 12 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2 13 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle3 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST006: List bundle's dependencies when bundle has flat dependencies" { 24 | 25 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --deps test-bundle1" 26 | 27 | assert_status_is 0 28 | expected_output=$(cat <<-EOM 29 | Loading required manifests... 30 | 31 | Bundles included by test-bundle1: 32 | - os-core 33 | - test-bundle2 34 | - test-bundle3 35 | 36 | Total: 3 37 | EOM 38 | ) 39 | assert_is_output --identical "$expected_output" 40 | 41 | } 42 | #WEIGHT=4 43 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-deps-invalid-bundle.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | 9 | } 10 | 11 | teardown_file() { 12 | 13 | destroy_test_environment --force "$TEST_NAME" 14 | 15 | } 16 | 17 | @test "LST009: Try listing bundle's dependencies when bundle does not exist" { 18 | 19 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --deps not-a-bundle" 20 | 21 | assert_status_is "$SWUPD_INVALID_BUNDLE" 22 | expected_output=$(cat <<-EOM 23 | Loading required manifests... 24 | Warning: Bundle "not-a-bundle" is invalid, skipping it... 25 | EOM 26 | ) 27 | assert_is_output "$expected_output" 28 | 29 | } 30 | #WEIGHT=1 31 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-deps-nested.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /foo "$TEST_NAME" 10 | create_bundle -n test-bundle3 -f /foo "$TEST_NAME" 11 | # add bundle2 as dependencies of bundle1 and bundle 3 as dependency of bundle2 12 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2 13 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle3 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST007: List bundle's dependencies when bundle has nested dependencies" { 24 | 25 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --deps test-bundle1" 26 | 27 | assert_status_is "$SWUPD_OK" 28 | expected_output=$(cat <<-EOM 29 | Loading required manifests... 30 | 31 | Bundles included by test-bundle1: 32 | - os-core 33 | - test-bundle2 34 | - test-bundle3 35 | 36 | Total: 3 37 | EOM 38 | ) 39 | assert_is_output --identical "$expected_output" 40 | 41 | } 42 | 43 | @test "LST023: List bundle's dependencies (with nested deps) in a tree view" { 44 | 45 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --deps test-bundle1 --verbose" 46 | 47 | assert_status_is "$SWUPD_OK" 48 | expected_output=$(cat <<-EOM 49 | Loading required manifests... 50 | 51 | Bundles included by test-bundle1: 52 | * test-bundle1 53 | |-- os-core 54 | |-- test-bundle2 55 | |-- os-core 56 | |-- test-bundle3 57 | |-- os-core 58 | 59 | Total: 3 60 | EOM 61 | ) 62 | assert_is_output --identical "$expected_output" 63 | 64 | } 65 | #WEIGHT=7 66 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-flags.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | @test "LST029: List conflicting flags" { 9 | 10 | # Some flags are mutually exclusive 11 | 12 | # --orphans & --all 13 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --orphans --all" 14 | assert_status_is "$SWUPD_INVALID_OPTION" 15 | assert_in_output "Error: --orphans and --all options are mutually exclusive" 16 | 17 | # --orphans & --has-dep 18 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --orphans --has-dep os-core" 19 | assert_status_is "$SWUPD_INVALID_OPTION" 20 | assert_in_output "Error: --orphans and --has-dep options are mutually exclusive" 21 | 22 | # --orphans & --deps 23 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --orphans --deps 0s-core" 24 | assert_status_is "$SWUPD_INVALID_OPTION" 25 | assert_in_output "Error: --orphans and --deps options are mutually exclusive" 26 | 27 | } 28 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-has-dep-nested-not-installed.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /foo "$TEST_NAME" 10 | create_bundle -n test-bundle3 -f /foo "$TEST_NAME" 11 | # add bundle1 as dependencies of bundle2 and bundle 2 as dependency of bundle3 12 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 13 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST013: Try listing bundles that have a given bundle as dependency (and the bundle is not installed)" { 24 | 25 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --has-dep test-bundle1" 26 | 27 | assert_status_is "$SWUPD_BUNDLE_NOT_TRACKED" 28 | expected_output=$(cat <<-EOM 29 | Bundle "test-bundle1" does not seem to be installed 30 | try passing --all to check uninstalled bundles 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | #WEIGHT=4 37 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-has-dep-nested-server.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /foo "$TEST_NAME" 10 | create_bundle -n test-bundle3 -f /foo "$TEST_NAME" 11 | # add bundle1 as dependencies of bundle2 and bundle 2 as dependency of bundle3 12 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle2 test-bundle1 13 | add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle3 test-bundle2 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST010: List all bundles that have a given bundle as dependency" { 24 | 25 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --has-dep test-bundle1 --all" 26 | 27 | assert_status_is 0 28 | expected_output=$(cat <<-EOM 29 | Loading required manifests... 30 | 31 | All bundles that have test-bundle1 as a dependency: 32 | - test-bundle2 33 | - test-bundle3 34 | 35 | Total: 2 36 | EOM 37 | ) 38 | assert_is_output --identical "$expected_output" 39 | 40 | } 41 | #WEIGHT=4 42 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-installed.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_bundle -L -t -n test-bundle2 -f /file_2 "$TEST_NAME" 13 | create_bundle -n test-bundle3 -f /file_3 "$TEST_NAME" 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST001: List all installed bundles" { 24 | 25 | # bundle-list with no options should list only installed bundles 26 | 27 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS" 28 | 29 | assert_status_is "$SWUPD_OK" 30 | expected_output=$(cat <<-EOM 31 | Installed bundles: 32 | - os-core 33 | - test-bundle1 34 | - test-bundle2 35 | 36 | Total: 3 37 | EOM 38 | ) 39 | assert_is_output --identical "$expected_output" 40 | 41 | } 42 | 43 | @test "LST024: List all installed bundles and their installation status" { 44 | 45 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --status" 46 | 47 | assert_status_is "$SWUPD_OK" 48 | expected_output=$(cat <<-EOM 49 | Installed bundles: 50 | - os-core (installed) 51 | - test-bundle1 (installed) 52 | - test-bundle2 (explicitly installed) 53 | 54 | Total: 3 55 | EOM 56 | ) 57 | assert_is_output --identical "$expected_output" 58 | 59 | } 60 | #WEIGHT=6 61 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-no-deps.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /foo "$TEST_NAME" 10 | 11 | } 12 | 13 | teardown_file() { 14 | 15 | destroy_test_environment --force "$TEST_NAME" 16 | 17 | } 18 | 19 | @test "LST008: List bundle's dependencies when bundle has no dependencies" { 20 | 21 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --deps test-bundle1" 22 | 23 | assert_status_is 0 24 | expected_output=$(cat <<-EOM 25 | Loading required manifests... 26 | 27 | No included bundles 28 | EOM 29 | ) 30 | assert_is_output --identical "$expected_output" 31 | 32 | } 33 | #WEIGHT=3 34 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-none-has-deps.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle1 -f /foo "$TEST_NAME" 9 | create_bundle -L -n test-bundle2 -f /foo "$TEST_NAME" 10 | 11 | } 12 | 13 | teardown_file() { 14 | 15 | destroy_test_environment --force "$TEST_NAME" 16 | 17 | } 18 | 19 | @test "LST012: List bundles that have a given bundle as dependency (and there are none)" { 20 | 21 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --has-dep test-bundle1" 22 | 23 | assert_status_is 0 24 | expected_output=$(cat <<-EOM 25 | Loading required manifests... 26 | 27 | No bundles have test-bundle1 as a dependency 28 | EOM 29 | ) 30 | assert_is_output --identical "$expected_output" 31 | 32 | } 33 | #WEIGHT=3 34 | -------------------------------------------------------------------------------- /test/functional/bundlelist/list-quiet.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | setup_file() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_bundle -L -n test-bundle2 -f /file_2 "$TEST_NAME" 13 | create_bundle -n test-bundle3 -f /file_3 "$TEST_NAME" 14 | 15 | } 16 | 17 | teardown_file() { 18 | 19 | destroy_test_environment --force "$TEST_NAME" 20 | 21 | } 22 | 23 | @test "LST021: List all installed bundles using a scriptable output (quiet)" { 24 | 25 | # when using the --quiet flag, the output should be in a format that 26 | # can be piped 27 | 28 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --quiet" 29 | 30 | assert_status_is "$SWUPD_OK" 31 | expected_output=$(cat <<-EOM 32 | os-core 33 | test-bundle1 34 | test-bundle2 35 | EOM 36 | ) 37 | assert_is_output --identical "$expected_output" 38 | 39 | } 40 | 41 | @test "LST022: List all available bundles using scriptable output (quiet)" { 42 | 43 | run sudo sh -c "$SWUPD bundle-list $SWUPD_OPTS --all --quiet" 44 | 45 | assert_status_is "$SWUPD_OK" 46 | expected_output=$(cat <<-EOM 47 | os-core 48 | test-bundle1 49 | test-bundle2 50 | test-bundle3 51 | EOM 52 | ) 53 | assert_is_output --identical "$expected_output" 54 | 55 | } 56 | #WEIGHT=6 57 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-boot-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -r "$TEST_NAME" 8 | create_bundle -L -n test-bundle -f /usr/lib/kernel/test-file "$TEST_NAME" 9 | 10 | } 11 | 12 | @test "REM008: Removing a bundle containing a boot file" { 13 | 14 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS test-bundle" 15 | 16 | assert_status_is 0 17 | assert_file_not_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle 18 | assert_file_not_exists "$TARGET_DIR"/usr/lib/kernel/testfile 19 | assert_dir_not_exists "$TARGET_DIR"/usr/lib/kernel 20 | # these files should not be deleted because they are also part of os-core 21 | assert_dir_exists "$TARGET_DIR"/usr/lib 22 | assert_dir_exists "$TARGET_DIR"/usr/ 23 | expected_output=$(cat <<-EOM 24 | The following bundles are being removed: 25 | - test-bundle 26 | Deleting bundle files... 27 | Total deleted files: 3 28 | Successfully removed 1 bundle 29 | EOM 30 | ) 31 | assert_is_output "$expected_output" 32 | 33 | } 34 | #WEIGHT=3 35 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-flags.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | @test "REM032: Bundle remove conflicting flags" { 9 | 10 | # some flags are mutually exclusive 11 | 12 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS --orphans --force" 13 | assert_status_is "$SWUPD_INVALID_OPTION" 14 | assert_in_output "Error: --orphans and --force options are mutually exclusive" 15 | 16 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS --orphans --recursive" 17 | assert_status_is "$SWUPD_INVALID_OPTION" 18 | assert_in_output "Error: --orphans and --recursive options are mutually exclusive" 19 | 20 | } 21 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-include.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle1 -f /foo/test-file1 "$TEST_NAME" 9 | create_bundle -L -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" 10 | # add test-bundle1 as dependency of test-bundle2 11 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.test-bundle2 test-bundle1 12 | 13 | } 14 | 15 | @test "REM010: Try removing a bundle that is a dependency of another bundle" { 16 | 17 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS test-bundle1" 18 | 19 | assert_status_is "$SWUPD_REQUIRED_BUNDLE_ERROR" 20 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle1 21 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle2 22 | assert_file_exists "$TARGET_DIR"/foo/test-file1 23 | assert_file_exists "$TARGET_DIR"/bar/test-file2 24 | expected_output=$(cat <<-EOM 25 | Bundle "test-bundle1" is required by the following bundles: 26 | - test-bundle2 27 | Error: Bundle "test-bundle1" is required by 1 bundle, skipping it... 28 | Use "swupd bundle-remove --force test-bundle1" to remove "test-bundle1" and all bundles that require it 29 | Failed to remove 1 of 1 bundles 30 | EOM 31 | ) 32 | assert_is_output "$expected_output" 33 | 34 | } 35 | #WEIGHT=3 36 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-optional-bundles.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /foo/test-file1 "$TEST_NAME" 12 | create_bundle -L -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" 13 | create_bundle -L -n test-bundle3 -f /baz/test-file3 "$TEST_NAME" 14 | 15 | # add test-bundle2 as a dependency of test-bundle1 and 16 | # test-bundle3 as optional 17 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.test-bundle1 test-bundle2 18 | add_dependency_to_manifest -o "$WEB_DIR"/10/Manifest.test-bundle1 test-bundle3 19 | 20 | } 21 | 22 | @test "REM021: Removing an optional bundle" { 23 | 24 | # An optional bundle is not required to be installed in the system while includes 25 | # are, but they are installed by default. Users shuld be able to remove them. 26 | 27 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS test-bundle3" 28 | 29 | assert_status_is 0 30 | expected_output=$(cat <<-EOM 31 | The following bundles are being removed: 32 | - test-bundle3 33 | Deleting bundle files... 34 | Total deleted files: 3 35 | Successfully removed 1 bundle 36 | EOM 37 | ) 38 | assert_is_output "$expected_output" 39 | assert_file_exists "$TARGET_DIR"/foo/test-file1 40 | assert_file_exists "$TARGET_DIR"/bar/test-file2 41 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle1 42 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle2 43 | assert_file_not_exists "$TARGET_DIR"/baz/test-file3 44 | assert_file_not_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle3 45 | 46 | } 47 | #WEIGHT=4 48 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-os-core.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | 9 | } 10 | 11 | @test "REM009: Try removing bundle 'os-core'" { 12 | 13 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS os-core" 14 | 15 | assert_status_is "$SWUPD_REQUIRED_BUNDLE_ERROR" 16 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/os-core 17 | assert_file_exists "$TARGET_DIR"/core 18 | expected_output=$(cat <<-EOM 19 | Warning: Bundle "os-core" not allowed to be removed, skipping it... 20 | Failed to remove 1 of 1 bundles 21 | EOM 22 | ) 23 | assert_is_output "$expected_output" 24 | 25 | } 26 | #WEIGHT=1 27 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-parse-args.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | @test "REM013: Ensure bundle name is passed as an option when removing a bundle" { 6 | 7 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS" 8 | 9 | assert_status_is "$SWUPD_INVALID_OPTION" 10 | assert_in_output "Error: missing bundle(s) to be removed" 11 | 12 | } 13 | #WEIGHT=1 14 | -------------------------------------------------------------------------------- /test/functional/bundleremove/remove-with-dependency.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_bundle -L -n test-bundle2 -f /file_2 "$TEST_NAME" 13 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.test-bundle1 test-bundle2 14 | 15 | } 16 | 17 | @test "REM012: Removing a bundle that has another bundle as dependency" { 18 | 19 | # When removing a bundle that has another bundle as dependency, only the 20 | # requested bundle should be deleted but its dependencies should not 21 | 22 | run sudo sh -c "$SWUPD bundle-remove $SWUPD_OPTS test-bundle1" 23 | 24 | assert_status_is 0 25 | # test-bundle1 is deleted 26 | assert_file_not_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle1 27 | assert_file_not_exists "$TARGET_DIR"/file_1 28 | # test-bundle2 is not deleted 29 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle2 30 | assert_file_exists "$TARGET_DIR"/file_2 31 | expected_output=$(cat <<-EOM 32 | The following bundles are being removed: 33 | - test-bundle1 34 | Deleting bundle files... 35 | Total deleted files: 2 36 | Successfully removed 1 bundle 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | 41 | } 42 | #WEIGHT=3 43 | -------------------------------------------------------------------------------- /test/functional/certattributes.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = myca 3 | 4 | [ crl_ext ] 5 | authorityKeyIdentifier=keyid:always 6 | 7 | [ req ] 8 | private_key = private.pem 9 | distinguished_name = myca_policy 10 | x509_extensions = ca_extensions 11 | 12 | [ myca_policy ] 13 | commonName = supplied 14 | stateOrProvinceName = supplied 15 | countryName = supplied 16 | emailAddress = optional 17 | organizationName = supplied 18 | organizationalUnitName = optional 19 | 20 | [ca_extensions] 21 | keyUsage = digitalSignature,keyCertSign,cRLSign 22 | extendedKeyUsage = codeSigning 23 | basicConstraints = critical,CA:FALSE 24 | subjectKeyIdentifier = hash 25 | authorityKeyIdentifier = keyid:always,issuer 26 | -------------------------------------------------------------------------------- /test/functional/check_ids.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # shellcheck disable=SC1090,SC1091 4 | # SC1091: Not following, SC couldn't follow the dynamic path 5 | # We already process that file, so it's fine to ignore 6 | SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 7 | source "$SCRIPT_PATH/../functional/testlib.bash" 8 | 9 | set -e 10 | 11 | #Check if there's no dupicated test 12 | list_tests --all| cut -f 1 -d ':'|sort -cu 13 | 14 | last_lbl="" 15 | last_num=0 16 | for t in $(list_tests --all| cut -f 1 -d ':'|sort); do 17 | lbl=$(echo "$t" | cut -b 1-3) 18 | num=$(echo "$t" | cut -b 4-6) 19 | if [ "$last_lbl" != "$lbl" ]; then 20 | last_lbl="$lbl" 21 | last_num=0 22 | fi 23 | 24 | last_num=$((last_num + 1)) 25 | if [ "$last_num" -ne "$num" ]; then 26 | echo "Test $t has an incorrect number" 27 | exit 1 28 | fi 29 | done 30 | 31 | echo "All tests have valid IDs." 32 | 33 | exit 0 34 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-format-bump.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 10 1 11 | bump_format "$TEST_NAME" 12 | create_version -r "$TEST_NAME" 40 30 2 13 | 14 | } 15 | 16 | @test "CHK010: Check for available updates accross format bumps" { 17 | 18 | # check-update should return the latest available version regardless 19 | # of if it is in a different format 20 | 21 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | expected_output=$(cat <<-EOM 25 | Current OS version: 10 26 | Latest server version: 40 27 | There is a new OS version available: 40 28 | EOM 29 | ) 30 | assert_is_output "$expected_output" 31 | 32 | } 33 | 34 | @test "CHK011: Check if the check-update returns format no with --verbose" { 35 | 36 | # check if verbose options holds 37 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS --verbose -F 1" 38 | 39 | expected_output=$(cat <<-EOM 40 | Current OS version: 10 (format 1) 41 | Latest server version: 40 (format 2) 42 | Latest version in format 1: 20 43 | There is a new OS version available: 40 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | assert_status_is "$SWUPD_OK" 48 | 49 | } 50 | #WEIGHT=13 51 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-json.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_version "$TEST_NAME" 20 10 12 | 13 | } 14 | 15 | @test "CHK009: Check for updates using machine readable output" { 16 | 17 | # the --json-output flag can be used so all the output of the check-update 18 | # command is created as a JSON stream that can be read and parsed by other 19 | # applications interested into knowing real time status of the command 20 | 21 | run sudo sh -c "$SWUPD check-update --json-outpu $SWUPD_OPTS_PROGRESS" 22 | 23 | assert_status_is 0 24 | expected_output=$(cat <<-EOM 25 | [ 26 | { "type" : "start", "section" : "check-update" }, 27 | { "type" : "info", "msg" : "Current OS version: 10" }, 28 | { "type" : "info", "msg" : "Latest server version: 20" }, 29 | { "type" : "info", "msg" : "There is a new OS version available:" }, 30 | { "type" : "info", "msg" : "20" }, 31 | { "type" : "end", "section" : "check-update", "status" : 0 } 32 | ] 33 | EOM 34 | ) 35 | assert_is_output "$expected_output" 36 | 37 | } 38 | #WEIGHT=2 39 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-new-version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # create a new version 100 9 | create_test_environment "$TEST_NAME" 100 10 | # this will leave both latest version and current version as 100 11 | # so change current version back to 10 12 | set_current_version "$TEST_NAME" 10 13 | 14 | } 15 | 16 | @test "CHK001: Check for available updates when there is a new version available" { 17 | 18 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" 19 | 20 | assert_status_is 0 21 | expected_output=$(cat <<-EOM 22 | Current OS version: 10 23 | Latest server version: 100 24 | There is a new OS version available: 100 25 | EOM 26 | ) 27 | assert_is_output "$expected_output" 28 | 29 | } 30 | #WEIGHT=2 31 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-no-server-content.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # remove the version from web-dir so there is no "server" data 9 | sudo rm -rf "$TEST_NAME"/web-dir/version 10 | 11 | } 12 | 13 | @test "CHK004: Check for available updates with no server version file available" { 14 | 15 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" 16 | 17 | assert_status_is_not 0 18 | expected_output=$(cat <<-EOM 19 | Error: Unable to determine the server version 20 | Current OS version: 10 21 | EOM 22 | ) 23 | assert_in_output "$expected_output" 24 | 25 | } 26 | #WEIGHT=2 27 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-no-target-content.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | # remove os-release file from target-dir so no current version can be determined 9 | sudo rm "$TARGET_DIR"/usr/lib/os-release 10 | 11 | } 12 | 13 | @test "CHK005: Check for available updates with no target version file available" { 14 | 15 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" 16 | 17 | assert_status_is_not 0 18 | expected_output=$(cat <<-EOM 19 | Error: Unable to determine current OS version 20 | Latest server version: 10 21 | EOM 22 | ) 23 | assert_is_output "$expected_output" 24 | 25 | } 26 | #WEIGHT=1 27 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-slow-server.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version "$TEST_NAME" 99990 10 staging 9 | 10 | # start slow response web server 11 | start_web_server -s -l 1 12 | 13 | # Set the web server as our upstream server 14 | port=$(get_web_server_port "$TEST_NAME") 15 | set_upstream_server "$TEST_NAME" "http://localhost:$port/$TEST_NAME/web-dir" 16 | 17 | } 18 | 19 | @test "CHK003: Check for available updates with a slow server" { 20 | 21 | run sudo sh -c "$SWUPD check-update --allow-insecure-http $SWUPD_OPTS" 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | Warning: This is an insecure connection 25 | The --allow-insecure-http flag was used, be aware that this poses a threat to the system 26 | Current OS version: 10 27 | Latest server version: 99990 28 | There is a new OS version available: 99990 29 | EOM 30 | ) 31 | assert_is_output "$expected_output" 32 | } 33 | #WEIGHT=5 34 | -------------------------------------------------------------------------------- /test/functional/checkupdate/chk-update-version-match.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | 9 | } 10 | 11 | @test "CHK002: Check for available updates when we are at latest" { 12 | 13 | run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" 14 | 15 | assert_status_is 1 16 | expected_output=$(cat <<-EOM 17 | Current OS version: 10 18 | Latest server version: 10 19 | There are no updates available 20 | EOM 21 | ) 22 | assert_is_output "$expected_output" 23 | 24 | } 25 | #WEIGHT=1 26 | -------------------------------------------------------------------------------- /test/functional/diagnose/diagnose-boot-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle -f /usr/lib/kernel/testfile "$TEST_NAME" 9 | # change the content of testfile so the hash doesn't match 10 | write_to_protected_file -a "$TARGET_DIR"/usr/lib/kernel/testfile "some new content" 11 | 12 | } 13 | 14 | @test "DIA004: Diagnose a system that has a corrupt boot file" { 15 | 16 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS" 17 | assert_status_is "$SWUPD_NO" 18 | expected_output=$(cat <<-EOM 19 | Diagnosing version 10 20 | Downloading missing manifests... 21 | Checking for missing files 22 | Checking for corrupt files 23 | .* Hash mismatch for file: .*/target-dir/usr/lib/kernel/testfile 24 | Checking for extraneous files 25 | Inspected 7 files 26 | 1 file did not match 27 | Use "swupd repair" to correct the problems in the system 28 | Diagnose successful 29 | EOM 30 | ) 31 | assert_regex_is_output "$expected_output" 32 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 33 | 34 | } 35 | #WEIGHT=2 36 | -------------------------------------------------------------------------------- /test/functional/diagnose/diagnose-directory-tree-deleted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -e "$TEST_NAME" 8 | create_bundle -L -n os-core -f /testdir1/testdir2/testfile "$TEST_NAME" 9 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-status /testdir1/testdir2/testfile .d.. 10 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-status /testdir1/testdir2 .d.. 11 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-status /testdir1 .d.. 12 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-hash /testdir1/testdir2/testfile "$ZERO_HASH" 13 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-hash /testdir1/testdir2 "$ZERO_HASH" 14 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-hash /testdir1 "$ZERO_HASH" 15 | 16 | } 17 | 18 | 19 | @test "DIA006: Diagnose a system that has a file that should be deleted" { 20 | 21 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS" 22 | assert_status_is "$SWUPD_NO" 23 | expected_output=$(cat <<-EOM 24 | Diagnosing version 10 25 | Downloading missing manifests... 26 | Checking for missing files 27 | Checking for corrupt files 28 | Checking for extraneous files 29 | .* File that should be deleted: .*/target-dir/testdir1/testdir2/testfile 30 | .* File that should be deleted: .*/target-dir/testdir1/testdir2 31 | .* File that should be deleted: .*/target-dir/testdir1 32 | Inspected 4 files 33 | 3 files found which should be deleted 34 | Use "swupd repair" to correct the problems in the system 35 | Diagnose successful 36 | EOM 37 | ) 38 | assert_regex_is_output "$expected_output" 39 | assert_dir_exists "$TARGET_DIR"/testdir1 40 | assert_dir_exists "$TARGET_DIR"/testdir1/testdir2 41 | assert_file_exists "$TARGET_DIR"/testdir1/testdir2/testfile 42 | 43 | } 44 | #WEIGHT=2 45 | -------------------------------------------------------------------------------- /test/functional/diagnose/diagnose-good.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 11 | 12 | } 13 | 14 | @test "DIA001: Diagnose installed content on a system that is fine" { 15 | 16 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS" 17 | 18 | assert_status_is 0 19 | expected_output=$(cat <<-EOM 20 | Diagnosing version 10 21 | Downloading missing manifests... 22 | Checking for missing files 23 | Checking for corrupt files 24 | Checking for extraneous files 25 | Inspected 11 files 26 | Diagnose successful 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | #WEIGHT=2 33 | -------------------------------------------------------------------------------- /test/functional/diagnose/diagnose-missing-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle -f /foo/test-file1,/bar/test-file2 "$TEST_NAME" 9 | # remove a directory and file that are part of the bundle 10 | sudo rm -rf "$TARGET_DIR"/foo/test-file1 11 | 12 | } 13 | 14 | @test "DIA002: Diagnose a system that is missing a file" { 15 | 16 | run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS" 17 | assert_status_is "$SWUPD_NO" 18 | expected_output=$(cat <<-EOM 19 | Diagnosing version 10 20 | Downloading missing manifests... 21 | Checking for missing files 22 | .* Missing file: .*/target-dir/foo/test-file1 23 | Checking for corrupt files 24 | Checking for extraneous files 25 | Inspected 7 files 26 | 1 file was missing 27 | Use "swupd repair" to correct the problems in the system 28 | Diagnose successful 29 | EOM 30 | ) 31 | assert_regex_is_output "$expected_output" 32 | assert_file_not_exists "$TARGET_DIR"/foo/test-file1 33 | assert_file_exists "$TARGET_DIR"/bar/test-file2 34 | 35 | } 36 | #WEIGHT=2 37 | -------------------------------------------------------------------------------- /test/functional/hashdump/hashdump-file-hash.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | printf "test-data" | sudo tee "$TARGET_DIR"/test-hash > /dev/null 9 | 10 | } 11 | 12 | teardown_file() { 13 | 14 | destroy_test_environment --force "$TEST_NAME" 15 | 16 | } 17 | 18 | @test "HSD001: Calculate the hash of a file" { 19 | 20 | run sudo sh -c "$SWUPD hashdump $TARGET_DIR/test-hash" 21 | 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | Calculating hash with xattrs for: .*/target-dir/test-hash 25 | 8286279c93f45c7ffa6b9ed440066de09716527346d9dd0239f50948e0e554f0 26 | EOM 27 | ) 28 | assert_regex_is_output "$expected_output" 29 | 30 | } 31 | 32 | @test "HSD002: Try calculating the hash of a file that does not exist" { 33 | 34 | # attempting to calculate the hash from a non existent file should still 35 | # succeed but should return a hash of all zeros 36 | 37 | run sudo sh -c "$SWUPD hashdump $TARGET_DIR/fake-file" 38 | 39 | assert_status_is 0 40 | expected_output=$(cat <<-EOM 41 | Calculating hash with xattrs for: .*/target-dir/fake-file 42 | 0000000000000000000000000000000000000000000000000000000000000000 43 | EOM 44 | ) 45 | assert_regex_is_output "$expected_output" 46 | 47 | } 48 | 49 | @test "HSD003: Calculate the hash of a file specifying its path separatelly" { 50 | 51 | run sudo sh -c "$SWUPD hashdump --path=$TARGET_DIR test-hash" 52 | 53 | assert_status_is 0 54 | expected_output=$(cat <<-EOM 55 | Calculating hash with xattrs for: .*/target-dir/test-hash 56 | 8286279c93f45c7ffa6b9ed440066de09716527346d9dd0239f50948e0e554f0 57 | EOM 58 | ) 59 | assert_regex_is_output "$expected_output" 60 | 61 | } 62 | #WEIGHT=2 63 | -------------------------------------------------------------------------------- /test/functional/ignore-list: -------------------------------------------------------------------------------- 1 | Warning: helper script .* not found, it will be skipped 2 | Update took .* 3 | Compile-time options:.* 4 | Compile-time configuration: 5 | mount point.* 6 | state directory.* 7 | bundles directory.* 8 | certificate path.* 9 | fallback certificate path.* 10 | content URL.* 11 | version URL.* 12 | format ID.* 13 | pre-update hook.* 14 | post-update hook.* 15 | -------------------------------------------------------------------------------- /test/functional/info/info-basic.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Karthik Prabhu Vinod 4 | # Email: karthik.prabhu.vinod@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 10 1 11 | 12 | } 13 | 14 | @test "INF001: Basic test, Check info verbose" { 15 | 16 | run sudo sh -c "$SWUPD info $SWUPD_OPTS --verbose" 17 | assert_status_is "$SWUPD_OK" 18 | expected_output=$(cat <<-EOM 19 | Distribution: Swupd Test Distro 20 | Installed version: 10 (format 1) 21 | Version URL: file://$ABS_TEST_DIR/web-dir 22 | Content URL: file://$ABS_TEST_DIR/web-dir 23 | EOM 24 | ) 25 | 26 | assert_is_output "$expected_output" 27 | 28 | } 29 | 30 | @test "INF002: Basic test, Check info basic" { 31 | 32 | run sudo sh -c "$SWUPD info $SWUPD_OPTS" 33 | assert_status_is "$SWUPD_OK" 34 | expected_output=$(cat <<-EOM 35 | Distribution: Swupd Test Distro 36 | Installed version: 10 37 | Version URL: file://$ABS_TEST_DIR/web-dir 38 | Content URL: file://$ABS_TEST_DIR/web-dir 39 | EOM 40 | ) 41 | 42 | assert_is_output "$expected_output" 43 | 44 | } 45 | #WEIGHT=2 46 | -------------------------------------------------------------------------------- /test/functional/mirror/mirror-createdir-negative.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | 9 | } 10 | 11 | teardown_file() { 12 | 13 | destroy_test_environment --force "$TEST_NAME" 14 | 15 | } 16 | 17 | @test "MIR004: Try setting up a mirror when /etc/swupd is a file instead of a directory" { 18 | 19 | sudo rm -rf "$TARGET_DIR"/etc/swupd 20 | sudo touch "$TARGET_DIR"/etc/swupd 21 | 22 | run sudo sh -c "$SWUPD mirror -s https://example.com/swupd-file $SWUPD_OPTS" 23 | 24 | assert_status_is_not 0 25 | expected_output=$(cat <<-EOM 26 | .*/etc/swupd: not a directory 27 | Error: Unable to set mirror url 28 | EOM 29 | ) 30 | assert_regex_is_output "$expected_output" 31 | 32 | } 33 | 34 | @test "MIR005: Try setting up a mirror when /etc/swupd is a symlink to a file instead of a directory" { 35 | 36 | sudo rm -rf "$TARGET_DIR"/etc/swupd 37 | sudo touch "$TARGET_DIR"/foo 38 | sudo ln -s "$(realpath "$TARGET_DIR"/foo)" "$TARGET_DIR"/etc/swupd 39 | 40 | run sudo sh -c "$SWUPD mirror -s https://example.com/swupd-file $SWUPD_OPTS" 41 | 42 | assert_status_is_not 0 43 | expected_output=$(cat <<-EOM 44 | .*/etc/swupd: not a directory 45 | Error: Unable to set mirror url 46 | EOM 47 | ) 48 | assert_regex_is_output "$expected_output" 49 | 50 | } 51 | #WEIGHT=2 52 | -------------------------------------------------------------------------------- /test/functional/mirror/mirror-json.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | } 13 | 14 | @test "MIR006: Set a mirror using machine readable output" { 15 | 16 | # the --json-output flag can be used so all the output of the mirror 17 | # command is created as a JSON stream that can be read and parsed by other 18 | # applications interested into knowing real time status of the command 19 | 20 | run sudo sh -c "$SWUPD mirror --json-output -s http://example.com/swupd-file --allow-insecure-http $SWUPD_OPTS_PROGRESS" 21 | 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | [ 25 | { "type" : "start", "section" : "mirror" }, 26 | { "type" : "warning", "msg" : "This is an insecure connection" }, 27 | { "type" : "info", "msg" : "The --allow-insecure-http flag was used, be aware that this poses a threat to the system" }, 28 | { "type" : "warning", "msg" : "The mirror was set up using HTTP. In order for autoupdate to continue working you will need to set allow_insecure_http=true in the swupd configuration file. Alternatively you can set the mirror using HTTPS (recommended)" }, 29 | { "type" : "info", "msg" : "Mirror url set" }, 30 | { "type" : "info", "msg" : "Distribution: Swupd Test Distro" }, 31 | { "type" : "info", "msg" : "Installed version:" }, 32 | { "type" : "info", "msg" : "10" }, 33 | { "type" : "info", "msg" : "Version URL: http://example.com/swupd-file" }, 34 | { "type" : "info", "msg" : "Content URL: http://example.com/swupd-file" }, 35 | { "type" : "end", "section" : "mirror", "status" : 0 } 36 | ] 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | 41 | } 42 | #WEIGHT=1 43 | -------------------------------------------------------------------------------- /test/functional/only_in_ci_system/add-no-disk-space.ignore-list: -------------------------------------------------------------------------------- 1 | Error: Curl - Cannot close file.* 2 | -------------------------------------------------------------------------------- /test/functional/os-install/install-download.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: John Akre 4 | # Email: john.w.akre@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -f /core "$TEST_NAME" 12 | 13 | } 14 | 15 | @test "INS015: Download os-install content without installing" { 16 | 17 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS_NO_PATH --download $TARGET_DIR" 18 | 19 | assert_status_is 0 20 | expected_output=$(cat <<-EOM 21 | Installing OS version 10 (latest) 22 | Downloading missing manifests... 23 | Downloading packs for: 24 | - os-core 25 | Finishing packs extraction... 26 | Checking for corrupt files 27 | Validate downloaded files 28 | No extra files need to be downloaded 29 | Installation files downloaded 30 | EOM 31 | ) 32 | 33 | assert_is_output "$expected_output" 34 | assert_file_not_exists "$TARGET_DIR"/core 35 | 36 | assert_file_exists "$ABS_MANIFEST_DIR"/10/Manifest.MoM 37 | assert_file_exists "$ABS_MANIFEST_DIR"/10/Manifest.os-core 38 | 39 | core_hash=$(get_hash_from_manifest "$ABS_MANIFEST_DIR"/10/Manifest.os-core "/core") 40 | assert_file_exists "$ABS_STAGED_DIR"/"$core_hash" 41 | 42 | } 43 | #WEIGHT=1 44 | -------------------------------------------------------------------------------- /test/functional/os-install/install-hardlink-symlink.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -a /core,/core2,/core3 -H /symlink,/symlink2,/symlink3 "$TEST_NAME" 12 | 13 | } 14 | 15 | @test "INS027: Check if hardlinks are preserved" { 16 | 17 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS --path $TARGET_DIR" 18 | assert_status_is "$SWUPD_OK" 19 | run sudo sh -c "$SWUPD clean --all $SWUPD_OPTS --path $TARGET_DIR" 20 | assert_status_is "$SWUPD_OK" 21 | 22 | run stat --printf=%h "$TARGET_DIR"/core 23 | assert_status_is "0" 24 | assert_is_output "3" 25 | 26 | run stat --printf=%h "$TARGET_DIR"/core2 27 | assert_status_is "0" 28 | assert_is_output "3" 29 | 30 | run stat --printf=%h "$TARGET_DIR"/core3 31 | assert_status_is "0" 32 | assert_is_output "3" 33 | 34 | } 35 | 36 | @test "INS028: Check if symlink hardlinks are not preserved" { 37 | 38 | # There are known bugs on bsdtar to extract hardlink to symlinks, 39 | # so we avoid to have them on swupd. 40 | 41 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS --path $TARGET_DIR" 42 | assert_status_is "$SWUPD_OK" 43 | run sudo sh -c "$SWUPD clean --all $SWUPD_OPTS --path $TARGET_DIR" 44 | assert_status_is "$SWUPD_OK" 45 | 46 | run stat --printf=%h "$TARGET_DIR"/symlink 47 | assert_status_is "0" 48 | assert_is_output "1" 49 | 50 | run stat --printf=%h "$TARGET_DIR"/symlink2 51 | assert_status_is "0" 52 | assert_is_output "1" 53 | 54 | run stat --printf=%h "$TARGET_DIR"/symlink3 55 | assert_status_is "0" 56 | assert_is_output "1" 57 | 58 | } 59 | #WEIGHT=4 60 | -------------------------------------------------------------------------------- /test/functional/os-install/install-latest-missing.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | # remove the formatstaging/latest 12 | sudo rm -rf "$WEB_DIR/version/formatstaging/latest" 13 | 14 | } 15 | 16 | @test "INS012: Try doing an OS install based on the latest version and a version file can't be found on server" { 17 | 18 | # if swupd cannot determine what the "latest" version is, it should fail 19 | 20 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS --version latest" 21 | 22 | assert_status_is_not "$SWUPD_OK" 23 | expected_output=$(cat <<-EOM 24 | Error: Unable to get latest version for install 25 | Installation failed 26 | EOM 27 | ) 28 | assert_in_output "$expected_output" 29 | 30 | } 31 | #WEIGHT=1 32 | -------------------------------------------------------------------------------- /test/functional/os-install/install-no-also-add.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: John Akre 4 | # Email: john.w.akre@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle1 -f /foo/test-file1 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" 13 | create_bundle -n test-bundle3 -f /bar/test-file3 "$TEST_NAME" 14 | 15 | # Create bundle dependencies 16 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.os-core test-bundle1 17 | add_dependency_to_manifest -o "$WEB_DIR"/10/Manifest.os-core test-bundle2 18 | add_dependency_to_manifest -o "$WEB_DIR"/10/Manifest.test-bundle1 test-bundle3 19 | 20 | } 21 | 22 | @test "INS016: Install without also-add bundles" { 23 | 24 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS_NO_PATH --path $TARGET_DIR --skip-optional" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | Installing OS version 10 (latest) 29 | Downloading missing manifests... 30 | Downloading packs for: 31 | - test-bundle1 32 | - os-core 33 | Finishing packs extraction... 34 | Checking for corrupt files 35 | Validate downloaded files 36 | No extra files need to be downloaded 37 | Installing base OS and selected bundles 38 | Inspected 5 files 39 | 3 files were missing 40 | 3 of 3 missing files were installed 41 | 0 of 3 missing files were not installed 42 | Calling post-update helper scripts 43 | Installation successful 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | assert_file_exists "$TARGET_DIR"/core 48 | assert_file_exists "$TARGET_DIR"/foo/test-file1 49 | assert_file_not_exists "$TARGET_DIR"/bar/test-file2 50 | assert_file_not_exists "$TARGET_DIR"/bar/test-file3 51 | 52 | } 53 | #WEIGHT=5 54 | -------------------------------------------------------------------------------- /test/functional/os-install/install-no-fullfile-fallback.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -f /core "$TEST_NAME" 12 | # remove the zero packs and fullfiles 13 | sudo rm "$WEB_DIR"/10/pack-os-core-from-0.tar 14 | sudo rm -rf "$WEB_DIR"/10/files/* 15 | 16 | } 17 | 18 | @test "INS010: An OS Install with no zero packs and no fullfile fallbacks cannot complete" { 19 | 20 | # no way to get content, everything should fail 21 | 22 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS" 23 | 24 | assert_status_is "$SWUPD_COULDNT_DOWNLOAD_FILE" 25 | expected_output=$(cat <<-EOM 26 | Installing OS version 10 (latest) 27 | Downloading missing manifests... 28 | Downloading packs for: 29 | - os-core 30 | Error: zero pack downloads failed 31 | Checking for corrupt files 32 | Validate downloaded files 33 | Starting download of remaining update content. This may take a while... 34 | Error: Unable to download necessary files for this OS release 35 | Installation failed 36 | EOM 37 | ) 38 | assert_is_output "$expected_output" 39 | 40 | } 41 | #WEIGHT=1 42 | -------------------------------------------------------------------------------- /test/functional/os-install/install-no-packs.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -f /core "$TEST_NAME" 12 | # remove the zero pack 13 | sudo rm "$WEB_DIR"/10/pack-os-core-from-0.tar 14 | 15 | } 16 | 17 | @test "INS011: An OS install should fall back to use fullfiles if no packs are available" { 18 | 19 | # install should use packs if available as first choice, but if no packs exist 20 | # for the content to be installed, then swupd should fall back to using fullfiles 21 | 22 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS" 23 | 24 | assert_status_is "$SWUPD_OK" 25 | expected_output=$(cat <<-EOM 26 | Installing OS version 10 (latest) 27 | Downloading missing manifests... 28 | Downloading packs for: 29 | - os-core 30 | Error: zero pack downloads failed 31 | Checking for corrupt files 32 | Validate downloaded files 33 | Starting download of remaining update content. This may take a while... 34 | Installing base OS and selected bundles 35 | Inspected 2 files 36 | 2 files were missing 37 | 2 of 2 missing files were installed 38 | 0 of 2 missing files were not installed 39 | Calling post-update helper scripts 40 | Installation successful 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/os-core 45 | assert_file_exists "$TARGET_DIR"/core 46 | 47 | } 48 | #WEIGHT=2 49 | -------------------------------------------------------------------------------- /test/functional/os-install/install-var.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 10 11 | create_bundle -n os-core -f /var/file "$TEST_NAME" 12 | 13 | } 14 | 15 | @test "INS029: Install files on /var" { 16 | 17 | # Making sure os-install is installing files on /var. 18 | # /var is filtered by heuristics, but on install time we want 19 | # to create them. 20 | 21 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS_NO_PATH $TARGET_DIR" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | expected_output=$(cat <<-EOM 25 | Installing OS version 10 (latest) 26 | Downloading missing manifests... 27 | Downloading packs for: 28 | - os-core 29 | Finishing packs extraction... 30 | Checking for corrupt files 31 | Validate downloaded files 32 | No extra files need to be downloaded 33 | Installing base OS and selected bundles 34 | Inspected 3 files 35 | 2 files were missing 36 | 2 of 2 missing files were installed 37 | 0 of 2 missing files were not installed 38 | Calling post-update helper scripts 39 | Installation successful 40 | EOM 41 | ) 42 | assert_is_output "$expected_output" 43 | assert_file_exists "$TARGET_DIR"/usr/share/clear/bundles/os-core 44 | assert_file_exists "$TARGET_DIR"/var/file 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test/functional/repair/repair-add-missing-include-old.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /test-file1 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /test-file2 "$TEST_NAME" 13 | create_version "$TEST_NAME" 100 10 14 | update_bundle "$TEST_NAME" test-bundle1 --header-only 15 | add_dependency_to_manifest "$WEB_DIR"/100/Manifest.test-bundle1 test-bundle2 16 | set_current_version "$TEST_NAME" 100 17 | 18 | } 19 | 20 | @test "REP002: Repair a system that has a missing dependency from a previous version" { 21 | 22 | # 23 | 24 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | Diagnosing version 100 29 | Downloading missing manifests... 30 | Checking for corrupt files 31 | Validate downloaded files 32 | Starting download of remaining update content. This may take a while... 33 | Adding any missing files 34 | .* Missing file: .*/target-dir/test-file2 -> fixed 35 | .* Missing file: .*/target-dir/usr/share/clear/bundles/test-bundle2 -> fixed 36 | Repairing corrupt files 37 | Removing extraneous files 38 | Inspected 6 files 39 | 2 files were missing 40 | 2 of 2 missing files were replaced 41 | 0 of 2 missing files were not replaced 42 | Calling post-update helper scripts 43 | Repair successful 44 | EOM 45 | ) 46 | assert_regex_is_output "$expected_output" 47 | assert_file_exists "$TARGET_DIR"/core 48 | assert_file_exists "$TARGET_DIR"/test-file1 49 | assert_file_exists "$TARGET_DIR"/test-file2 50 | 51 | } 52 | #WEIGHT=4 53 | -------------------------------------------------------------------------------- /test/functional/repair/repair-add-missing-include.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /foo/test-file1 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /bar/test-file2 "$TEST_NAME" 13 | # add test-bundle2 and os-core as dependency of test-bundle1 14 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.test-bundle1 os-core 15 | add_dependency_to_manifest "$WEB_DIR"/10/Manifest.test-bundle1 test-bundle2 16 | 17 | } 18 | 19 | @test "REP001: Repairs a system that has a missing dependency" { 20 | 21 | # 22 | 23 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 24 | 25 | assert_status_is "$SWUPD_OK" 26 | expected_output=$(cat <<-EOM 27 | Diagnosing version 10 28 | Downloading missing manifests... 29 | Checking for corrupt files 30 | Validate downloaded files 31 | Starting download of remaining update content. This may take a while... 32 | Adding any missing files 33 | .* Missing file: .*/target-dir/bar -> fixed 34 | .* Missing file: .*/target-dir/bar/test-file2 -> fixed 35 | .* Missing file: .*/target-dir/usr/share/clear/bundles/test-bundle2 -> fixed 36 | Repairing corrupt files 37 | Removing extraneous files 38 | Inspected 8 files 39 | 3 files were missing 40 | 3 of 3 missing files were replaced 41 | 0 of 3 missing files were not replaced 42 | Calling post-update helper scripts 43 | Repair successful 44 | EOM 45 | ) 46 | assert_regex_is_output "$expected_output" 47 | assert_file_exists "$TARGET_DIR"/core 48 | assert_file_exists "$TARGET_DIR"/foo/test-file1 49 | assert_file_exists "$TARGET_DIR"/bar/test-file2 50 | 51 | } 52 | #WEIGHT=3 53 | -------------------------------------------------------------------------------- /test/functional/repair/repair-boot-file-deleted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 11 | create_bundle -L -n os-core -f /usr/lib/kernel/testfile "$TEST_NAME" 12 | update_manifest -p "$WEB_DIR"/10/Manifest.os-core file-status /usr/lib/kernel/testfile .db. 13 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-hash /usr/lib/kernel/testfile "$ZERO_HASH" 14 | 15 | } 16 | 17 | @test "REP004: Repair does not delete boot files from the system" { 18 | 19 | # 20 | 21 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | expected_output=$(cat <<-EOM 25 | Diagnosing version 10 26 | Downloading missing manifests... 27 | Checking for corrupt files 28 | Adding any missing files 29 | Repairing corrupt files 30 | Removing extraneous files 31 | Inspected 5 files 32 | Calling post-update helper scripts 33 | Repair successful 34 | EOM 35 | ) 36 | assert_is_output "$expected_output" 37 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 38 | 39 | } 40 | #WEIGHT=2 41 | -------------------------------------------------------------------------------- /test/functional/repair/repair-boot-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle -f /usr/lib/kernel/testfile "$TEST_NAME" 12 | # change the content of testfile so the hash doesn't match 13 | write_to_protected_file -a "$TARGET_DIR"/usr/lib/kernel/testfile "some new content" 14 | 15 | } 16 | 17 | @test "REP003: Repair a system that has a corrupt boot file" { 18 | 19 | # 20 | 21 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | expected_output=$(cat <<-EOM 25 | Diagnosing version 10 26 | Downloading missing manifests... 27 | Checking for corrupt files 28 | Validate downloaded files 29 | Starting download of remaining update content. This may take a while... 30 | Adding any missing files 31 | Repairing corrupt files 32 | -> Hash mismatch for file: $ABS_TARGET_DIR/usr/lib/kernel/testfile -> fixed 33 | Removing extraneous files 34 | Inspected 7 files 35 | 1 file did not match 36 | 1 of 1 files were repaired 37 | 0 of 1 files were not repaired 38 | Calling post-update helper scripts 39 | Warning: helper script ($ABS_TARGET_DIR/usr/bin/clr-boot-manager) not found, it will be skipped 40 | Repair successful 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 45 | 46 | } 47 | #WEIGHT=2 48 | -------------------------------------------------------------------------------- /test/functional/repair/repair-boot-file.ignore-list: -------------------------------------------------------------------------------- 1 | Update took .* 2 | Compile-time options:.* 3 | Compile-time configuration: 4 | mount point.* 5 | state directory.* 6 | bundles directory.* 7 | certificate path.* 8 | fallback certificate path.* 9 | content URL.* 10 | version URL.* 11 | format ID.* 12 | pre-update hook.* 13 | post-update hook.* 14 | -------------------------------------------------------------------------------- /test/functional/repair/repair-boot-skip.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 11 | create_bundle -L -n os-core -f /usr/lib/kernel/testfile "$TEST_NAME" 12 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-status /usr/lib/kernel/testfile .db. 13 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-hash /usr/lib/kernel/testfile "$ZERO_HASH" 14 | 15 | } 16 | 17 | @test "REP005: Repair can skip the installation of updated boot files" { 18 | 19 | # 20 | 21 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --no-boot-update" 22 | 23 | assert_status_is "$SWUPD_OK" 24 | expected_output=$(cat <<-EOM 25 | Diagnosing version 10 26 | Downloading missing manifests... 27 | Checking for corrupt files 28 | Adding any missing files 29 | Repairing corrupt files 30 | Removing extraneous files 31 | Inspected 5 files 32 | Calling post-update helper scripts 33 | Warning: boot files update skipped due to --no-boot-update argument 34 | Repair successful 35 | EOM 36 | ) 37 | assert_is_output "$expected_output" 38 | # this should exist at the end, even if cbm is not run 39 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 40 | 41 | } 42 | #WEIGHT=2 43 | -------------------------------------------------------------------------------- /test/functional/repair/repair-deleted-include-manifest.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: John Akre 4 | # Email: john.w.akre@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /test-file1 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /test-file2 "$TEST_NAME" 13 | create_version "$TEST_NAME" 100 10 14 | update_bundle "$TEST_NAME" test-bundle1 --header-only 15 | add_dependency_to_manifest "$WEB_DIR"/100/Manifest.test-bundle1 test-bundle2 16 | set_current_version "$TEST_NAME" 100 17 | 18 | # Delete the included manifest 19 | sudo rm "$WEB_DIR"/10/Manifest.test-bundle2 20 | sudo rm "$WEB_DIR"/10/pack-test-bundle2-from-0.tar 21 | sudo rm "$WEB_DIR"/10/Manifest.test-bundle2.tar 22 | } 23 | 24 | @test "REP037: Report error when an included manifest is deleted" { 25 | 26 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 27 | 28 | assert_status_is "$SWUPD_COULDNT_LOAD_MANIFEST" 29 | expected_output=$(cat <<-EOM 30 | Diagnosing version 100 31 | Downloading missing manifests... 32 | Error: Failed to retrieve 10 test-bundle2 manifest 33 | Error: Unable to download manifest test-bundle2 version 10, exiting now 34 | Repair did not fully succeed 35 | EOM 36 | ) 37 | assert_regex_is_output "$expected_output" 38 | 39 | } 40 | #WEIGHT=4 41 | -------------------------------------------------------------------------------- /test/functional/repair/repair-empty-dir-deleted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 11 | create_bundle -L -n os-core -d /testdir "$TEST_NAME" 12 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-status /testdir .d.. 13 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-hash /testdir "$ZERO_HASH" 14 | 15 | } 16 | 17 | @test "REP010: Repair is able to remove an empty directory" { 18 | 19 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 20 | 21 | assert_status_is "$SWUPD_OK" 22 | expected_output=$(cat <<-EOM 23 | Diagnosing version 10 24 | Downloading missing manifests... 25 | Checking for corrupt files 26 | Adding any missing files 27 | Repairing corrupt files 28 | Removing extraneous files 29 | .* File that should be deleted: .*/target-dir/testdir -> deleted 30 | Inspected 2 files 31 | 1 file found which should be deleted 32 | 1 of 1 files were deleted 33 | 0 of 1 files were not deleted 34 | Calling post-update helper scripts 35 | Repair successful 36 | EOM 37 | ) 38 | assert_regex_is_output "$expected_output" 39 | assert_dir_not_exists "$TARGET_DIR"/testdir 40 | 41 | } 42 | #WEIGHT=2 43 | -------------------------------------------------------------------------------- /test/functional/repair/repair-flags.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | @test "REP008: Repair conflicting flags" { 9 | 10 | # Some flags are mutually exclusive 11 | 12 | # --quick & --picky 13 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --quick --picky" 14 | assert_status_is "$SWUPD_INVALID_OPTION" 15 | assert_in_output "Error: --quick and --picky options are mutually exclusive" 16 | 17 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --picky --quick" 18 | assert_status_is "$SWUPD_INVALID_OPTION" 19 | assert_in_output "Error: --quick and --picky options are mutually exclusive" 20 | 21 | # --quick & --extra-files-only 22 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --quick --extra-files-only" 23 | assert_status_is "$SWUPD_INVALID_OPTION" 24 | assert_in_output "Error: --quick and --extra-files-only options are mutually exclusive" 25 | 26 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --extra-files-only --quick" 27 | assert_status_is "$SWUPD_INVALID_OPTION" 28 | assert_in_output "Error: --quick and --extra-files-only options are mutually exclusive" 29 | 30 | # --picky & --extra-files-only 31 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --picky --extra-files-only" 32 | assert_status_is "$SWUPD_INVALID_OPTION" 33 | assert_in_output "Error: --extra-files-only and --picky options are mutually exclusive" 34 | 35 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS --extra-files-only --picky" 36 | assert_status_is "$SWUPD_INVALID_OPTION" 37 | assert_in_output "Error: --extra-files-only and --picky options are mutually exclusive" 38 | 39 | } 40 | #WEIGHT=1 41 | -------------------------------------------------------------------------------- /test/functional/repair/repair-format-mismatch.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 10 1 11 | bump_format "$TEST_NAME" 12 | create_version -r "$TEST_NAME" 40 30 2 13 | 14 | } 15 | 16 | @test "REP017: Repair enforces the use of the correct format" { 17 | 18 | run sudo sh -c "$SWUPD repair --format=1 --version=40 $SWUPD_OPTS_NO_FMT" 19 | 20 | assert_status_is "$SWUPD_COULDNT_LOAD_MANIFEST" 21 | expected_output=$(cat <<-EOM 22 | Diagnosing version 40 23 | Error: Mismatching formats detected when diagnosing 40 (expected: 1; actual: 2) 24 | Latest supported version to diagnose: 20 25 | Repair did not fully succeed 26 | EOM 27 | ) 28 | assert_is_output "$expected_output" 29 | 30 | } 31 | #WEIGHT=7 32 | -------------------------------------------------------------------------------- /test/functional/repair/repair-ghosted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 11 | create_bundle -L -n os-core -f /foo "$TEST_NAME" 12 | update_manifest "$WEB_DIR"/10/Manifest.os-core file-status /foo .g.. 13 | 14 | } 15 | 16 | @test "REP019: Repair does not delete ghosted files from the system" { 17 | 18 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 19 | 20 | assert_status_is "$SWUPD_OK" 21 | expected_output=$(cat <<-EOM 22 | Diagnosing version 10 23 | Downloading missing manifests... 24 | Checking for corrupt files 25 | Adding any missing files 26 | Repairing corrupt files 27 | Removing extraneous files 28 | Inspected 2 files 29 | Calling post-update helper scripts 30 | Repair successful 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | # this should exist at the end, despite being marked as "ghosted" in the 35 | # Manifest and treated as deleted for parts of swupd-client. 36 | assert_file_exists "$TARGET_DIR"/foo 37 | 38 | } 39 | #WEIGHT=2 40 | -------------------------------------------------------------------------------- /test/functional/repair/repair-missing-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle -f /foo/test-file1,/bar/test-file2 "$TEST_NAME" 12 | # remove a directory and file that are part of the bundle 13 | sudo rm -rf "$TARGET_DIR"/foo/test-file1 14 | 15 | } 16 | 17 | @test "REP021: Repair a system that is missing a file" { 18 | 19 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 20 | 21 | assert_status_is "$SWUPD_OK" 22 | expected_output=$(cat <<-EOM 23 | Diagnosing version 10 24 | Downloading missing manifests... 25 | Checking for corrupt files 26 | Validate downloaded files 27 | Starting download of remaining update content. This may take a while... 28 | Adding any missing files 29 | .* Missing file: .*/target-dir/foo/test-file1 -> fixed 30 | Repairing corrupt files 31 | Removing extraneous files 32 | Inspected 7 files 33 | 1 file was missing 34 | 1 of 1 missing files were replaced 35 | 0 of 1 missing files were not replaced 36 | Calling post-update helper scripts 37 | Repair successful 38 | EOM 39 | ) 40 | assert_regex_is_output "$expected_output" 41 | assert_file_exists "$TARGET_DIR"/foo/test-file1 42 | assert_file_exists "$TARGET_DIR"/bar/test-file2 43 | 44 | } 45 | #WEIGHT=2 46 | -------------------------------------------------------------------------------- /test/functional/repair/repair-picky-ghosted-missing.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 11 | create_bundle -L -n test-bundle -f /usr/foo -d/usr/share/clear/bundles "$TEST_NAME" 12 | update_manifest "$WEB_DIR"/10/Manifest.test-bundle file-status /usr/foo .g.. 13 | # since the files must have been installed by the -L option, remove /usr/foo 14 | sudo rm -f "$TARGET_DIR"/usr/foo 15 | 16 | } 17 | 18 | @test "REP029: When repairing ghosted files are not added during --picky" { 19 | 20 | run sudo sh -c "$SWUPD repair --picky $SWUPD_OPTS" 21 | 22 | assert_status_is "$SWUPD_OK" 23 | expected_output=$(cat <<-EOM 24 | Diagnosing version 10 25 | Downloading missing manifests... 26 | Checking for corrupt files 27 | Adding any missing files 28 | Repairing corrupt files 29 | Removing extraneous files 30 | Removing extra files under $ABS_TARGET_DIR/usr 31 | -> Extra file: $ABS_TARGET_DIR/usr/share/defaults/swupd/versionurl -> deleted 32 | -> Extra file: $ABS_TARGET_DIR/usr/share/defaults/swupd/contenturl -> deleted 33 | Inspected 15 files 34 | 2 files found which should be deleted 35 | 2 of 2 files were deleted 36 | 0 of 2 files were not deleted 37 | Calling post-update helper scripts 38 | Repair successful 39 | EOM 40 | ) 41 | assert_is_output "$expected_output" 42 | # this should not exist at the end, despite being marked in the Manifest as 43 | # "ghosted". In this case ghosted files should be ignored. 44 | assert_file_not_exists "$TARGET_DIR"/usr/foo 45 | 46 | } 47 | #WEIGHT=4 48 | -------------------------------------------------------------------------------- /test/functional/repair/repair-picky-ghosted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 11 | create_bundle -L -n test-bundle -f /usr/foo -d/usr/share/clear/bundles "$TEST_NAME" 12 | update_manifest "$WEB_DIR"/10/Manifest.test-bundle file-status /usr/foo .g.. 13 | 14 | } 15 | 16 | @test "REP028: When repairing ghosted files are skipped during --picky" { 17 | 18 | run sudo sh -c "$SWUPD repair --picky $SWUPD_OPTS" 19 | 20 | assert_status_is "$SWUPD_OK" 21 | expected_output=$(cat <<-EOM 22 | Diagnosing version 10 23 | Downloading missing manifests... 24 | Checking for corrupt files 25 | Adding any missing files 26 | Repairing corrupt files 27 | Removing extraneous files 28 | Removing extra files under $ABS_TARGET_DIR/usr 29 | -> Extra file: $ABS_TARGET_DIR/usr/share/defaults/swupd/versionurl -> deleted 30 | -> Extra file: $ABS_TARGET_DIR/usr/share/defaults/swupd/contenturl -> deleted 31 | Inspected 15 files 32 | 2 files found which should be deleted 33 | 2 of 2 files were deleted 34 | 0 of 2 files were not deleted 35 | Calling post-update helper scripts 36 | Repair successful 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | # this should exist at the end, despite being marked as "ghosted" in the 41 | # Manifest. With the ghosted file existing under /usr this test is to make 42 | # sure the ghosted files aren't removed during the --picky flow. 43 | assert_file_exists "$TARGET_DIR"/usr/foo 44 | 45 | } 46 | #WEIGHT=4 47 | -------------------------------------------------------------------------------- /test/functional/repair/repair-skip-scripts.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle -f /usr/lib/kernel/testfile "$TEST_NAME" 12 | create_version "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" test-bundle --delete /usr/lib/kernel/testfile 14 | set_current_version "$TEST_NAME" 20 15 | 16 | } 17 | 18 | @test "REP030: Repair can skip running the post-update scripts and boot update tool" { 19 | 20 | run sudo sh -c "$SWUPD repair --no-scripts $SWUPD_OPTS" 21 | 22 | assert_status_is "$SWUPD_OK" 23 | # check for the warning 24 | expected_output=$(cat <<-EOM 25 | Diagnosing version 20 26 | Downloading missing manifests... 27 | Checking for corrupt files 28 | Adding any missing files 29 | Repairing corrupt files 30 | Removing extraneous files 31 | Inspected 7 files 32 | Warning: post-update helper scripts skipped due to --no-scripts argument 33 | Repair successful 34 | EOM 35 | ) 36 | assert_is_output "$expected_output" 37 | # this should exist at the end, even if the scripts are not run 38 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 39 | 40 | } 41 | #WEIGHT=4 42 | -------------------------------------------------------------------------------- /test/functional/repair/repair-unsafe-to-delete.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle -c /foo -f /foo/file1,/foo/file2,/bar/file3 "$TEST_NAME" 12 | create_version "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" test-bundle --delete /foo/file1 14 | set_current_version "$TEST_NAME" 20 15 | 16 | } 17 | 18 | @test "REP014: Repair a system with extra files that are unsafe to delete" { 19 | 20 | # when running repair and there are extra files, but the extra 21 | # files are found not safe to be deleted, they should be skipped and 22 | # users should not be notified about these 23 | 24 | run sudo sh -c "$SWUPD repair $SWUPD_OPTS" 25 | 26 | assert_status_is "$SWUPD_OK" 27 | expected_output=$(cat <<-EOM 28 | Diagnosing version 20 29 | Downloading missing manifests... 30 | Checking for corrupt files 31 | Adding any missing files 32 | Repairing corrupt files 33 | Removing extraneous files 34 | Inspected 9 files 35 | Calling post-update helper scripts 36 | Repair successful 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | 41 | } 42 | #WEIGHT=4 43 | -------------------------------------------------------------------------------- /test/functional/repair/repair-version-mismatch-overdrive.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -e "$TEST_NAME" 11 | create_bundle -L -n os-core -d /usr/bin "$TEST_NAME" 12 | create_version "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" os-core --header-only 14 | set_current_version "$TEST_NAME" 20 15 | # remove /usr/bin so it is missing in the target system 16 | sudo rm -rf "$TARGET_DIR"/usr/bin 17 | 18 | } 19 | 20 | @test "REP016: Repair can be forced to continue when there is a version mismatch" { 21 | 22 | run sudo sh -c "$SWUPD repair -m 10 --force $SWUPD_OPTS" 23 | 24 | assert_status_is "$SWUPD_OK" 25 | expected_output=$(cat <<-EOM 26 | Diagnosing version 10 27 | Warning: The --force option is specified; ignoring version mismatch for repair 28 | Downloading missing manifests... 29 | Checking for corrupt files 30 | Validate downloaded files 31 | Starting download of remaining update content. This may take a while... 32 | Adding any missing files 33 | -> Missing file: $ABS_TEST_DIR/testfs/target-dir/usr/bin -> fixed 34 | Repairing corrupt files 35 | Removing extraneous files 36 | Inspected 3 files 37 | 1 file was missing 38 | 1 of 1 missing files were replaced 39 | 0 of 1 missing files were not replaced 40 | Calling post-update helper scripts 41 | Repair successful 42 | EOM 43 | ) 44 | assert_is_output "$expected_output" 45 | 46 | } 47 | #WEIGHT=2 48 | -------------------------------------------------------------------------------- /test/functional/repair/repair-version-mismatch.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_version "$TEST_NAME" 20 10 12 | update_bundle "$TEST_NAME" os-core --add-dir /usr/bin 13 | set_current_version "$TEST_NAME" 20 14 | 15 | } 16 | 17 | @test "REP015: Repair enforces the use of the correct version" { 18 | 19 | run sudo sh -c "$SWUPD repair -m 10 $SWUPD_OPTS" 20 | assert_status_is "$SWUPD_INVALID_OPTION" 21 | expected_output=$(cat <<-EOM 22 | Diagnosing version 10 23 | Error: Repairing to a different version requires --force or --picky 24 | Repair did not fully succeed 25 | EOM 26 | ) 27 | assert_is_output "$expected_output" 28 | 29 | } 30 | #WEIGHT=2 31 | -------------------------------------------------------------------------------- /test/functional/search/search-content-check-negative.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -n test-bundle -f /foo/test-file1,/usr/lib/test-lib32,/libtest-nohit "$TEST_NAME" 9 | 10 | } 11 | 12 | teardown_file() { 13 | 14 | destroy_test_environment --force "$TEST_NAME" 15 | 16 | } 17 | 18 | @test "SRH009: Try searching for a file that does not exist" { 19 | 20 | # the first time we run search it needs to download the 21 | # manifests, so we need to account for those messages in 22 | # this first test 23 | 24 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS fake-file" 25 | 26 | assert_status_is "$SWUPD_NO" 27 | expected_output=$(cat <<-EOM 28 | Downloading all Clear Linux manifests 29 | Searching for 'fake-file' 30 | Search term not found 31 | EOM 32 | ) 33 | assert_is_output "$expected_output" 34 | 35 | } 36 | 37 | @test "SRH010: Try searching for a file that does not exist using the full path" { 38 | 39 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS /usr/lib64/test-lib100" 40 | 41 | assert_status_is "$SWUPD_NO" 42 | expected_output=$(cat <<-EOM 43 | Downloading all Clear Linux manifests 44 | Searching for '/usr/lib64/test-lib100' 45 | Search term not found 46 | EOM 47 | ) 48 | assert_regex_is_output "$expected_output" 49 | 50 | } 51 | 52 | @test "SRH011: Try searching for a library that does not exist" { 53 | 54 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS -l libtest-nohit" 55 | 56 | assert_status_is "$SWUPD_NO" 57 | expected_output=$(cat <<-EOM 58 | Downloading all Clear Linux manifests 59 | Searching for 'libtest-nohit' 60 | Search term not found 61 | EOM 62 | ) 63 | assert_is_output "$expected_output" 64 | 65 | } 66 | 67 | #WEIGHT=3 68 | -------------------------------------------------------------------------------- /test/functional/search/search-version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle1 -f /foo/file_1 "$TEST_NAME" 12 | create_version -p "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" test-bundle1 --add /bar/file_2 14 | set_current_version "$TEST_NAME" 10 15 | 16 | } 17 | 18 | @test "SRH030: Search for a file specifying the version" { 19 | 20 | # Users should be able to search for files in specific versions of Clear 21 | # using the --version option 22 | 23 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS file_2" 24 | 25 | assert_status_is "$SWUPD_NO" 26 | expected_output=$(cat <<-EOM 27 | Downloading all Clear Linux manifests 28 | Searching for 'file_2' 29 | Search term not found 30 | EOM 31 | ) 32 | assert_is_output "$expected_output" 33 | 34 | run sudo sh -c "$SWUPD search-file $SWUPD_OPTS file_2 --version 20" 35 | 36 | assert_status_is "$SWUPD_OK" 37 | expected_output=$(cat <<-EOM 38 | Downloading all Clear Linux manifests 39 | Searching for 'file_2' 40 | Bundle test-bundle1 \\(0 MB to install\\) 41 | ./bar/file_2 42 | EOM 43 | ) 44 | assert_regex_is_output "$expected_output" 45 | 46 | } 47 | #WEIGHT=3 48 | -------------------------------------------------------------------------------- /test/functional/signature/corrupted-certificate.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle -f /test-file "$TEST_NAME" 12 | write_to_protected_file "$TEST_NAME"/cert "invalid" 13 | 14 | } 15 | 16 | @test "SIG001: Swupd bundle-add with corrupted certificate" { 17 | 18 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS_NO_CERT -C $TEST_NAME/cert test-bundle" 19 | 20 | assert_status_is "$SWUPD_SIGNATURE_VERIFICATION_FAILED" 21 | expected_output=$(cat <<-EOM 22 | Error: Failed to verify certificate: unknown certificate verification error 23 | Error: Failed swupd initialization, exiting now 24 | EOM 25 | ) 26 | assert_regex_is_output "$expected_output" 27 | assert_file_not_exists "$TARGET_DIR"/test-file 28 | 29 | } 30 | 31 | @test "SIG002: Force swupd bundle-add a bundle with corrupted certificate" { 32 | 33 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS_NO_CERT -C $TEST_NAME/cert --nosigcheck test-bundle" 34 | 35 | assert_status_is "$SWUPD_OK" 36 | expected_output=$(cat <<-EOM 37 | Warning: The --nosigcheck flag was used and this compromises the system security 38 | Warning: THE SIGNATURE OF file://$ABS_TEST_DIR/web-dir/10/Manifest.MoM WILL NOT BE VERIFIED 39 | Loading required manifests... 40 | No packs need to be downloaded 41 | Validate downloaded files 42 | Starting download of remaining update content. This may take a while... 43 | Installing files... 44 | Calling post-update helper scripts 45 | Successfully installed 1 bundle 46 | EOM 47 | ) 48 | assert_is_output "$expected_output" 49 | assert_file_exists "$TARGET_DIR"/test-file 50 | 51 | } 52 | #WEIGHT=4 53 | -------------------------------------------------------------------------------- /test/functional/signature/no-signature.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle -f /test-file "$TEST_NAME" 12 | sudo rm "$WEB_DIR"/10/Manifest.MoM.sig 13 | 14 | } 15 | 16 | @test "SIG007: Swupd bundle-add without a MoM signature" { 17 | 18 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle" 19 | 20 | assert_status_is "$SWUPD_COULDNT_LOAD_MOM" 21 | expected_output=$(cat <<-EOM 22 | Warning: Removing corrupt Manifest.MoM artifacts and re-downloading... 23 | Error: Signature verification failed for manifest version 10 24 | Error: Cannot load official manifest MoM for version 10 25 | Failed to install 1 of 1 bundles 26 | EOM 27 | ) 28 | assert_is_output "$expected_output" 29 | assert_file_not_exists "$TARGET_DIR"/test-file 30 | 31 | } 32 | 33 | @test "SIG008: Force swupd bundle-add a bundle without a MoM signature" { 34 | 35 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS --nosigcheck test-bundle" 36 | 37 | assert_status_is "$SWUPD_OK" 38 | expected_output=$(cat <<-EOM 39 | Warning: The --nosigcheck flag was used and this compromises the system security 40 | Warning: THE SIGNATURE OF file://$ABS_TEST_DIR/web-dir/10/Manifest.MoM WILL NOT BE VERIFIED 41 | Loading required manifests... 42 | No packs need to be downloaded 43 | Validate downloaded files 44 | Starting download of remaining update content. This may take a while... 45 | Installing files... 46 | Calling post-update helper scripts 47 | Successfully installed 1 bundle 48 | EOM 49 | ) 50 | assert_is_output "$expected_output" 51 | assert_file_exists "$TARGET_DIR"/test-file 52 | 53 | } 54 | #WEIGHT=4 55 | -------------------------------------------------------------------------------- /test/functional/signature/valid-certificate.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -n test-bundle -f /test-file "$TEST_NAME" 12 | 13 | # Resign release 14 | sudo rm "$WEB_DIR"/version/latest_version.sig 15 | sudo rm "$WEB_DIR"/version/formatstaging/latest.sig 16 | sudo rm "$WEB_DIR"/10/Manifest.MoM.sig 17 | 18 | sudo sh -c "openssl req -x509 -sha512 -days 1 -newkey rsa:4096 -keyout $TEST_NAME/root.key -out $TEST_NAME/root.pem -nodes -subj '/C=US/ST=Oregon/L=Portland/O=Company Name/OU=Org/CN=localhost'" 19 | sudo sh -c "openssl smime -sign -binary -in $WEB_DIR/10/Manifest.MoM -signer $TEST_NAME/root.pem -inkey $TEST_NAME/root.key -out $WEB_DIR/10/Manifest.MoM.sig -outform DER" 20 | 21 | } 22 | 23 | @test "SIG024: Swupd bundle-add with valid certificate" { 24 | 25 | # Operations should work when using a custom valid certificate 26 | 27 | run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS_NO_CERT -C $TEST_NAME/root.pem test-bundle" 28 | 29 | assert_status_is "$SWUPD_OK" 30 | 31 | } 32 | #WEIGHT=2 33 | -------------------------------------------------------------------------------- /test/functional/update/update-boot-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --add /usr/lib/kernel/testfile 10 | 11 | } 12 | 13 | @test "UPD007: Updating a system where a boot file was added in the newer version" { 14 | 15 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 16 | assert_status_is 0 17 | expected_output=$(cat <<-EOM 18 | Update started 19 | Preparing to update from 10 to 100 (in format staging) 20 | Downloading packs for: 21 | - os-core 22 | Finishing packs extraction... 23 | Statistics for going from version 10 to version 100: 24 | changed bundles : 1 25 | new bundles : 0 26 | deleted bundles : 0 27 | changed files : 0 28 | new files : 4 29 | deleted files : 0 30 | Validate downloaded files 31 | No extra files need to be downloaded 32 | Installing files... 33 | Update was applied 34 | Calling post-update helper scripts 35 | Warning: helper script ($ABS_TEST_DIR/testfs/target-dir/usr/bin/clr-boot-manager) not found, it will be skipped 36 | Update successful - System updated from version 10 to version 100 37 | EOM 38 | ) 39 | assert_is_output "$expected_output" 40 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 41 | 42 | } 43 | #WEIGHT=2 44 | -------------------------------------------------------------------------------- /test/functional/update/update-boot-file.ignore-list: -------------------------------------------------------------------------------- 1 | Update took .* 2 | Compile-time options:.* 3 | Compile-time configuration: 4 | mount point.* 5 | state directory.* 6 | bundles directory.* 7 | certificate path.* 8 | fallback certificate path.* 9 | content URL.* 10 | version URL.* 11 | format ID.* 12 | pre-update hook.* 13 | post-update hook.* 14 | -------------------------------------------------------------------------------- /test/functional/update/update-boot-skip.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --add /usr/lib/kernel/testfile 10 | 11 | } 12 | 13 | @test "UPD031: Updating a system where a boot file was added but not updated in the newer version" { 14 | 15 | run sudo sh -c "$SWUPD update --no-boot-update $SWUPD_OPTS" 16 | 17 | assert_status_is 0 18 | expected_output=$(cat <<-EOM 19 | Update started 20 | Preparing to update from 10 to 100 (in format staging) 21 | Downloading packs for: 22 | - os-core 23 | Finishing packs extraction... 24 | Statistics for going from version 10 to version 100: 25 | changed bundles : 1 26 | new bundles : 0 27 | deleted bundles : 0 28 | changed files : 0 29 | new files : 4 30 | deleted files : 0 31 | Validate downloaded files 32 | No extra files need to be downloaded 33 | Installing files... 34 | Update was applied 35 | Calling post-update helper scripts 36 | Warning: boot files update skipped due to --no-boot-update argument 37 | Update successful - System updated from version 10 to version 100 38 | EOM 39 | ) 40 | assert_is_output "$expected_output" 41 | assert_file_exists "$TARGET_DIR"/usr/lib/kernel/testfile 42 | 43 | } 44 | #WEIGHT=3 45 | -------------------------------------------------------------------------------- /test/functional/update/update-bundle-removed.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment -r "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /file_1 "$TEST_NAME" 12 | create_version -r "$TEST_NAME" 20 10 13 | remove_from_manifest "$WEB_DIR"/20/Manifest.MoM test-bundle1 14 | 15 | } 16 | 17 | @test "UPD008: Updating a system where a bundle was removed in the newer version" { 18 | 19 | # If a bundle happens to be removed from the content server (or mix) it means the 20 | # bundle won't be in the MoM anymore, this now indicates a bundle delete. 21 | 22 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 23 | 24 | assert_status_is 0 25 | expected_output=$(cat <<-EOM 26 | Update started 27 | Preparing to update from 10 to 20 (in format staging) 28 | Downloading packs for: 29 | - os-core 30 | Finishing packs extraction... 31 | Statistics for going from version 10 to version 20: 32 | changed bundles : 1 33 | new bundles : 0 34 | deleted bundles : 1 35 | changed files : 2 36 | new files : 0 37 | deleted files : 2 38 | Validate downloaded files 39 | No extra files need to be downloaded 40 | Installing files... 41 | Update was applied 42 | Calling post-update helper scripts 43 | Update successful - System updated from version 10 to version 20 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | # bundle should not be removed 48 | assert_file_not_exists "$TARGET_DIR"/file_1 49 | assert_file_not_exists "$TARGET_DIR"/usr/share/clear/bundles/test-bundle1 50 | 51 | } 52 | #WEIGHT=5 53 | -------------------------------------------------------------------------------- /test/functional/update/update-deleted-include-manifest.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: John Akre 4 | # Email: john.w.akre@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /foo/testfile1 "$TEST_NAME" 12 | create_bundle -n test-bundle2 -f /bar/testfile2 "$TEST_NAME" 13 | create_version -p "$TEST_NAME" 100 10 14 | update_bundle "$TEST_NAME" test-bundle1 --header-only 15 | add_dependency_to_manifest "$WEB_DIR"/100/Manifest.test-bundle1 test-bundle2 16 | 17 | # Delete the included manifest 18 | sudo rm "$WEB_DIR"/10/Manifest.test-bundle2 19 | sudo rm "$WEB_DIR"/10/pack-test-bundle2-from-0.tar 20 | sudo rm "$WEB_DIR"/10/Manifest.test-bundle2.tar 21 | 22 | } 23 | 24 | @test "UPD058: Report error when an included manifest is deleted" { 25 | 26 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 27 | 28 | assert_status_is "$SWUPD_RECURSE_MANIFEST" 29 | expected_output=$(cat <<-EOM 30 | Update started 31 | Preparing to update from 10 to 100 (in format staging) 32 | Error: Failed to retrieve 10 test-bundle2 manifest 33 | Error: Unable to download manifest test-bundle2 version 10, exiting now 34 | Update failed 35 | EOM 36 | ) 37 | assert_is_output "$expected_output" 38 | 39 | } 40 | #WEIGHT=4 41 | -------------------------------------------------------------------------------- /test/functional/update/update-download.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --add /foo 10 | 11 | } 12 | 13 | @test "UPD032: Download the update content only" { 14 | 15 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --download" 16 | 17 | assert_status_is 0 18 | expected_output=$(cat <<-EOM 19 | Update started 20 | Preparing to update from 10 to 100 (in format staging) 21 | Downloading packs for: 22 | - os-core 23 | Finishing packs extraction... 24 | Statistics for going from version 10 to version 100: 25 | changed bundles : 1 26 | new bundles : 0 27 | deleted bundles : 0 28 | changed files : 0 29 | new files : 1 30 | deleted files : 0 31 | Validate downloaded files 32 | No extra files need to be downloaded 33 | EOM 34 | ) 35 | assert_is_output "$expected_output" 36 | assert_file_not_exists "$TARGET_DIR"/foo 37 | } 38 | 39 | #WEIGHT=2 40 | -------------------------------------------------------------------------------- /test/functional/update/update-fail-to-get-mom.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 20 10 9 | 10 | } 11 | 12 | @test "UPD009: Try updating a system where the 'from' MoM is not found" { 13 | 14 | # remove the "from" mom 15 | sudo rm -rf "$WEB_DIR"/10/Manifest.MoM.tar 16 | 17 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 18 | 19 | assert_status_is "$SWUPD_COULDNT_LOAD_MOM" 20 | expected_output=$(cat <<-EOM 21 | Update started 22 | Preparing to update from 10 to 20 \(in format staging\) 23 | Error: Failed to retrieve 10 MoM manifest 24 | Update failed 25 | EOM 26 | ) 27 | assert_regex_is_output "$expected_output" 28 | 29 | } 30 | 31 | @test "UPD010: Try updating a system where the 'to' MoM is not found" { 32 | 33 | # remove the "to" mom 34 | sudo rm -rf "$WEB_DIR"/20/Manifest.MoM.tar 35 | 36 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 37 | 38 | assert_status_is "$SWUPD_COULDNT_LOAD_MOM" 39 | expected_output=$(cat <<-EOM 40 | Update started 41 | Preparing to update from 10 to 20 \(in format staging\) 42 | Error: Failed to retrieve 20 MoM manifest 43 | Update failed 44 | EOM 45 | ) 46 | assert_regex_is_output "$expected_output" 47 | 48 | } 49 | #WEIGHT=3 50 | -------------------------------------------------------------------------------- /test/functional/update/update-include-old-bundle.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle1 -f /testfile1 "$TEST_NAME" 9 | create_bundle -n test-bundle2 -f /testfile2 "$TEST_NAME" 10 | create_version -p "$TEST_NAME" 100 10 11 | update_bundle "$TEST_NAME" test-bundle1 --update /testfile1 12 | add_dependency_to_manifest "$WEB_DIR"/100/Manifest.test-bundle1 test-bundle2 13 | 14 | } 15 | 16 | @test "UPD012: Update a system where an old dependency is added in the newer version" { 17 | 18 | # the "old" dependency is one that was not updated in the last version 19 | 20 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 21 | 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | Update started 25 | Preparing to update from 10 to 100 (in format staging) 26 | Downloading packs for: 27 | - test-bundle2 28 | - test-bundle1 29 | Finishing packs extraction... 30 | Statistics for going from version 10 to version 100: 31 | changed bundles : 1 32 | new bundles : 0 33 | deleted bundles : 0 34 | changed files : 1 35 | new files : 2 36 | deleted files : 0 37 | Validate downloaded files 38 | No extra files need to be downloaded 39 | Installing files... 40 | Update was applied 41 | Calling post-update helper scripts 42 | Update successful - System updated from version 10 to version 100 43 | EOM 44 | ) 45 | assert_is_output "$expected_output" 46 | # changed files 47 | assert_file_exists "$TARGET_DIR"/testfile1 48 | # new file 49 | assert_file_exists "$TARGET_DIR"/testfile2 50 | 51 | } 52 | 53 | #WEIGHT=4 54 | -------------------------------------------------------------------------------- /test/functional/update/update-minversion.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 10 8 | create_bundle -L -n bundle1 -v 10 -f /file1 "$TEST_NAME" 9 | 10 | create_version "$TEST_NAME" 20 10 staging 11 | set_as_minversion "$WEB_DIR"/20 12 | 13 | sudo rm -rf "$WEB_DIR"/20/files/* 14 | } 15 | 16 | @test "UPD015: Skip fullfile download for unchanged file in minversion update" { 17 | 18 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 19 | assert_status_is 0 20 | 21 | expected_output=$(cat <<-EOM 22 | Update started 23 | Preparing to update from 10 to 20 (in format staging) 24 | Downloading packs for: 25 | - bundle1 26 | - os-core 27 | Finishing packs extraction... 28 | Statistics for going from version 10 to version 20: 29 | changed bundles : 2 30 | new bundles : 0 31 | deleted bundles : 0 32 | changed files : 4 33 | new files : 0 34 | deleted files : 0 35 | Validate downloaded files 36 | Installing files... 37 | Update was applied 38 | Calling post-update helper scripts 39 | Update successful - System updated from version 10 to version 20 40 | EOM 41 | ) 42 | assert_in_output "$expected_output" 43 | } 44 | #WEIGHT=3 45 | -------------------------------------------------------------------------------- /test/functional/update/update-missing-os-core.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -e "$TEST_NAME" 8 | create_bundle -n os-core -f /os-core "$TEST_NAME" 9 | create_bundle -L -n test-bundle -f /foo/testfile2 "$TEST_NAME" 10 | create_version -p "$TEST_NAME" 100 10 11 | update_bundle "$TEST_NAME" os-core --add /testfile1 12 | update_bundle "$TEST_NAME" test-bundle --update /foo/testfile2 13 | 14 | } 15 | 16 | @test "UPD014: Update always adds os-core to tracked bundles" { 17 | 18 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 19 | 20 | assert_status_is 0 21 | expected_output=$(cat <<-EOM 22 | Update started 23 | Preparing to update from 10 to 100 (in format staging) 24 | Downloading packs for: 25 | - os-core 26 | - test-bundle 27 | Finishing packs extraction... 28 | Statistics for going from version 10 to version 100: 29 | changed bundles : 2 30 | new bundles : 0 31 | deleted bundles : 0 32 | changed files : 1 33 | new files : 1 34 | deleted files : 0 35 | Validate downloaded files 36 | No extra files need to be downloaded 37 | Installing files... 38 | Update was applied 39 | Calling post-update helper scripts 40 | Update successful - System updated from version 10 to version 100 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | assert_file_exists "$TARGET_DIR"/testfile1 45 | 46 | } 47 | #WEIGHT=4 48 | -------------------------------------------------------------------------------- /test/functional/update/update-newest-added.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_bundle -L -n test-bundle1 -f /file_1,/foo/file_2 "$TEST_NAME" 12 | create_version -p "$TEST_NAME" 20 10 13 | update_bundle "$TEST_NAME" test-bundle1 --add /bar/file_3 14 | 15 | } 16 | 17 | @test "UPD001: Updating a system where a file was added in the newer version" { 18 | 19 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 20 | 21 | assert_status_is 0 22 | expected_output=$(cat <<-EOM 23 | Update started 24 | Preparing to update from 10 to 20 (in format staging) 25 | Downloading packs for: 26 | - test-bundle1 27 | Finishing packs extraction... 28 | Statistics for going from version 10 to version 20: 29 | changed bundles : 1 30 | new bundles : 0 31 | deleted bundles : 0 32 | changed files : 0 33 | new files : 2 34 | deleted files : 0 35 | Validate downloaded files 36 | No extra files need to be downloaded 37 | Installing files... 38 | Update was applied 39 | Calling post-update helper scripts 40 | Update successful - System updated from version 10 to version 20 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | 45 | } 46 | #WEIGHT=3 47 | -------------------------------------------------------------------------------- /test/functional/update/update-newest-ghosted.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --ghost /core 10 | 11 | } 12 | 13 | @test "UPD004: Updating a system where a file was ghosted in the newer version" { 14 | 15 | # NOTE: we don't create delta packs when a file is ghosted in an update with the test library 16 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 17 | 18 | assert_status_is 0 19 | expected_output=$(cat <<-EOM 20 | Update started 21 | Preparing to update from 10 to 100 (in format staging) 22 | Downloading packs for: 23 | - os-core 24 | Finishing packs extraction... 25 | Statistics for going from version 10 to version 100: 26 | changed bundles : 1 27 | new bundles : 0 28 | deleted bundles : 0 29 | changed files : 0 30 | new files : 0 31 | deleted files : 1 32 | Validate downloaded files 33 | No extra files need to be downloaded 34 | Installing files... 35 | Update was applied 36 | Calling post-update helper scripts 37 | Update successful - System updated from version 10 to version 100 38 | EOM 39 | ) 40 | assert_is_output "$expected_output" 41 | assert_file_exists "$TARGET_DIR"/core 42 | 43 | } 44 | #WEIGHT=2 45 | -------------------------------------------------------------------------------- /test/functional/update/update-older-server-version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 10 8 | 9 | } 10 | 11 | @test "UPD019: Try updating a system where the server is older than the target system" { 12 | 13 | set_current_version "$TEST_NAME" 20 14 | 15 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 16 | 17 | assert_status_is 0 18 | expected_output=$(cat <<-EOM 19 | Update started 20 | Version on server (10) is not newer than system version (20) 21 | Update complete - System already up-to-date at version 20 22 | EOM 23 | ) 24 | assert_is_output "$expected_output" 25 | 26 | } 27 | 28 | @test "UPD020: Try updating a system where there is no server version file available" { 29 | 30 | sudo rm -rf "$WEB_DIR"/version 31 | 32 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 33 | 34 | assert_status_is "$SWUPD_SERVER_CONNECTION_ERROR" 35 | expected_output=$(cat <<-EOM 36 | Error: Unable to determine the server version 37 | Update failed 38 | EOM 39 | ) 40 | assert_in_output "$expected_output" 41 | 42 | } 43 | 44 | @test "UPD021: Try updating a system where there is no target version file available" { 45 | 46 | sudo rm -rf "$TARGET_DIR"/usr/lib/os-release 47 | 48 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 49 | 50 | assert_status_is "$SWUPD_CURRENT_VERSION_UNKNOWN" 51 | expected_output=$(cat <<-EOM 52 | Update started 53 | Error: Unable to determine current OS version 54 | Warning: Unable to determine current OS version 55 | Update failed 56 | EOM 57 | ) 58 | assert_is_output "$expected_output" 59 | 60 | } 61 | #WEIGHT=3 62 | -------------------------------------------------------------------------------- /test/functional/update/update-re-update-bad-os-release.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -r "$TEST_NAME" 10 1 8 | bump_format "$TEST_NAME" 9 | create_version -r "$TEST_NAME" 40 30 2 10 | # remove the os-release file from all manifests 11 | remove_from_manifest "$WEB_DIR"/10/Manifest.os-core /usr/lib/os-release 12 | remove_from_manifest "$WEB_DIR"/20/Manifest.os-core /usr/lib/os-release 13 | remove_from_manifest "$WEB_DIR"/30/Manifest.os-core /usr/lib/os-release 14 | remove_from_manifest "$WEB_DIR"/40/Manifest.os-core /usr/lib/os-release 15 | 16 | } 17 | 18 | @test "UPD024: Try updating a system across a format bump with a bad os-release file" { 19 | 20 | run sudo sh -c "$SWUPD update $SWUPD_OPTS_NO_FMT" 21 | 22 | assert_status_is "$SWUPD_CURRENT_VERSION_UNKNOWN" 23 | expected_output=$(cat <<-EOM 24 | Update started 25 | Preparing to update from 10 to 20 (in format 1) 26 | Downloading packs for: 27 | - os-core 28 | Finishing packs extraction... 29 | Statistics for going from version 10 to version 20: 30 | changed bundles : 1 31 | new bundles : 0 32 | deleted bundles : 0 33 | changed files : 1 34 | new files : 0 35 | deleted files : 0 36 | Validate downloaded files 37 | No extra files need to be downloaded 38 | Installing files... 39 | Update was applied 40 | Calling post-update helper scripts 41 | Update successful - System updated from version 10 to version 20 42 | Error: Inconsistency between version files, exiting now 43 | EOM 44 | ) 45 | assert_is_output "$expected_output" 46 | assert_file_exists "$TARGET_DIR"/core 47 | 48 | } 49 | #WEIGHT=8 50 | -------------------------------------------------------------------------------- /test/functional/update/update-rename.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle -f /foo/testfile1,/foo/testfile3 "$TEST_NAME" 9 | create_version -p "$TEST_NAME" 100 10 10 | update_bundle "$TEST_NAME" test-bundle --rename /foo/testfile3:/foo/testfile2 11 | 12 | } 13 | 14 | @test "UPD002: Updating a system where a file was renamed in the newer version" { 15 | 16 | # renames are now considered a deletion of a file + an addition 17 | # of a file, so the rename flags are not used anymore in manifests 18 | 19 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 20 | 21 | assert_status_is 0 22 | expected_output=$(cat <<-EOM 23 | Update started 24 | Preparing to update from 10 to 100 (in format staging) 25 | Downloading packs for: 26 | - test-bundle 27 | Finishing packs extraction... 28 | Statistics for going from version 10 to version 100: 29 | changed bundles : 1 30 | new bundles : 0 31 | deleted bundles : 0 32 | changed files : 0 33 | new files : 1 34 | deleted files : 1 35 | Validate downloaded files 36 | No extra files need to be downloaded 37 | Installing files... 38 | Update was applied 39 | Calling post-update helper scripts 40 | Update successful - System updated from version 10 to version 100 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | assert_file_exists "$TARGET_DIR"/foo/testfile2 45 | assert_file_not_exists "$TARGET_DIR"/foo/testfile3 46 | 47 | } 48 | #WEIGHT=3 49 | -------------------------------------------------------------------------------- /test/functional/update/update-skip-scripts.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --update /core 10 | update_bundle "$TEST_NAME" os-core --add /testfile 11 | 12 | } 13 | 14 | @test "UPD033: Updating a system without running the post-update scripts" { 15 | 16 | run sudo sh -c "$SWUPD update --no-scripts $SWUPD_OPTS" 17 | 18 | # Should still be successful 19 | assert_status_is 0 20 | expected_output=$(cat <<-EOM 21 | Update started 22 | Preparing to update from 10 to 100 (in format staging) 23 | Downloading packs for: 24 | - os-core 25 | Finishing packs extraction... 26 | Statistics for going from version 10 to version 100: 27 | changed bundles : 1 28 | new bundles : 0 29 | deleted bundles : 0 30 | changed files : 1 31 | new files : 1 32 | deleted files : 0 33 | Validate downloaded files 34 | No extra files need to be downloaded 35 | Installing files... 36 | Update was applied 37 | Warning: post-update helper scripts skipped due to --no-scripts argument 38 | Update successful - System updated from version 10 to version 100 39 | EOM 40 | ) 41 | assert_is_output "$expected_output" 42 | # The file should still be added 43 | assert_file_exists "$TARGET_DIR"/testfile 44 | } 45 | #WEIGHT=3 46 | -------------------------------------------------------------------------------- /test/functional/update/update-statedir-bad-hash.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --add /test-file 10 | file_hash=$(get_hash_from_manifest "$TEST_NAME"/web-dir/100/Manifest.os-core /test-file) 11 | # copy the file from the files directory to state/staged and modify it 12 | sudo cp "$WEB_DIR"/100/files/"$file_hash" "$ABS_STAGED_DIR" 13 | write_to_protected_file -a "$ABS_STAGED_DIR"/"$file_hash" "extra string" 14 | 15 | } 16 | 17 | @test "UPD026: Update should discard full files with bad hash in the state dir" { 18 | 19 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 20 | 21 | assert_status_is 0 22 | expected_output=$(cat <<-EOM 23 | Update started 24 | Preparing to update from 10 to 100 (in format staging) 25 | Downloading packs for: 26 | - os-core 27 | Finishing packs extraction... 28 | Statistics for going from version 10 to version 100: 29 | changed bundles : 1 30 | new bundles : 0 31 | deleted bundles : 0 32 | changed files : 0 33 | new files : 1 34 | deleted files : 0 35 | Validate downloaded files 36 | No extra files need to be downloaded 37 | Installing files... 38 | Update was applied 39 | Calling post-update helper scripts 40 | Update successful - System updated from version 10 to version 100 41 | EOM 42 | ) 43 | # no errors are printed for a mismatched hash 44 | assert_is_output "$expected_output" 45 | # the file exists on the filesystem (it does not exist before the test) 46 | assert_file_exists "$TARGET_DIR"/test-file 47 | 48 | } 49 | #WEIGHT=2 50 | -------------------------------------------------------------------------------- /test/functional/update/update-status-no-server-content.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -e "$TEST_NAME" 8 | sudo rm -rf "$WEB_DIR"/version 9 | 10 | } 11 | 12 | @test "UPD037: Try showing latest version available on server when there is no server content" { 13 | 14 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --status" 15 | 16 | assert_status_is "$SWUPD_SERVER_CONNECTION_ERROR" 17 | expected_output=$(cat <<-EOM 18 | Error: Unable to determine the server version 19 | Current OS version: 10 20 | EOM 21 | ) 22 | assert_in_output "$expected_output" 23 | } 24 | #WEIGHT=1 25 | -------------------------------------------------------------------------------- /test/functional/update/update-status-no-target-content.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment -e "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 9 | sudo rm -f "$TARGET_DIR"/usr/lib/os-release 10 | 11 | } 12 | 13 | @test "UPD038: Try showing current OS version when there is no target content" { 14 | 15 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --status" 16 | 17 | assert_status_is "$SWUPD_CURRENT_VERSION_UNKNOWN" 18 | expected_output=$(cat <<-EOM 19 | Error: Unable to determine current OS version 20 | Latest server version: 100 21 | EOM 22 | ) 23 | assert_is_output "$expected_output" 24 | 25 | } 26 | #WEIGHT=1 27 | -------------------------------------------------------------------------------- /test/functional/update/update-status.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | setup_file() { 6 | 7 | create_test_environment -e "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 9 | 10 | } 11 | 12 | teardown_file() { 13 | 14 | destroy_test_environment --force "$TEST_NAME" 15 | 16 | } 17 | 18 | @test "UPD034: Show current OS version and latest version available on server" { 19 | 20 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --status" 21 | 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | Current OS version: 10 25 | Latest server version: 100 26 | There is a new OS version available: 100 27 | EOM 28 | ) 29 | assert_is_output "$expected_output" 30 | 31 | } 32 | 33 | @test "UPD035: Show current OS version when os-release has double quote on version" { 34 | 35 | set_current_version "$TEST_NAME" "\\'10\\'" 36 | 37 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --status" 38 | 39 | assert_status_is 0 40 | expected_output=$(cat <<-EOM 41 | Current OS version: 10 42 | Latest server version: 100 43 | There is a new OS version available: 100 44 | EOM 45 | ) 46 | assert_is_output "$expected_output" 47 | 48 | } 49 | 50 | @test "UPD036: Show current OS version when os-release has single quote on version" { 51 | 52 | set_current_version "$TEST_NAME" "\\'10\\'" 53 | 54 | run sudo sh -c "$SWUPD update $SWUPD_OPTS --status" 55 | 56 | assert_status_is 0 57 | expected_output=$(cat <<-EOM 58 | Current OS version: 10 59 | Latest server version: 100 60 | There is a new OS version available: 100 61 | EOM 62 | ) 63 | assert_is_output "$expected_output" 64 | 65 | } 66 | #WEIGHT=1 67 | -------------------------------------------------------------------------------- /test/functional/update/update-to-same-version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Otavio Pontes 4 | # Email: otavio.pontes@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | create_version -p "$TEST_NAME" 20 10 12 | 13 | } 14 | 15 | @test "UPD050: Update to the same version using -m" { 16 | 17 | run sudo sh -c "$SWUPD update $SWUPD_OPTS -m 10" 18 | 19 | assert_status_is 0 20 | expected_output=$(cat <<-EOM 21 | Update started 22 | Requested version (10) is not newer than system version (10) 23 | Update complete - System already up-to-date at version 10 24 | EOM 25 | ) 26 | assert_is_output "$expected_output" 27 | 28 | } 29 | 30 | @test "UPD051: Update to same version using -m, when already in last version" { 31 | 32 | set_current_version "$TEST_NAME" 20 33 | 34 | run sudo sh -c "$SWUPD update $SWUPD_OPTS -m 20" 35 | 36 | assert_status_is 0 37 | expected_output=$(cat <<-EOM 38 | Update started 39 | Requested version (20) is not newer than system version (20) 40 | Update complete - System already up-to-date at version 20 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | 45 | } 46 | 47 | @test "UPD052: Update when already in last version" { 48 | 49 | set_current_version "$TEST_NAME" 20 50 | 51 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 52 | 53 | assert_status_is 0 54 | expected_output=$(cat <<-EOM 55 | Update started 56 | Version on server (20) is not newer than system version (20) 57 | Update complete - System already up-to-date at version 20 58 | EOM 59 | ) 60 | assert_is_output "$expected_output" 61 | 62 | } 63 | #WEIGHT=4 64 | -------------------------------------------------------------------------------- /test/functional/update/update-use-full-file.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --update /core 10 | # remove packs so full file is used 11 | sudo rm -rf "$WEB_DIR"/100/pack-* 12 | sudo rm -f "$WEB_DIR"/100/delta/* 13 | 14 | } 15 | 16 | @test "UPD006: Update falls back to using full files if no packs are available" { 17 | 18 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 19 | 20 | assert_status_is 0 21 | expected_output=$(cat <<-EOM 22 | Update started 23 | Preparing to update from 10 to 100 (in format staging) 24 | Downloading packs for: 25 | - os-core 26 | Finishing packs extraction... 27 | Statistics for going from version 10 to version 100: 28 | changed bundles : 1 29 | new bundles : 0 30 | deleted bundles : 0 31 | changed files : 1 32 | new files : 0 33 | deleted files : 0 34 | Validate downloaded files 35 | Starting download of remaining update content. This may take a while... 36 | Installing files... 37 | Update was applied 38 | Calling post-update helper scripts 39 | 1 file was not in a pack 40 | Update successful - System updated from version 10 to version 100 41 | EOM 42 | ) 43 | assert_is_output "$expected_output" 44 | assert_file_exists "$TARGET_DIR"/core 45 | 46 | } 47 | #WEIGHT=2 48 | -------------------------------------------------------------------------------- /test/functional/update/update-use-pack.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version -p "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --update /core 10 | 11 | } 12 | 13 | @test "UPD005: Update uses delta packs if available" { 14 | 15 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 16 | assert_status_is 0 17 | expected_output=$(cat <<-EOM 18 | Update started 19 | Preparing to update from 10 to 100 (in format staging) 20 | Downloading packs for: 21 | - os-core 22 | Finishing packs extraction... 23 | Statistics for going from version 10 to version 100: 24 | changed bundles : 1 25 | new bundles : 0 26 | deleted bundles : 0 27 | changed files : 1 28 | new files : 0 29 | deleted files : 0 30 | Validate downloaded files 31 | No extra files need to be downloaded 32 | Installing files... 33 | Update was applied 34 | Calling post-update helper scripts 35 | Update successful - System updated from version 10 to version 100 36 | EOM 37 | ) 38 | assert_is_output "$expected_output" 39 | assert_file_exists "$TARGET_DIR"/core 40 | # make sure the file was updated correctly 41 | fhash=$(get_hash_from_manifest "$WEB_DIR"/100/Manifest.os-core /core) 42 | assert_files_equal "$TARGET_DIR"/core "$TEST_NAME"/web-dir/100/files/"$fhash" 43 | 44 | } 45 | #WEIGHT=2 46 | -------------------------------------------------------------------------------- /test/functional/update/update-verify-fix-path-missing-dir.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_bundle -L -n test-bundle -f /foo/bar/baz/test-file "$TEST_NAME" 9 | # remove the foo dir 10 | sudo rm -rf "$TARGET_DIR"/foo 11 | create_version "$TEST_NAME" 100 10 12 | update_bundle "$TEST_NAME" test-bundle --update /foo/bar/baz/test-file 13 | 14 | } 15 | 16 | @test "UPD029: Update corrects a missing directory in the target system" { 17 | 18 | assert_dir_not_exists "$TARGET_DIR"/foo 19 | 20 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 21 | 22 | assert_status_is 0 23 | expected_output=$(cat <<-EOM 24 | Update started 25 | Preparing to update from 10 to 100 (in format staging) 26 | Downloading packs for: 27 | - test-bundle 28 | Finishing packs extraction... 29 | Warning: File "/foo/bar/baz/test-file" is missing or corrupted 30 | Warning: Couldn't use delta file because original file is corrupted or missing 31 | Consider running "swupd repair" to fix the issue 32 | Statistics for going from version 10 to version 100: 33 | changed bundles : 1 34 | new bundles : 0 35 | deleted bundles : 0 36 | changed files : 1 37 | new files : 0 38 | deleted files : 0 39 | Validate downloaded files 40 | Starting download of remaining update content. This may take a while... 41 | Installing files... 42 | Update was applied 43 | Calling post-update helper scripts 44 | 1 file was not in a pack 45 | Update successful - System updated from version 10 to version 100 46 | EOM 47 | ) 48 | assert_is_output "$expected_output" 49 | assert_dir_exists "$TARGET_DIR"/foo/bar/baz 50 | assert_file_exists "$TARGET_DIR"/foo/bar/baz/test-file 51 | 52 | } 53 | 54 | #WEIGHT=3 55 | -------------------------------------------------------------------------------- /test/functional/update/update-verify-fullfile-hash.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | test_setup() { 6 | 7 | create_test_environment "$TEST_NAME" 8 | create_version "$TEST_NAME" 100 10 9 | update_bundle "$TEST_NAME" os-core --update /core 10 | file_hash=$(get_hash_from_manifest "$WEB_DIR"/100/Manifest.os-core /core) 11 | # remove the /usr/bin/core file from the system 12 | sudo rm -f "$TARGET_DIR"/core 13 | # remove packs so fullfiles are used 14 | sudo rm -rf "$WEB_DIR"/100/pack-* 15 | # modify the fullfile so it is corrupt 16 | write_to_protected_file -a "$WEB_DIR"/100/files/"$file_hash" "some extra stuff to break the hash" 17 | sudo rm "$WEB_DIR"/100/files/"$file_hash".tar 18 | create_tar "$WEB_DIR"/100/files/"$file_hash" 19 | 20 | } 21 | 22 | @test "UPD028: Try updating a system having a corrupt fullfile in the server" { 23 | 24 | run sudo sh -c "$SWUPD update $SWUPD_OPTS" 25 | 26 | assert_status_is 1 27 | expected_output=$(cat <<-EOM 28 | Update started 29 | Preparing to update from 10 to 100 \(in format staging\) 30 | Downloading packs for: 31 | - os-core 32 | Finishing packs extraction... 33 | Statistics for going from version 10 to version 100: 34 | changed bundles : 1 35 | new bundles : 0 36 | deleted bundles : 0 37 | changed files : 1 38 | new files : 0 39 | deleted files : 0 40 | Validate downloaded files 41 | Starting download of remaining update content. This may take a while... 42 | Error: File content hash mismatch for .* \\(bad server data\\?\\) 43 | EOM 44 | ) 45 | assert_regex_is_output "$expected_output" 46 | assert_file_not_exists "$TARGET_DIR"/core 47 | 48 | } 49 | #WEIGHT=2 50 | -------------------------------------------------------------------------------- /test/functional/usability/usa-cachedir-with-symlink.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # Author: Castulo Martinez 4 | # Email: castulo.martinez@intel.com 5 | 6 | load "../testlib" 7 | 8 | test_setup() { 9 | 10 | create_test_environment "$TEST_NAME" 11 | 12 | # create a symlink to the the statedir 13 | sudo ln -s "$ABS_STATE_DIR" "$ABS_TEST_DIR"/state_path 14 | sudo mkdir "$ABS_STATE_DIR"/new_state 15 | 16 | } 17 | 18 | @test "USA020: Tar files can be extracted into paths that contain symlinks" { 19 | 20 | # swupd should be able to extract files in the cache dir even when the path 21 | # provided for the cache directory contains symlinks 22 | 23 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS_NO_STATE --statedir $ABS_TEST_DIR/state_path/new_state" 24 | assert_status_is "$SWUPD_OK" 25 | 26 | } 27 | -------------------------------------------------------------------------------- /test/functional/usability/usa-completion-basic.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "../testlib" 4 | 5 | @test "USA001: Verify the script for autocomplete exists" { 6 | 7 | assert_file_exists "$ABS_SWUPD_DIR"/swupd.bash 8 | 9 | } 10 | 11 | @test "USA002: Verify the autocomplete syntax" { 12 | 13 | bash --posix "$ABS_SWUPD_DIR"/swupd.bash 14 | 15 | } 16 | 17 | @test "USA003: Autocomplete has autoupdate" { 18 | 19 | grep -q '("bundle-add")' "$ABS_SWUPD_DIR"/swupd.bash 20 | 21 | } 22 | 23 | @test "USA004: Autocomplete has expected hashdump" { 24 | 25 | grep -q '("hashdump")' "$ABS_SWUPD_DIR"/swupd.bash 26 | 27 | } 28 | #WEIGHT=1 29 | -------------------------------------------------------------------------------- /test/installation/test.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "INS001: Check if all files were installed successfully in a full install" { 4 | # Binaries 5 | [ -x /usr/bin/swupd ] 6 | [ -x /usr/bin/verifytime ] 7 | 8 | # Manuals 9 | [ -s /usr/share/man/man4/update-triggers.target.4 ] 10 | [ -s /usr/share/man/man4/swupd-update.timer.4 ] 11 | [ -s /usr/share/man/man4/swupd-update.service.4 ] 12 | [ -s /usr/share/man/man1/swupd.1 ] 13 | 14 | # System d files 15 | [ -s /usr/lib/systemd/system/swupd-update.timer ] 16 | [ -s /usr/lib/systemd/system/swupd-update.service ] 17 | [ -s /usr/lib/systemd/system/verifytime.service ] 18 | 19 | } 20 | -------------------------------------------------------------------------------- /test/real_content/swupd_repair_fullfiles.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "real_content_lib" 4 | 5 | # Test massive fullfile downloads 6 | @test "RCT002: Repair a big system" { 7 | print "Install minimal system with newest version" 8 | # shellcheck disable=SC2153 9 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS -F $FORMAT" 10 | assert_status_is 0 11 | 12 | install_bundles -r 13 | verify_system 14 | } 15 | -------------------------------------------------------------------------------- /test/real_content/swupd_update.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "real_content_lib" 4 | 5 | # Test update in delta pack range 6 | @test "RCT001: Incremental Updates" { 7 | # shellcheck disable=SC2153 8 | print "Install minimal system with oldest version (${VERSION[0]})" 9 | 10 | # shellcheck disable=SC2153 11 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS -V ${VERSION[0]} -F $FORMAT" 12 | assert_status_is 0 13 | check_version "${VERSION[0]}" 14 | 15 | install_bundles 16 | 17 | i=1 18 | while [ -n "${VERSION[$i]}" ]; do 19 | print "Update system to next version (${VERSION[$i]})" 20 | run sudo sh -c "$SWUPD update $SWUPD_OPTS -m ${VERSION[$i]}" 21 | assert_status_is 0 22 | check_version "${VERSION[$i]}" 23 | verify_system 24 | 25 | i=$((i+1)) 26 | done 27 | } 28 | -------------------------------------------------------------------------------- /test/real_content/swupd_update_jump.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load "real_content_lib" 4 | 5 | # Test update out of the delta pack range 6 | @test "RCT003: Update from 2 distant versions" { 7 | # shellcheck disable=SC2153 8 | print "Install minimal system with oldest version (${VERSION[0]})" 9 | # shellcheck disable=SC2153 10 | run sudo sh -c "$SWUPD os-install $SWUPD_OPTS -V ${VERSION[0]} -F $FORMAT" 11 | assert_status_is 0 12 | check_version "${VERSION[0]}" 13 | 14 | install_bundles 15 | 16 | version=${VERSION[${#VERSION[@]} -1]} 17 | 18 | print "Update system to last version ($version)" 19 | run sudo sh -c "$SWUPD update $SWUPD_OPTS -m ${version}" 20 | assert_status_is 0 21 | check_version "$version" 22 | verify_system 23 | } 24 | -------------------------------------------------------------------------------- /test/unit/data/config_noocsp_critical.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = myca 3 | 4 | [ req ] 5 | distinguished_name = myca_policy 6 | x509_extensions = ca_extensions 7 | 8 | [ myca_policy ] 9 | commonName = supplied 10 | stateOrProvinceName = supplied 11 | countryName = supplied 12 | emailAddress = optional 13 | organizationName = supplied 14 | organizationalUnitName = optional 15 | 16 | [ca_extensions] 17 | keyUsage = digitalSignature,keyCertSign,cRLSign 18 | extendedKeyUsage = codeSigning 19 | basicConstraints = critical,CA:FALSE 20 | subjectKeyIdentifier = hash 21 | authorityInfoAccess = critical,caIssuers;URI:http://127.0.0.1:8080 22 | -------------------------------------------------------------------------------- /test/unit/data/config_ocsp.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = myca 3 | 4 | [ req ] 5 | distinguished_name = myca_policy 6 | x509_extensions = ca_extensions 7 | 8 | [ myca_policy ] 9 | commonName = supplied 10 | stateOrProvinceName = supplied 11 | countryName = supplied 12 | emailAddress = optional 13 | organizationName = supplied 14 | organizationalUnitName = optional 15 | 16 | [ca_extensions] 17 | keyUsage = digitalSignature,keyCertSign,cRLSign 18 | extendedKeyUsage = codeSigning 19 | basicConstraints = critical,CA:FALSE 20 | subjectKeyIdentifier = hash 21 | authorityInfoAccess = OCSP;URI:http://127.0.0.1:8080 22 | -------------------------------------------------------------------------------- /test/unit/data/config_ocsp_critical.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = myca 3 | 4 | [ req ] 5 | distinguished_name = myca_policy 6 | x509_extensions = ca_extensions 7 | 8 | [ myca_policy ] 9 | commonName = supplied 10 | stateOrProvinceName = supplied 11 | countryName = supplied 12 | emailAddress = optional 13 | organizationName = supplied 14 | organizationalUnitName = optional 15 | 16 | [ca_extensions] 17 | keyUsage = digitalSignature,keyCertSign,cRLSign 18 | extendedKeyUsage = codeSigning 19 | basicConstraints = critical,CA:FALSE 20 | subjectKeyIdentifier = hash 21 | authorityInfoAccess = critical,OCSP;URI:http://127.0.0.1:8080 22 | -------------------------------------------------------------------------------- /test/unit/data/mom1: -------------------------------------------------------------------------------- 1 | MANIFEST 1 2 | version: 30 3 | previous: 20 4 | minversion: 10 5 | filecount: 123 6 | timestamp: 456 7 | contentsize: 789 8 | 9 | INVALID 10 | -------------------------------------------------------------------------------- /test/unit/data/mom_invalid1: -------------------------------------------------------------------------------- 1 | version: 10 2 | previous: 20 3 | minversion: 10 4 | filecount: 1 5 | timestamp: 123 6 | contentsize: 456 7 | XXXXXXXX: XXXXXX 8 | 9 | M... 0000000000000000000000000000000000000000000000000000000000000001 10 m1 10 | -------------------------------------------------------------------------------- /test/unit/data/mom_invalid2: -------------------------------------------------------------------------------- 1 | MANIFEST 1 2 | version: 3 | previous: 20 4 | minversion: 10 5 | filecount: 1 6 | timestamp: 123 7 | contentsize: 456 8 | XXXXXXXX: XXXXXX 9 | 10 | M... 0000000000000000000000000000000000000000000000000000000000000001 10 m1 11 | -------------------------------------------------------------------------------- /test/unit/test_helper.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define print_error(_msg) printf("Test error(%s:%d): %s\n", __FILE__, __LINE__, _msg); 5 | 6 | /* 7 | * Assert and print error message if _exp is false. 8 | */ 9 | #define check_msg(_exp, _msg) \ 10 | do { \ 11 | if (!(_exp)) { \ 12 | print_error(_msg); \ 13 | exit(EXIT_FAILURE); \ 14 | } \ 15 | } while(0) 16 | 17 | /* 18 | * Assert and print error message if _exp is false. 19 | * Goto to label instead of exiting. 20 | */ 21 | #define check_msg_goto(_exp, _msg, _label) \ 22 | do { \ 23 | if (!(_exp)) { \ 24 | print_error(_msg); \ 25 | goto _label; \ 26 | } \ 27 | } while(0) 28 | 29 | #define check(_exp) check_msg(_exp, "failed") 30 | #define check_goto(_exp, _label) check_msg_goto(_exp, "failed", _label) 31 | --------------------------------------------------------------------------------