Skip to content

Commit

Permalink
SECURITY-480: compatibility with the central test suite
Browse files Browse the repository at this point in the history
Co-authored-by: Laszlo Losonczy <laszlo.losonczy@emarsys.com>
Co-authored-by: Dora Kaszasne Sztanko <dora.sztanko@emarsys.com>
  • Loading branch information
3 people committed Jun 14, 2024
1 parent 4f04b42 commit 9eaa1b7
Show file tree
Hide file tree
Showing 29 changed files with 1,359 additions and 1,126 deletions.
64 changes: 36 additions & 28 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
name: PHP

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']

steps:
- name: Install prerequesits
run: sudo apt update && sudo apt install -y php-mbstring
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring
tools: composer
- name: Install dependencies
run: composer update && composer install
- name: Test
run: composer test
- name: Deploy
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
run: |
curl -XPOST -f -H'content-type:application/json' "https://packagist.org/api/update-package?username=emartech&apiToken=${{secrets.PACKAGIST_API_TOKEN}}" -d"{\"repository\":{\"url\":\"${{secrets.PACKAGIST_PACKAGE_URL}}\"}}"
name: PHP

on:
push:
branches: [ master ]
tags:
- 'v*'
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- name: Install prerequesits
run: sudo apt update && sudo apt install -y php-mbstring
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring
tools: composer
- name: Install dependencies
run: composer update && composer install
- name: Test
run: composer test
- name: Deploy
if: startsWith(github.ref, 'refs/tags') && matrix.php-versions == '8.3'
run: |
curl -XPOST -f -H'content-type:application/json' "https://packagist.org/api/update-package?username=emartech&apiToken=${{secrets.PACKAGIST_API_TOKEN}}" -d"{\"repository\":{\"url\":\"${{secrets.PACKAGIST_PACKAGE_URL}}\"}}"
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test-cases"]
path = test-cases
url = git@github.com:EscherAuth/test-cases.git
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM php:7.3-alpine3.15

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 2.2.23

RUN set -eux ; \
apk add --no-cache --virtual .composer-rundeps \
bash \
coreutils \
git \
make \
openssh-client \
patch \
subversion \
tini \
bzip2 \
bzip2-dev \
zlib \
zlib-dev \
libzip \
libzip-dev \
unzip \
zip

RUN set -eux ; \
# install necessary/useful extensions not included in base image
docker-php-ext-install \
bz2 \
zip \
; \
# download installer.php, see https://getcomposer.org/download/
curl \
--silent \
--fail \
--location \
--retry 3 \
--output /tmp/installer.php \
--url https://raw.githubusercontent.com/composer/getcomposer.org/f24b8f860b95b52167f91bbd3e3a7bcafe043038/web/installer \
; \
# install composer phar binary
php /tmp/installer.php \
--no-ansi \
--install-dir=/usr/bin \
--filename=composer \
--version=${COMPOSER_VERSION} \
; \
composer --ansi --version --no-interaction ; \
composer diagnose ; \
rm -f /tmp/installer.php ; \
find /tmp -type d -exec chmod -v 1777 {} + \
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
tests: ## Run tests in docker
@docker-compose up -d --build
@docker-compose run web /bin/bash -l -c "/var/www/html/vendor/bin/phpunit -c /var/www/html/test/phpunit.xml"
.PHONY: test

build: ; docker compose build

install: ; docker compose run --rm web composer install
update: ; docker compose run --rm web composer update

test: ; docker compose run --rm web ./vendor/bin/phpunit --do-not-cache-result -c phpunit.xml
test-only: ; docker compose run --rm web ./vendor/bin/phpunit --do-not-cache-result --group only -c phpunit.xml

38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ Exceptions
| 5xxx | Expired exception |
| 6xxx | Signature exceptions |

| Code | Message |
|------|-------------------------------------------------------------------------------------|
| 1001 | Escher authentication is missing |
| 1100 | The {PARAM} header is missing |
| 1101 | Query key: {PARAM} is missing |
| 1102 | The host header is missing |
| 2001 | Date header is invalid, the expected format is Wed, 04 Nov 2015 09:20:22 GMT |
| 2002 | Auth header format is invalid |
| 2003 | Invalid {PARAM} query key format |
| 2004 | Date header is invalid, the expected format is 20151104T092022Z |
| 3001 | Invalid Escher key |
| 3002 | Hash algorithm is invalid. Only SHA256 and SHA512 are allowed |
| 3003 | Credential scope is invalid |
| 3004 | Date in the authorization header is invalid. It must be the same as the date header |
| 4001 | The host header is not signed |
| 4002 | The {PARAM} header is not signed |
| 5001 | The request date is not within the accepted time range |
| 6001 | The signatures do not match |
| Code | Message |
|------|------------------------------------------------------------------------------|
| 1001 | The authorization header is missing |
| 1100 | The {PARAM} header is missing |
| 1101 | Query key: {PARAM} is missing |
| 1102 | The host header is missing |
| 2001 | Date header is invalid, the expected format is Wed, 04 Nov 2015 09:20:22 GMT |
| 2002 | Could not parse auth header |
| 2003 | Invalid {PARAM} query key format |
| 2004 | Date header is invalid, the expected format is 20151104T092022Z |
| 3001 | Invalid Escher key |
| 3002 | Only SHA256 and SHA512 hash algorithms are allowed |
| 3003 | The credential scope is invalid |
| 3004 | The credential date does not match with the request date |
| 4001 | The host header is not signed |
| 4002 | The {PARAM} header is not signed |
| 5001 | The request date is not within the accepted time range |
| 6001 | The signatures do not match |

Configuration
-------------
Expand All @@ -115,4 +115,4 @@ TBA
Running tests
-------------
1. Install packages with Composer: `composer install`
2. Run tests with `make tests`
2. Run tests with `make tests`
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
],
"type": "library",
"autoload": {
"psr-4": {"": "src/"}
"psr-4": {"Escher\\": "src/Escher"}
},
"autoload-dev": {
"psr-4": {"Escher\\Test\\": "test/Escher/Test"}
},
"require": {
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "9.5.3"
"ext-json": "*",
"phpunit/phpunit": "9.6.19"
},
"keywords": [
"escher",
Expand Down
Loading

0 comments on commit 9eaa1b7

Please sign in to comment.