From 65504b72bb5a14ec7dadf5ad984b476eb7b1ba02 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 10 Jan 2022 23:08:48 +0000 Subject: [PATCH] [TOOLS] Setup pa11y to run on pages after codeception --- Makefile | 2 +- docker/accessibility | 1 - .../tooling/acceptance_and_accessibility.sh | 3 +++ docker/tooling/docker-compose.yaml | 14 +++++++++---- docker/tooling/pa11y/Dockerfile | 8 +++++++ docker/tooling/pa11y/sshd_config | 7 +++++++ docker/tooling/{ => php}/Dockerfile | 2 +- .../Helper/AccessibilityValidator.php | 21 +++++++------------ .../{FirstCest.php => LoggedOutCest.php} | 7 ++----- tests/CodeCeption/pa11y-config.js | 5 +++++ tests/CodeCeption/pa11y-config.json | 6 ++++++ 11 files changed, 51 insertions(+), 25 deletions(-) delete mode 160000 docker/accessibility create mode 100755 docker/tooling/acceptance_and_accessibility.sh create mode 100644 docker/tooling/pa11y/Dockerfile create mode 100644 docker/tooling/pa11y/sshd_config rename docker/tooling/{ => php}/Dockerfile (81%) rename tests/CodeCeption/acceptance/{FirstCest.php => LoggedOutCest.php} (60%) create mode 100644 tests/CodeCeption/pa11y-config.js create mode 100644 tests/CodeCeption/pa11y-config.json diff --git a/Makefile b/Makefile index fcb4ec4eb7..15ec1f2ea2 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ tooling-php-shell: tooling-docker docker exec -it $(call translate-container-name,tooling_php_1) sh acceptance-and-accessibility: tooling-docker - docker exec -it $(call translate-container-name,tooling_php_1) sh -c "SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/codecept run" + docker exec -it $(call translate-container-name,tooling_php_1) /var/tooling/acceptance_and_accessibility.sh test: tooling-docker docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'') diff --git a/docker/accessibility b/docker/accessibility deleted file mode 160000 index abcd45f8ec..0000000000 --- a/docker/accessibility +++ /dev/null @@ -1 +0,0 @@ -Subproject commit abcd45f8ecd361ae1b84cc40df4dbf2548735035 diff --git a/docker/tooling/acceptance_and_accessibility.sh b/docker/tooling/acceptance_and_accessibility.sh new file mode 100755 index 0000000000..b4a2d17b46 --- /dev/null +++ b/docker/tooling/acceptance_and_accessibility.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/codecept run diff --git a/docker/tooling/docker-compose.yaml b/docker/tooling/docker-compose.yaml index 4f29c2135c..fe872f1607 100644 --- a/docker/tooling/docker-compose.yaml +++ b/docker/tooling/docker-compose.yaml @@ -2,10 +2,11 @@ version: '3' services: php: - build: . + build: php depends_on: - db - redis + - pa11y volumes: # Entrypoint - ../php/entrypoint.sh:/entrypoint.sh @@ -13,6 +14,7 @@ services: - ../social/install.sh:/var/entrypoint.d/0_social_install.sh - ./coverage.sh:/var/tooling/coverage.sh - ./phpstan.sh:/var/tooling/phpstan.sh + - ./acceptance_and_accessibility.sh:/var/tooling/acceptance_and_accessibility.sh # Main files - ../../:/var/www/social - /var/www/social/docker # exclude docker folder @@ -28,9 +30,6 @@ services: - php restart: always tty: false - # ports: - # - "8080:80" - # - "4443:443" volumes: # Nginx - ../nginx/nginx.conf:/var/nginx/social.conf @@ -44,6 +43,13 @@ services: - ../bootstrap/bootstrap.env command: /bin/sh -c '/var/nginx/domain.sh; nginx -g "daemon off;"' + pa11y: + build: pa11y + volumes: + - ../../tests/CodeCeption/pa11y-config.json:/pa11y/config.json + cap_add: + - SYS_ADMIN + db: image: postgres:alpine environment: diff --git a/docker/tooling/pa11y/Dockerfile b/docker/tooling/pa11y/Dockerfile new file mode 100644 index 0000000000..ec4d19b402 --- /dev/null +++ b/docker/tooling/pa11y/Dockerfile @@ -0,0 +1,8 @@ +FROM node + +RUN apt-get update && apt-get -y install npm openssh-server && npm install -g pa11y + +COPY sshd_config /etc/ssh/sshd_config +RUN echo 'root:pa11y' | chpasswd + +ENTRYPOINT service ssh start && sleep infinity diff --git a/docker/tooling/pa11y/sshd_config b/docker/tooling/pa11y/sshd_config new file mode 100644 index 0000000000..9958f5037a --- /dev/null +++ b/docker/tooling/pa11y/sshd_config @@ -0,0 +1,7 @@ +ChallengeResponseAuthentication no +ListenAddress 0.0.0.0 +PasswordAuthentication yes +PermitEmptyPasswords yes +PermitRootLogin yes +Port 22 + diff --git a/docker/tooling/Dockerfile b/docker/tooling/php/Dockerfile similarity index 81% rename from docker/tooling/Dockerfile rename to docker/tooling/php/Dockerfile index 3896571d03..b12aff6a34 100644 --- a/docker/tooling/Dockerfile +++ b/docker/tooling/php/Dockerfile @@ -7,4 +7,4 @@ RUN apk update \ && pecl install xdebug \ && docker-php-ext-enable xdebug -RUN apk add npm && npm install -g pa11y +RUN apk add --no-cache openssh sshpass diff --git a/tests/CodeCeption/_support/Helper/AccessibilityValidator.php b/tests/CodeCeption/_support/Helper/AccessibilityValidator.php index 497ee2a674..e6aa55da13 100644 --- a/tests/CodeCeption/_support/Helper/AccessibilityValidator.php +++ b/tests/CodeCeption/_support/Helper/AccessibilityValidator.php @@ -92,21 +92,16 @@ class AccessibilityValidator extends \Codeception\Module throw new Exception('Unknown standard: ' . $standard); } - $pa11yPath = $this->_getConfig('pa11yPath'); - if (!$pa11yPath) { - $pa11yPath = 'pa11y'; - } - if (!file_exists($pa11yPath)) { - throw new Exception('pa11y not found: ' . $pa11yPath); - } + exec('sshpass -p pa11y ssh -o StrictHostKeyChecking=no pa11y 2>/dev/null pa11y -c /pa11y/config.json' . ' -s ' . $standard . " -r json '" . addslashes($url) . "'", $output); - exec($pa11yPath . ' -s ' . $standard . " -r json '" . addslashes($url) . "'", $return); - $data = json_decode($return[0], true); - if (!$data) { - $msg = 'Invalid data returned from validation service: '; - throw new Exception($msg . $return); + if (!empty($output)) { + $data = json_decode($output[0], true); + if (!$data) { + throw new Exception('Invalid data returned from validation service: ' . implode("\n", $output)); + } + return $data; } - return $data; + return []; } /** diff --git a/tests/CodeCeption/acceptance/FirstCest.php b/tests/CodeCeption/acceptance/LoggedOutCest.php similarity index 60% rename from tests/CodeCeption/acceptance/FirstCest.php rename to tests/CodeCeption/acceptance/LoggedOutCest.php index 8ba79c308f..c75dddb7f5 100644 --- a/tests/CodeCeption/acceptance/FirstCest.php +++ b/tests/CodeCeption/acceptance/LoggedOutCest.php @@ -2,15 +2,12 @@ declare(strict_types = 1); -class FirstCest +class LoggedOutCest { - public function _before(AcceptanceTester $I) - { - } - public function root(AcceptanceTester $I) { $I->amOnPage('/'); $I->see('Feed'); + $I->validatePa11y(\Helper\AccessibilityValidator::STANDARD_WCAG2AAA); } } diff --git a/tests/CodeCeption/pa11y-config.js b/tests/CodeCeption/pa11y-config.js new file mode 100644 index 0000000000..4f1794676c --- /dev/null +++ b/tests/CodeCeption/pa11y-config.js @@ -0,0 +1,5 @@ +{ + "chromeLaunchConfig": { + "args": ["--no-sandbox"] + } +} diff --git a/tests/CodeCeption/pa11y-config.json b/tests/CodeCeption/pa11y-config.json new file mode 100644 index 0000000000..55f35f6f1b --- /dev/null +++ b/tests/CodeCeption/pa11y-config.json @@ -0,0 +1,6 @@ +{ + "chromeLaunchConfig": { + "args": ["--no-sandbox"], + "ignoreHTTPSErrors": true + } +}