-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Smart CDN Signature Auth helper #61
Conversation
test/SmartCDNNodeParityTest.php
Outdated
); | ||
$nodeUrl = $this->runNodeScript($params); | ||
|
||
$this->assertEquals($nodeUrl, $url, 'Generated URLs should match node implementation'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same comment as in the Ruby SDK. Can we also compare the generated URL against a static string here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what we have the unit tests for:
php-sdk/test/simple/TransloaditTest.php
Lines 149 to 178 in fe2748d
public function testSignedSmartCDNUrl() { | |
$transloadit = new Transloadit([ | |
'key' => 'test-key', | |
'secret' => 'test-secret' | |
]); | |
// Test basic URL generation | |
$url = $transloadit->signedSmartCDNUrl('workspace', 'template', 'file.jpg'); | |
$this->assertStringStartsWith('https://workspace.tlcdn.com/template/file.jpg', $url); | |
$this->assertStringContainsString('auth_key=test-key', $url); | |
$this->assertStringContainsString('sig=sha256%3A', $url); | |
// Test with input field | |
$url = $transloadit->signedSmartCDNUrl('workspace', 'template', 'input.jpg'); | |
$this->assertStringStartsWith('https://workspace.tlcdn.com/template/input.jpg', $url); | |
// Test with additional params | |
$url = $transloadit->signedSmartCDNUrl('workspace', 'template', 'file.jpg', ['width' => 100]); | |
$this->assertStringContainsString('width=100', $url); | |
// Test with custom sign props | |
$url = $transloadit->signedSmartCDNUrl( | |
'workspace', | |
'template', | |
'file.jpg', | |
[], | |
['authKey' => 'custom-key', 'authSecret' => 'custom-secret', 'expiryMs' => 60000] | |
); | |
$this->assertStringContainsString('auth_key=custom-key', $url); | |
} |
The parity test is to check it against the reference implementation. When we make changes, it's nice to see if the reference implementation would disagree in CI. After we finalize the reference implementation in the Node SDK, I'll use that SDK to verify parity, instead of this copy pasted function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing to these unit tests. I think it would be useful if they assert the entire URL and not just parts of it, making the test case easier to understand/debug and help find subtle bugs outside of the examined parts of the URL.
The method has a field to define the expiration time, so it should be possible to generate them deterministically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now merged parity tests with regular tests to make it a bit more obvious, as well as checking both against hardcoded URLs
test/SmartCDNNodeParityTest.php
Outdated
$url = $this->transloadit->signedSmartCDNUrl( | ||
$params['workspace'], | ||
$params['template'], | ||
$params['input'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test name suggests that this logic covers situations where input
might be empty, but as far as I can tell $params['input']
is always non-empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty string input is now allowed
lib/transloadit/Transloadit.php
Outdated
foreach ($params as $key => $value) { | ||
if (is_array($value)) { | ||
foreach ($value as $val) { | ||
if ($val !== null && $val !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in the Ruby SDK PR. Can we allow empty string values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want the empty parameter to show up? I don't think the node implementation did that at the time of writing?
For instance:
// Test with empty param string
$url = $transloadit->signedSmartCDNUrl('workspace', 'template', 'file.jpg', ['width' => '', 'height' => '200']);
$this->assertStringNotContainsString('width=', $url, 'Empty parameter should be excluded from URL');
or
// Test with empty param string
$url = $transloadit->signedSmartCDNUrl('workspace', 'template', 'file.jpg', ['width' => '', 'height' => '200']);
$this->assertStringContainsString('width=', $url, 'Empty parameter should be excluded from URL');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect the parameter to show up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's also fix this on the node side then, currently these SDKs are complaining about that bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe it was a bad port by me 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Node SDK PR already supports empty values in my tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty string e.g. width
is now supported and will be shown in the URL
Coverage report for commit: 09c9e2d Summary - Lines: 91.02% | Methods: 69.57%
🤖 comment via lucassabreu/comment-coverage-clover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am no PHP expert but the logic looks sounds
Released as 3.2.0 |
Allows you to generate signed URLs for Transloadit's Smart CDN.