|
2 | 2 |
|
3 | 3 | namespace VaasTesting; |
4 | 4 |
|
| 5 | +use Amp\File\Driver\BlockingFilesystemDriver; |
| 6 | +use Amp\File\File; |
| 7 | +use Amp\File\FilesystemDriver; |
5 | 8 | use Amp\File\FilesystemException; |
6 | 9 | use Dotenv\Dotenv; |
7 | 10 | use Monolog\Formatter\JsonFormatter; |
|
14 | 17 | use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator; |
15 | 18 | use VaasSdk\Exceptions\InvalidSha256Exception; |
16 | 19 | use VaasSdk\Exceptions\VaasClientException; |
| 20 | +use VaasSdk\Options\ForFileOptions; |
17 | 21 | use VaasSdk\Options\ForSha256Options; |
18 | 22 | use VaasSdk\Options\VaasOptions; |
19 | 23 | use VaasSdk\Sha256; |
20 | 24 | use VaasSdk\Vaas; |
21 | 25 | use VaasSdk\Verdict; |
| 26 | +use function Amp\File\filesystem; |
22 | 27 | use function Amp\File\openFile; |
23 | 28 |
|
24 | 29 | final class VaasTest extends TestCase |
@@ -274,6 +279,117 @@ public function testForFile_WithInvalidFile_ThrowsVaasClientException(): void |
274 | 279 | $this->vaas->forFileAsync(__DIR__ . "/invalid")->await(); |
275 | 280 | } |
276 | 281 |
|
| 282 | + public function testForFile_WithCustomFilesystemDriver_UtilizesDriver(): void |
| 283 | + { |
| 284 | + $file = file_get_contents(self::PUP_URL); |
| 285 | + file_put_contents(__DIR__ . "/PotentiallyUnwantedCustomDriver.exe", $file); |
| 286 | + $customDriverCalled = false; |
| 287 | + $customDriver = new class( |
| 288 | + function () use (&$customDriverCalled) { |
| 289 | + $customDriverCalled = true; |
| 290 | + } |
| 291 | + ) implements FileSystemDriver { |
| 292 | + private $callback; |
| 293 | + |
| 294 | + public function __construct(callable $callback) |
| 295 | + { |
| 296 | + $this->callback = $callback; |
| 297 | + } |
| 298 | + |
| 299 | + public function openFile(string $path, string $mode): File |
| 300 | + { |
| 301 | + ($this->callback)(); |
| 302 | + return filesystem(new BlockingFilesystemDriver())->openFile($path, $mode); |
| 303 | + } |
| 304 | + |
| 305 | + public function getStatus(string $path): ?array |
| 306 | + { |
| 307 | + return filesystem(new BlockingFilesystemDriver())->getStatus($path); |
| 308 | + } |
| 309 | + |
| 310 | + public function getLinkStatus(string $path): ?array |
| 311 | + { |
| 312 | + throw new BadMethodCallException('Not implemented'); |
| 313 | + } |
| 314 | + |
| 315 | + public function createSymlink(string $target, string $link): void |
| 316 | + { |
| 317 | + throw new BadMethodCallException('Not implemented'); |
| 318 | + } |
| 319 | + |
| 320 | + public function createHardlink(string $target, string $link): void |
| 321 | + { |
| 322 | + throw new BadMethodCallException('Not implemented'); |
| 323 | + } |
| 324 | + |
| 325 | + public function resolveSymlink(string $target): string |
| 326 | + { |
| 327 | + throw new BadMethodCallException('Not implemented'); |
| 328 | + } |
| 329 | + |
| 330 | + public function move(string $from, string $to): void |
| 331 | + { |
| 332 | + throw new BadMethodCallException('Not implemented'); |
| 333 | + } |
| 334 | + |
| 335 | + public function deleteFile(string $path): void |
| 336 | + { |
| 337 | + throw new BadMethodCallException('Not implemented'); |
| 338 | + } |
| 339 | + |
| 340 | + public function createDirectory(string $path, int $mode = 0777): void |
| 341 | + { |
| 342 | + throw new BadMethodCallException('Not implemented'); |
| 343 | + } |
| 344 | + |
| 345 | + public function createDirectoryRecursively(string $path, int $mode = 0777): void |
| 346 | + { |
| 347 | + throw new BadMethodCallException('Not implemented'); |
| 348 | + } |
| 349 | + |
| 350 | + public function deleteDirectory(string $path): void |
| 351 | + { |
| 352 | + throw new BadMethodCallException('Not implemented'); |
| 353 | + } |
| 354 | + |
| 355 | + public function listFiles(string $path): array |
| 356 | + { |
| 357 | + throw new BadMethodCallException('Not implemented'); |
| 358 | + } |
| 359 | + |
| 360 | + public function changePermissions(string $path, int $mode): void |
| 361 | + { |
| 362 | + throw new BadMethodCallException('Not implemented'); |
| 363 | + } |
| 364 | + |
| 365 | + public function changeOwner(string $path, ?int $uid, ?int $gid): void |
| 366 | + { |
| 367 | + throw new BadMethodCallException('Not implemented'); |
| 368 | + } |
| 369 | + |
| 370 | + public function touch(string $path, ?int $modificationTime, ?int $accessTime): void |
| 371 | + { |
| 372 | + throw new BadMethodCallException('Not implemented'); |
| 373 | + } |
| 374 | + |
| 375 | + public function read(string $path): string |
| 376 | + { |
| 377 | + throw new BadMethodCallException('Not implemented'); |
| 378 | + } |
| 379 | + |
| 380 | + public function write(string $path, string $contents): void |
| 381 | + { |
| 382 | + throw new BadMethodCallException('Not implemented'); |
| 383 | + } |
| 384 | + }; |
| 385 | + |
| 386 | + $verdict = $this->vaas->forFileAsync(__DIR__ . "/PotentiallyUnwantedCustomDriver.exe", new ForFileOptions(false, false, ForFileOptions::DEFAULT_TIMEOUT, $customDriver))->await(); |
| 387 | + |
| 388 | + unlink(__DIR__ . "/PotentiallyUnwantedCustomDriver.exe"); |
| 389 | + $this->assertEquals(Verdict::PUP, $verdict->verdict); |
| 390 | + $this->assertTrue($customDriverCalled, "custom driver not called"); |
| 391 | + } |
| 392 | + |
277 | 393 | public function testForStream_WithCleanStream_GetsCleanResponse(): void |
278 | 394 | { |
279 | 395 | try { |
|
0 commit comments