Skip to content

Commit e3c707d

Browse files
authored
Standardize signature parity testing, add Docker for testing
2 parents 4eabc08 + 6a0021d commit e3c707d

File tree

12 files changed

+485
-203
lines changed

12 files changed

+485
-203
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git
2+
.gitignore
3+
.docker-cache
4+
.env
5+
vendor
6+
node_modules
7+
transloadit-*.tgz

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ env.sh
88
.phpunit.cache
99
.aider*
1010
.env
11+
.docker-cache/

CHANGELOG.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
## Versions
1+
# Changelog
22

3-
### [main](https://github.com/transloadit/php-sdk/tree/main)
3+
## [main](https://github.com/transloadit/php-sdk/tree/main)
44

5-
diff: https://github.com/transloadit/php-sdk/compare/3.2.0...main
5+
diff: https://github.com/transloadit/php-sdk/compare/3.3.0...main
66

7-
### [3.2.0](https://github.com/transloadit/php-sdk/tree/3.2.0)
7+
## [3.3.0](https://github.com/transloadit/php-sdk/tree/3.3.0)
8+
9+
- Replace the custom Node parity helper with the official `transloadit` CLI for Smart CDN signatures
10+
- Add a Docker-based test harness and document the parity workflow
11+
- Randomize system-test request signatures and document optional `auth.nonce` usage to avoid replay protection failures
12+
13+
diff: https://github.com/transloadit/php-sdk/compare/3.2.0...3.3.0
14+
15+
## [3.2.0](https://github.com/transloadit/php-sdk/tree/3.2.0)
816

917
- Implement `signedSmartCDNUrl`
1018

1119
diff: https://github.com/transloadit/php-sdk/compare/3.1.0...3.2.0
1220

13-
### [3.1.0](https://github.com/transloadit/php-sdk/tree/3.1.0)
21+
## [3.1.0](https://github.com/transloadit/php-sdk/tree/3.1.0)
1422

1523
- Pass down `curlOptions` when `TransloaditRequest` reinstantiates itself for `waitForCompletion`
1624

1725
diff: https://github.com/transloadit/php-sdk/compare/3.0.4-dev...3.1.0
1826

19-
### [3.0.4-dev](https://github.com/transloadit/php-sdk/tree/3.0.4-dev)
27+
## [3.0.4-dev](https://github.com/transloadit/php-sdk/tree/3.0.4-dev)
2028

2129
- Pass down `curlOptions` when `TransloaditRequest` reinstantiates itself for `waitForCompletion`
2230

2331
diff: https://github.com/transloadit/php-sdk/compare/3.0.4...3.0.4-dev
2432

25-
### [3.0.4](https://github.com/transloadit/php-sdk/tree/3.0.4)
33+
## [3.0.4](https://github.com/transloadit/php-sdk/tree/3.0.4)
2634

2735
- Ditch `v` prefix in versions as that's more idiomatic
2836
- Bring back the getAssembly() function
@@ -34,7 +42,7 @@ diff: https://github.com/transloadit/php-sdk/compare/3.0.4...3.0.4-dev
3442

3543
diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...3.0.4
3644

37-
### [v2.1.0](https://github.com/transloadit/php-sdk/tree/v2.1.0)
45+
## [v2.1.0](https://github.com/transloadit/php-sdk/tree/v2.1.0)
3846

3947
- Fix for CURL deprecated functions (thanks @ABerkhout)
4048
- CI improvements (phpunit, travis, composer)
@@ -43,7 +51,7 @@ diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...3.0.4
4351

4452
diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...v2.1.0
4553

46-
### [v2.0.0](https://github.com/transloadit/php-sdk/tree/v2.0.0)
54+
## [v2.0.0](https://github.com/transloadit/php-sdk/tree/v2.0.0)
4755

4856
- Retire host + protocol in favor of one endpoint property,
4957
allow passing that on to the Request object.
@@ -52,14 +60,14 @@ diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...v2.1.0
5260

5361
diff: https://github.com/transloadit/php-sdk/compare/v1.0.1...v2.0.0
5462

55-
### [v1.0.1](https://github.com/transloadit/php-sdk/tree/v1.0.1)
63+
## [v1.0.1](https://github.com/transloadit/php-sdk/tree/v1.0.1)
5664

5765
- Fix broken examples
5866
- Improve documentation (version changelogs)
5967

6068
diff: https://github.com/transloadit/php-sdk/compare/v1.0.0...v1.0.1
6169

62-
### [v1.0.0](https://github.com/transloadit/php-sdk/tree/v1.0.0)
70+
## [v1.0.0](https://github.com/transloadit/php-sdk/tree/v1.0.0)
6371

