createServerModel(); $backup = Backup::factory()->for($server)->create(['disk' => Backup::ADAPTER_WINGS]); $url = $this->app->make(GeneratesBackupDownloadLinks::class)->generate($backup, $server->user); expect($url)->toStartWith($prefix = $server->node->getConnectionAddress().'/download/backup?token='); $config = Configuration::forSymmetricSigner(new Sha256(), $key = InMemory::plainText($server->node->getDecryptedKey())); $config = $config->withValidationConstraints(new SignedWith(new Sha256(), $key)); /** @var Plain $token */ $token = $config->parser()->parse(mb_substr($url, mb_strlen($prefix))); expect($config->validator()->validate($token, ...$config->validationConstraints()))->toBeTrue('Failed to validate that the JWT data returned was signed using the Node\'s secret key.'); $timestamp = CarbonImmutable::createFromTimestamp(CarbonImmutable::now()->getTimestamp())->timezone('UTC'); // Check that the claims are generated correctly. expect($token->hasBeenIssuedBy(config('app.url')))->toBeTrue(); expect($token->isPermittedFor($server->node->getConnectionAddress()))->toBeTrue(); expect($token->claims()->get('iat'))->toEqual($timestamp); expect($token->claims()->get('nbf'))->toEqual($timestamp->subMinutes(5)); expect($token->claims()->get('exp'))->toEqual($timestamp->addMinutes(15)); expect($token->claims()->get('backup_uuid'))->toBe($backup->uuid); expect($token->claims()->get('server_uuid'))->toBe($server->uuid); expect($token->claims()->get('scope'))->toEqual(JwtScope::BackupDownload->value); });