@@ -23,6 +23,7 @@ public function testAttributes() {
2323 $ this ->assertEquals ($ this ->request ->secret , null );
2424 $ this ->assertEquals ($ this ->request ->params , []);
2525 $ this ->assertEquals ($ this ->request ->expires , '+2 hours ' );
26+ $ this ->assertEquals ($ this ->request ->signatureAlgorithm , 'sha384 ' );
2627 $ this ->assertEquals ('Expect: ' , $ this ->request ->headers [0 ]);
2728 $ this ->assertContains ('Transloadit-Client: php-sdk:%s ' , $ this ->request ->headers );
2829 }
@@ -99,13 +100,28 @@ public function testSignString() {
99100 // No secret, no signature
100101 $ this ->assertEquals (null , $ this ->request ->signString ('foo ' ));
101102
102- // Verify the test vector given in the documentation, see: http://transloadit.com/docs/authentication
103+ // Verify the test vector (default sha384 + algorithm prefix)
103104 $ this ->request ->secret = 'd805593620e689465d7da6b8caf2ac7384fdb7e9 ' ;
104- $ expectedSignature = 'fec703ccbe36b942c90d17f64b71268ed4f5f512 ' ;
105+ $ expectedSignature = 'sha384:69b74f954488cbb571cace210ae9039d18d84ec57edc784d19fd364f4295c99c93c14f0fed7f245b480d5856f12effc2 ' ;
105106
106107 $ params = '{"auth":{"expires":"2010\/10\/19 09:01:20+00:00","key":"2b0c45611f6440dfb64611e872ec3211"},"steps":{"encode":{"robot":"\/video\/encode"}}} ' ;
107108 $ signature = $ this ->request ->signString ($ params );
108109 $ this ->assertEquals ($ expectedSignature , $ signature );
110+
111+ // Explicit algorithm override for legacy keys
112+ $ legacySignature = $ this ->request ->signString ($ params , 'sha1 ' );
113+ $ this ->assertEquals ('sha1:fec703ccbe36b942c90d17f64b71268ed4f5f512 ' , $ legacySignature );
114+
115+ // Request-level override should affect default signing behavior
116+ $ this ->request ->signatureAlgorithm = 'sha1 ' ;
117+ $ this ->assertEquals ('sha1:fec703ccbe36b942c90d17f64b71268ed4f5f512 ' , $ this ->request ->signString ($ params ));
118+ }
119+
120+ public function testSignStringWithInvalidAlgorithmThrowsInvalidArgumentException () {
121+ $ this ->request ->secret = 'secret ' ;
122+ $ this ->expectException (\InvalidArgumentException::class);
123+ $ this ->expectExceptionMessage ('Unsupported signature algorithm: definitely-not-a-real-algorithm ' );
124+ $ this ->request ->signString ('payload ' , 'definitely-not-a-real-algorithm ' );
109125 }
110126
111127 public function testGetParamsString () {
@@ -146,7 +162,7 @@ public function testSignatureParityWithNodeCli(): void {
146162 'width ' => 320 ,
147163 ],
148164 ],
149- ], 'cli-key ' , 'cli-secret ' , 'sha1 ' );
165+ ], 'cli-key ' , 'cli-secret ' , 'sha384 ' );
150166
151167 $ this ->assertNotNull ($ cliResult );
152168 $ this ->assertArrayHasKey ('signature ' , $ cliResult );
@@ -166,8 +182,9 @@ public function testSignatureParityWithNodeCli(): void {
166182 $ cliParams ['steps ' ]['resize ' ]['width ' ]
167183 );
168184
169- $ expectedSignature = hash_hmac ('sha1 ' , $ cliResult ['params ' ], 'cli-secret ' );
170- $ this ->assertEquals ('sha1: ' . $ expectedSignature , $ cliResult ['signature ' ]);
185+ $ expectedSignature = hash_hmac ('sha384 ' , $ cliResult ['params ' ], 'cli-secret ' );
186+ $ this ->assertEquals ('sha384: ' . $ expectedSignature , $ cliResult ['signature ' ]);
187+ $ this ->assertEquals ($ cliResult ['signature ' ], $ request ->signString ($ cliResult ['params ' ]));
171188 }
172189
173190 public function testExecute () {
0 commit comments