From d8b9889249702f5f25a99434d1797d6e4e2d1902 Mon Sep 17 00:00:00 2001 From: deepakpathania <68396823+deepakpathania@users.noreply.github.com> Date: Tue, 13 Jun 2023 12:55:37 +0530 Subject: [PATCH] Add QIT integration for running security tests locally (#6486) --- changelog/dev-qit-tests | 4 + composer.json | 3 +- composer.lock | 223 +++++++++++++++++++---------------- package.json | 1 + tests/qit/README.md | 21 ++++ tests/qit/config/default.env | 3 + tests/qit/security.sh | 42 +++++++ 7 files changed, 197 insertions(+), 100 deletions(-) create mode 100644 changelog/dev-qit-tests create mode 100644 tests/qit/README.md create mode 100644 tests/qit/config/default.env create mode 100755 tests/qit/security.sh diff --git a/changelog/dev-qit-tests b/changelog/dev-qit-tests new file mode 100644 index 00000000000..ba957482673 --- /dev/null +++ b/changelog/dev-qit-tests @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Add script to run QIT security tests locally. diff --git a/composer.json b/composer.json index a8ce162d36c..dd9d5804ec5 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "yoast/phpunit-polyfills": "1.0.3", "cweagans/composer-patches": "1.7.1", "automattic/jetpack-changelogger": "3.3.2", - "spatie/phpunit-watcher": "^1.23" + "spatie/phpunit-watcher": "1.23", + "woocommerce/qit-cli": "0.3.4" }, "scripts": { "test": [ diff --git a/composer.lock b/composer.lock index dc0996e29d9..771383e310f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0571fbd3f848f7e75919fe06199e4a90", + "content-hash": "b4f6a5ec0d357a7ab0227976b517898c", "packages": [ { "name": "automattic/jetpack-a8c-mc-stats", @@ -55,16 +55,16 @@ }, { "name": "automattic/jetpack-admin-ui", - "version": "v0.2.19", + "version": "v0.2.20", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-admin-ui.git", - "reference": "ae3c7f7a3bd564172ce48f72447ecea2c7508a5a" + "reference": "90f4de6c9d936bbf161f1c2356d98b00ba33576f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-admin-ui/zipball/ae3c7f7a3bd564172ce48f72447ecea2c7508a5a", - "reference": "ae3c7f7a3bd564172ce48f72447ecea2c7508a5a", + "url": "https://api.github.com/repos/Automattic/jetpack-admin-ui/zipball/90f4de6c9d936bbf161f1c2356d98b00ba33576f", + "reference": "90f4de6c9d936bbf161f1c2356d98b00ba33576f", "shasum": "" }, "require-dev": { @@ -102,29 +102,29 @@ ], "description": "Generic Jetpack wp-admin UI elements", "support": { - "source": "https://github.com/Automattic/jetpack-admin-ui/tree/v0.2.19" + "source": "https://github.com/Automattic/jetpack-admin-ui/tree/v0.2.20" }, - "time": "2023-04-10T11:44:03+00:00" + "time": "2023-04-25T15:05:53+00:00" }, { "name": "automattic/jetpack-assets", - "version": "v1.18.1", + "version": "v1.18.4", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-assets.git", - "reference": "bccd132389f780abf779bb85bf12b91984b4b0ce" + "reference": "fbb76cd3d88ef31ba65d3fa0d3bfed155c016d05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-assets/zipball/bccd132389f780abf779bb85bf12b91984b4b0ce", - "reference": "bccd132389f780abf779bb85bf12b91984b4b0ce", + "url": "https://api.github.com/repos/Automattic/jetpack-assets/zipball/fbb76cd3d88ef31ba65d3fa0d3bfed155c016d05", + "reference": "fbb76cd3d88ef31ba65d3fa0d3bfed155c016d05", "shasum": "" }, "require": { "automattic/jetpack-constants": "^1.6.22" }, "require-dev": { - "automattic/jetpack-changelogger": "^3.3.2", + "automattic/jetpack-changelogger": "^3.3.4", "brain/monkey": "2.6.1", "wikimedia/testing-access-wrapper": "^1.0 || ^2.0", "yoast/phpunit-polyfills": "1.0.4" @@ -158,9 +158,9 @@ ], "description": "Asset management utilities for Jetpack ecosystem packages", "support": { - "source": "https://github.com/Automattic/jetpack-assets/tree/v1.18.1" + "source": "https://github.com/Automattic/jetpack-assets/tree/v1.18.4" }, - "time": "2023-04-10T11:44:07+00:00" + "time": "2023-06-06T19:19:42+00:00" }, { "name": "automattic/jetpack-autoloader", @@ -432,20 +432,20 @@ }, { "name": "automattic/jetpack-ip", - "version": "v0.1.2", + "version": "v0.1.4", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-ip.git", - "reference": "8cc665d68ef5230de78e2701b61b91af64d8dfe6" + "reference": "fde10bea279aca8adbae9d7ae27d971da3a932e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-ip/zipball/8cc665d68ef5230de78e2701b61b91af64d8dfe6", - "reference": "8cc665d68ef5230de78e2701b61b91af64d8dfe6", + "url": "https://api.github.com/repos/Automattic/jetpack-ip/zipball/fde10bea279aca8adbae9d7ae27d971da3a932e3", + "reference": "fde10bea279aca8adbae9d7ae27d971da3a932e3", "shasum": "" }, "require-dev": { - "automattic/jetpack-changelogger": "^3.3.2", + "automattic/jetpack-changelogger": "^3.3.4", "brain/monkey": "2.6.1", "yoast/phpunit-polyfills": "1.0.4" }, @@ -478,9 +478,9 @@ ], "description": "Utilities for working with IP addresses.", "support": { - "source": "https://github.com/Automattic/jetpack-ip/tree/v0.1.2" + "source": "https://github.com/Automattic/jetpack-ip/tree/v0.1.4" }, - "time": "2023-04-10T11:43:44+00:00" + "time": "2023-05-29T19:04:13+00:00" }, { "name": "automattic/jetpack-logo", @@ -679,16 +679,16 @@ }, { "name": "automattic/jetpack-status", - "version": "v1.16.4", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/Automattic/jetpack-status.git", - "reference": "7c9153b4589bc5efc91637d3e8c6a8618f7afa6b" + "reference": "0032ee4bce1d4644722ba46858c702a0afa76cff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/jetpack-status/zipball/7c9153b4589bc5efc91637d3e8c6a8618f7afa6b", - "reference": "7c9153b4589bc5efc91637d3e8c6a8618f7afa6b", + "url": "https://api.github.com/repos/Automattic/jetpack-status/zipball/0032ee4bce1d4644722ba46858c702a0afa76cff", + "reference": "0032ee4bce1d4644722ba46858c702a0afa76cff", "shasum": "" }, "require": { @@ -696,7 +696,7 @@ }, "require-dev": { "automattic/jetpack-changelogger": "^3.3.2", - "automattic/jetpack-ip": "^0.1.2", + "automattic/jetpack-ip": "^0.1.3", "brain/monkey": "2.6.1", "yoast/phpunit-polyfills": "1.0.4" }, @@ -711,7 +711,7 @@ "link-template": "https://github.com/Automattic/jetpack-status/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "1.16.x-dev" + "dev-trunk": "1.17.x-dev" } }, "autoload": { @@ -725,9 +725,9 @@ ], "description": "Used to retrieve information about the current status of Jetpack and the site overall.", "support": { - "source": "https://github.com/Automattic/jetpack-status/tree/v1.16.4" + "source": "https://github.com/Automattic/jetpack-status/tree/v1.17.1" }, - "time": "2023-04-10T11:44:02+00:00" + "time": "2023-05-11T05:50:45+00:00" }, { "name": "automattic/jetpack-sync", @@ -2332,16 +2332,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.4", + "version": "v4.15.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290" + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", "shasum": "" }, "require": { @@ -2382,9 +2382,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5" }, - "time": "2023-03-05T19:49:14+00:00" + "time": "2023-05-19T20:20:00+00:00" }, { "name": "openlss/lib-array2xml", @@ -3560,33 +3560,31 @@ }, { "name": "react/event-loop", - "version": "v1.3.0", + "version": "v1.4.0", "source": { "type": "git", "url": "https://github.com/reactphp/event-loop.git", - "reference": "187fb56f46d424afb6ec4ad089269c72eec2e137" + "reference": "6e7e587714fff7a83dcc7025aee42ab3b265ae05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/187fb56f46d424afb6ec4ad089269c72eec2e137", - "reference": "187fb56f46d424afb6ec4ad089269c72eec2e137", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/6e7e587714fff7a83dcc7025aee42ab3b265ae05", + "reference": "6e7e587714fff7a83dcc7025aee42ab3b265ae05", "shasum": "" }, "require": { "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" }, "suggest": { - "ext-event": "~1.0 for ExtEventLoop", - "ext-pcntl": "For signal handling support when using the StreamSelectLoop", - "ext-uv": "* for ExtUvLoop" + "ext-pcntl": "For signal handling support when using the StreamSelectLoop" }, "type": "library", "autoload": { "psr-4": { - "React\\EventLoop\\": "src" + "React\\EventLoop\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -3622,19 +3620,15 @@ ], "support": { "issues": "https://github.com/reactphp/event-loop/issues", - "source": "https://github.com/reactphp/event-loop/tree/v1.3.0" + "source": "https://github.com/reactphp/event-loop/tree/v1.4.0" }, "funding": [ { - "url": "https://github.com/WyriHaximus", - "type": "github" - }, - { - "url": "https://github.com/clue", - "type": "github" + "url": "https://opencollective.com/reactphp", + "type": "open_collective" } ], - "time": "2022-03-17T11:10:22+00:00" + "time": "2023-05-05T10:11:24+00:00" }, { "name": "react/stream", @@ -4064,16 +4058,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -4118,7 +4112,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -4126,7 +4120,7 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", @@ -4730,34 +4724,32 @@ }, { "name": "spatie/phpunit-watcher", - "version": "1.23.6", + "version": "1.23.0", "source": { "type": "git", "url": "https://github.com/spatie/phpunit-watcher.git", - "reference": "c192fff763810c8378511bcf0069df4b91478866" + "reference": "8a8e0c3c8f3f03dfdb6bf62abf89c1b7273fc0b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/phpunit-watcher/zipball/c192fff763810c8378511bcf0069df4b91478866", - "reference": "c192fff763810c8378511bcf0069df4b91478866", + "url": "https://api.github.com/repos/spatie/phpunit-watcher/zipball/8a8e0c3c8f3f03dfdb6bf62abf89c1b7273fc0b3", + "reference": "8a8e0c3c8f3f03dfdb6bf62abf89c1b7273fc0b3", "shasum": "" }, "require": { - "clue/stdio-react": "^2.4", - "jolicode/jolinotif": "^2.2", - "php": "^7.2 | ^8.0 | ^8.1", - "symfony/console": "^5 | ^6", - "symfony/finder": "^5.4 | ^6", - "symfony/process": "^5.4 | ^6", - "symfony/yaml": "^5.2 | ^6", - "yosymfony/resource-watcher": "^2.0 | ^3.0" + "clue/stdio-react": "^2.0", + "jolicode/jolinotif": "^2.0", + "php": "^7.2", + "symfony/console": "^4.0|^5.0", + "symfony/process": "^4.0|^5.0", + "symfony/yaml": "^4.0|^5.0", + "yosymfony/resource-watcher": "^2.0" }, "conflict": { - "symfony/console": "<5.2", "yosymfony/resource-watcher": "<2.0" }, "require-dev": { - "phpunit/phpunit": "^8.6 | ^9.0" + "phpunit/phpunit": "^8.0" }, "bin": [ "phpunit-watcher" @@ -4788,9 +4780,9 @@ ], "support": { "issues": "https://github.com/spatie/phpunit-watcher/issues", - "source": "https://github.com/spatie/phpunit-watcher/tree/1.23.6" + "source": "https://github.com/spatie/phpunit-watcher/tree/1.23.0" }, - "time": "2022-01-31T11:57:13+00:00" + "time": "2020-10-27T07:36:25+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -4851,16 +4843,16 @@ }, { "name": "symfony/console", - "version": "v5.4.22", + "version": "v5.4.24", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "3cd51fd2e6c461ca678f84d419461281bd87a0a8" + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/3cd51fd2e6c461ca678f84d419461281bd87a0a8", - "reference": "3cd51fd2e6c461ca678f84d419461281bd87a0a8", + "url": "https://api.github.com/repos/symfony/console/zipball/560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", + "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", "shasum": "" }, "require": { @@ -4930,7 +4922,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.22" + "source": "https://github.com/symfony/console/tree/v5.4.24" }, "funding": [ { @@ -4946,7 +4938,7 @@ "type": "tidelift" } ], - "time": "2023-03-25T09:27:28+00:00" + "time": "2023-05-26T05:13:16+00:00" }, { "name": "symfony/deprecation-contracts", @@ -5572,16 +5564,16 @@ }, { "name": "symfony/process", - "version": "v5.4.22", + "version": "v5.4.24", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "4b850da0cc3a2a9181c1ed407adbca4733dc839b" + "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/4b850da0cc3a2a9181c1ed407adbca4733dc839b", - "reference": "4b850da0cc3a2a9181c1ed407adbca4733dc839b", + "url": "https://api.github.com/repos/symfony/process/zipball/e3c46cc5689c8782944274bb30702106ecbe3b64", + "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64", "shasum": "" }, "require": { @@ -5614,7 +5606,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.22" + "source": "https://github.com/symfony/process/tree/v5.4.24" }, "funding": [ { @@ -5630,7 +5622,7 @@ "type": "tidelift" } ], - "time": "2023-03-06T21:29:33+00:00" + "time": "2023-05-17T11:26:05+00:00" }, { "name": "symfony/service-contracts", @@ -5803,16 +5795,16 @@ }, { "name": "symfony/yaml", - "version": "v5.4.21", + "version": "v5.4.23", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "3713e20d93e46e681e51605d213027e48dab3469" + "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/3713e20d93e46e681e51605d213027e48dab3469", - "reference": "3713e20d93e46e681e51605d213027e48dab3469", + "url": "https://api.github.com/repos/symfony/yaml/zipball/4cd2e3ea301aadd76a4172756296fe552fb45b0b", + "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b", "shasum": "" }, "require": { @@ -5858,7 +5850,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.21" + "source": "https://github.com/symfony/yaml/tree/v5.4.23" }, "funding": [ { @@ -5874,7 +5866,7 @@ "type": "tidelift" } ], - "time": "2023-02-21T19:46:44+00:00" + "time": "2023-04-23T19:33:36+00:00" }, { "name": "theseer/tokenizer", @@ -6235,6 +6227,39 @@ }, "time": "2020-05-12T16:22:33+00:00" }, + { + "name": "woocommerce/qit-cli", + "version": "0.3.4", + "source": { + "type": "git", + "url": "https://github.com/woocommerce/qit-cli.git", + "reference": "ba2eed918086c340efb49f06d7309410604ccd7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/woocommerce/qit-cli/zipball/ba2eed918086c340efb49f06d7309410604ccd7e", + "reference": "ba2eed918086c340efb49f06d7309410604ccd7e", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": "^7.2.5 | ^8" + }, + "bin": [ + "qit" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-or-later" + ], + "description": "A command line interface for WooCommerce Quality Insights Toolkit (QIT).", + "support": { + "issues": "https://github.com/woocommerce/qit-cli/issues", + "source": "https://github.com/woocommerce/qit-cli/tree/0.3.4" + }, + "time": "2023-06-12T17:32:37+00:00" + }, { "name": "woocommerce/woocommerce-sniffs", "version": "0.1.0", @@ -6393,16 +6418,16 @@ }, { "name": "yosymfony/resource-watcher", - "version": "v3.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/yosymfony/resource-watcher.git", - "reference": "2f197cee0231c06db865d4ad2d8d7cd3faead2f8" + "reference": "a8c34f704e6bd4f786c97f3c0ba65bd86cb2bd73" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yosymfony/resource-watcher/zipball/2f197cee0231c06db865d4ad2d8d7cd3faead2f8", - "reference": "2f197cee0231c06db865d4ad2d8d7cd3faead2f8", + "url": "https://api.github.com/repos/yosymfony/resource-watcher/zipball/a8c34f704e6bd4f786c97f3c0ba65bd86cb2bd73", + "reference": "a8c34f704e6bd4f786c97f3c0ba65bd86cb2bd73", "shasum": "" }, "require": { @@ -6416,7 +6441,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -6446,7 +6471,7 @@ "issues": "https://github.com/yosymfony/resource-watcher/issues", "source": "https://github.com/yosymfony/resource-watcher/tree/master" }, - "time": "2020-06-10T14:58:36+00:00" + "time": "2020-01-04T15:36:55+00:00" } ], "aliases": [], @@ -6464,5 +6489,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.1.0" } diff --git a/package.json b/package.json index cc758c42d4e..ab4735d7e25 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "test:php": "./bin/run-tests.sh", "test:php-coverage": "./bin/check-test-coverage.sh", "test:php-watch": "npm run test:php -- -w", + "test:qit": "npm run build:release && ./tests/qit/security.sh", "watch": "webpack --watch", "hmr": "webpack server", "start": "npm run watch", diff --git a/tests/qit/README.md b/tests/qit/README.md new file mode 100644 index 00000000000..a1d2e951709 --- /dev/null +++ b/tests/qit/README.md @@ -0,0 +1,21 @@ +## WooCommerce Payments QIT tests + +We currently only use the security tests from the [QIT toolkit](https://woocommerce.github.io/qit-documentation/#/) and these can be run locally. + +#### Setup and running +- Create `local.env` inside the `tests/qit/config/` directory by copying the variables from `default.env`. +- To get the actual values for local config, refer to this [secret store](https://mc.a8c.com/secret-store/?secret_id=11043) link. +- Once configured, the first time you run the `npm` command, it should create a local auth file which will be used for subsequent runs. + +- For running, use: + ``` + npm run test:qit + ``` + +- The command uses the `build:release` command to create `woocommerce-payments.zip` at the root of the directory which is then uploaded and used for the QIT tests. + + +#### Analysing results +- Once the test run is done, you'll see a result URL along with the test summary. +- Look at any errors that might have been surfaced and associate with PRs that has introduced the same by using `git blame`. +- Ping the author for fixing the error, or fix it yourself if it is straightforward enough. diff --git a/tests/qit/config/default.env b/tests/qit/config/default.env new file mode 100644 index 00000000000..2b460fbdfdc --- /dev/null +++ b/tests/qit/config/default.env @@ -0,0 +1,3 @@ +# Create `local.env` and supply actual values. +QIT_USER="" +QIT_PASSWORD="" diff --git a/tests/qit/security.sh b/tests/qit/security.sh new file mode 100755 index 00000000000..4c9edcdfe19 --- /dev/null +++ b/tests/qit/security.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -e + +cwd=$(pwd) +WCP_ROOT=$cwd +QIT_ROOT="$cwd/tests/qit" +EXTENSION_NAME="woocommerce-payments" + +#Load local env variables if present. +if [[ -f "$QIT_ROOT/config/local.env" ]]; then + . "$QIT_ROOT/config/local.env" +fi + +# Check if QIT_USER and QIT_APP_PASSWORD are set and not empty +if [[ -z $QIT_USER ]] || [[ -z $QIT_PASSWORD ]]; then + echo "QIT_USER or QIT_APP_PASSWORD environment variables are not set or empty. Please set them in the local env file before running the script." + exit 1 +fi + +export QIT_DISABLE_ONBOARDING=yes + +# If QIT_BINARY is not set, default to ./vendor/bin/qit +QIT_BINARY=${QIT_BINARY:-./vendor/bin/qit} + +# Add the partner by validating credentials. +if ! $QIT_BINARY list | grep -q 'partner:remove'; then + echo "Adding partner with QIT credentials..." + $QIT_BINARY partner:add --user=$QIT_USER --application_password=$QIT_PASSWORD + if [ $? -ne 0 ]; then + echo "Failed to add partner. Exiting with status 1." + exit 1 + fi +fi + +# Run the security command +echo "Running security tests..." +$QIT_BINARY run:security woocommerce-payments --zip=woocommerce-payments.zip --wait +if [ $? -ne 0 ]; then + echo "Failed to run security command. Exiting with status 1." + exit 1 +fi