6472
A big thanks to [@nervetattoo](https://github.com/nervetattoo) for making this version happen!
6573

@@ -69,7 +77,7 @@ A big thanks to [@nervetattoo](https://github.com/nervetattoo) for making this v
6977

7078
diff: https://github.com/transloadit/php-sdk/compare/v0.10.0...v1.0.0
7179

72-
### [v0.10.0](https://github.com/transloadit/php-sdk/tree/v0.10.0)
80+
## [v0.10.0](https://github.com/transloadit/php-sdk/tree/v0.10.0)
7381

7482
- Add support for Strict mode
7583
- Add support for more auth params
@@ -79,15 +87,15 @@ diff: https://github.com/transloadit/php-sdk/compare/v0.10.0...v1.0.0
7987

8088
diff: https://github.com/transloadit/php-sdk/compare/v0.9.1...v0.10.0
8189

82-
### [v0.9.1](https://github.com/transloadit/php-sdk/tree/v0.9.1)
90+
## [v0.9.1](https://github.com/transloadit/php-sdk/tree/v0.9.1)
8391

8492
- Improve documentation
8593
- Better handling of errors & non-json responses
8694
- Change directory layout
8795

8896
diff: https://github.com/transloadit/php-sdk/compare/v0.9...v0.9.1
8997

90-
### [v0.9](https://github.com/transloadit/php-sdk/tree/v0.9)
98+
## [v0.9](https://github.com/transloadit/php-sdk/tree/v0.9)
9199

92100
- Use markdown for docs
93101
- Add support for signed GET requests
@@ -97,12 +105,12 @@ diff: https://github.com/transloadit/php-sdk/compare/v0.9...v0.9.1
97105

98106
diff: https://github.com/transloadit/php-sdk/compare/v0.2...v0.9
99107

100-
### [v0.2](https://github.com/transloadit/php-sdk/tree/v0.2)
108+
## [v0.2](https://github.com/transloadit/php-sdk/tree/v0.2)
101109

102110
- Add error handling
103111

104112
diff: https://github.com/transloadit/php-sdk/compare/v0.1...v0.2
105113

106-
### [v0.1](https://github.com/transloadit/php-sdk/tree/v0.1)
114+
## [v0.1](https://github.com/transloadit/php-sdk/tree/v0.1)
107115

108116
The very first version

CONTRIBUTING.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Contributing
2+
3+
Feel free to fork this project. We will happily merge bug fixes or other small
4+
improvements. For bigger changes you should probably get in touch with us
5+
before you start to avoid not seeing them merged.
6+
7+
## Testing
8+
9+
### Basic Tests
10+
11+
```bash
12+
make test
13+
```
14+
15+
### System Tests
16+
17+
System tests require:
18+
19+
1. Valid Transloadit credentials in environment:
20+
21+
```bash
22+
export TRANSLOADIT_KEY='your-auth-key'
23+
export TRANSLOADIT_SECRET='your-auth-secret'
24+
```
25+
26+
Then run:
27+
28+
```bash
29+
make test-all
30+
```
31+
32+
### Node.js Reference Implementation Parity Assertions
33+
34+
The SDK includes assertions that compare Smart CDN URL signatures and regular request signatures with our reference Node.js implementation. To run these tests:
35+
36+
1. Requirements:
37+
38+
- Node.js 20+ with npm
39+
- Ability to execute `npx transloadit smart_sig` (the CLI is downloaded on demand)
40+
- Ability to execute `npx transloadit sig` (the CLI is downloaded on demand)
41+
42+
2. Run the tests:
43+
44+
```bash
45+
export TRANSLOADIT_KEY='your-auth-key'
46+
export TRANSLOADIT_SECRET='your-auth-secret'
47+
TEST_NODE_PARITY=1 make test-all
48+
```
49+
50+
If you want to warm the CLI cache ahead of time you can run:
51+
52+
```bash
53+
npx --yes transloadit smart_sig --help
54+
```
55+
56+
For regular request signatures, you can also prime the CLI by running:
57+
58+
```bash
59+
TRANSLOADIT_KEY=... TRANSLOADIT_SECRET=... \
60+
npx --yes transloadit sig --algorithm sha1 --help
61+
```
62+
63+
CI opts into `TEST_NODE_PARITY=1`, and you can optionally do this locally as well.
64+
65+
### Run Tests in Docker
66+
67+
Use `scripts/test-in-docker.sh` for a reproducible environment:
68+
69+
```bash
70+
./scripts/test-in-docker.sh
71+
```
72+
73+
This builds the local image, runs `composer install`, and executes `make test-all` (unit + integration tests). Pass a custom command to run something else (composer install still runs first):
74+
75+
```bash
76+
./scripts/test-in-docker.sh vendor/bin/phpunit --filter signedSmartCDNUrl
77+
```
78+
79+
Environment variables such as `TEST_NODE_PARITY` or the credentials in `.env` are forwarded, so you can combine parity checks and integration tests with Docker:
80+
81+
```bash
82+
TEST_NODE_PARITY=1 ./scripts/test-in-docker.sh
83+
```
84+
85+
## Releasing a new version
86+
87+
To release, say `3.2.0` [Packagist](https://packagist.org/packages/transloadit/php-sdk), follow these steps:
88+
89+
1. Make sure `PACKAGIST_TOKEN` is set in your `.env` file
90+
1. Make sure you are in main: `git checkout main`
91+
1. Update `CHANGELOG.md` and `composer.json`
92+
1. Commit: `git add CHANGELOG.md composer.json && git commit -m "Release 3.2.0"`
93+
1. Tag, push, and release: `source .env && VERSION=3.2.0 ./release.sh`
94+
95+
This project implements the [Semantic Versioning](http://semver.org/) guidelines.

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM php:8.3-cli AS base
4+
5+
ENV COMPOSER_ALLOW_SUPERUSER=1
6+
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
git \
10+
unzip \
11+
zip \
12+
libzip-dev \
13+
curl \
14+
ca-certificates \
15+
&& docker-php-ext-configure zip \
16+
&& docker-php-ext-install zip \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
20+
21+
# Install Node.js (for transloadit CLI parity checks)
22+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
23+
&& apt-get install -y --no-install-recommends nodejs \
24+
&& npm install -g npm@latest \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
WORKDIR /workspace

README.md

Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,23 @@ echo '</pre>';
276276
277277
<dfn>Signature Authentication</dfn> is done by the PHP SDK by default internally so you do not need to worry about this :)
278278
279+
If you script the same request payload multiple times in quick succession (for example inside a health check or tight integration test loop), add a random nonce to keep each signature unique:
280+
281+
```php
282+
$params = [
283+
'auth' => [
284+
'key' => 'MY_TRANSLOADIT_KEY',
285+
'expires' => gmdate('Y/m/d H:i:s+00:00', strtotime('+2 hours')),
286+
'nonce' => bin2hex(random_bytes(16)),
287+
],
288+
'steps' => [
289+
//
290+
],
291+
];
292+
```
293+
294+
The nonce is optional for regular usage, but including it in heavily scripted flows prevents Transloadit from rejecting repeated identical signatures.
295+
279296
### Signature Auth (Smart CDN)
280297
281298
You can use the `signedSmartCDNUrl` method to generate signed URLs for Transloadit's [Smart CDN](https://transloadit.com/services/content-delivery/):
@@ -522,74 +539,6 @@ All of the following will cause an error string to be returned:
522539
523540
**_Note_**: You will need to set waitForCompletion = True in the $Transloadit->createAssembly($options) function call.
524541
525-
## Contributing
526-
527-
Feel free to fork this project. We will happily merge bug fixes or other small
528-
improvements. For bigger changes you should probably get in touch with us
529-
before you start to avoid not seeing them merged.
530-
531-
### Testing
532-
533-
#### Basic Tests
534-
535-
```bash
536-
make test
537-
```
538-
539-
#### System Tests
540-
541-
System tests require:
542-
543-
1. Valid Transloadit credentials in environment:
544-
545-
```bash
546-
export TRANSLOADIT_KEY='your-auth-key'
547-
export TRANSLOADIT_SECRET='your-auth-secret'
548-
```
549-
550-
Then run:
551-
552-
```bash
553-
make test-all
554-
```
555-
556-
#### Node.js Reference Implementation Parity Assertions
557-
558-
The SDK includes assertions that compare URL signing with our reference Node.js implementation. To run these tests:
559-
560-
1. Requirements:
561-
562-
- Node.js installed
563-
- tsx installed globally (`npm install -g tsx`)
564-
565-
2. Install dependencies:
566-
567-
```bash
568-
npm install -g tsx
569-
```
570-
571-
3. Run the test:
572-
573-
```bash
574-
export TRANSLOADIT_KEY='your-auth-key'
575-
export TRANSLOADIT_SECRET='your-auth-secret'
576-
TEST_NODE_PARITY=1 make test-all
577-
```
578-
579-
CI opts-into `TEST_NODE_PARITY=1`, and you can optionally do this locally as well.
580-
581-
### Releasing a new version
582-
583-
To release, say `3.2.0` [Packagist](https://packagist.org/packages/transloadit/php-sdk), follow these steps:
584-
585-
1. Make sure `PACKAGIST_TOKEN` is set in your `.env` file
586-
1. Make sure you are in main: `git checkout main`
587-
1. Update `CHANGELOG.md` and `composer.json`
588-
1. Commit: `git add CHANGELOG.md composer.json && git commit -m "Release 3.2.0"`
589-
1. Tag, push, and release: `source env.sh && VERSION=3.2.0 ./release.sh`
590-
591-
This project implements the [Semantic Versioning](http://semver.org/) guidelines.
592-
593542
## License
594543
595544
[MIT Licensed](LICENSE)

0 commit comments

Comments
 (0)