Skip to content

Commit

Permalink
Stricter Utils::getStackFromProjectUrl() arg validation (does not acc…
Browse files Browse the repository at this point in the history
…ept URL without scheme)
  • Loading branch information
romantmb committed May 10, 2024
1 parent 8633ce5 commit b282c8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public static function checkMigrationApps(Client $sourceProjectClient, Client $d

public static function getStackFromProjectUrl(string $url): string
{
if (!preg_match('~^https?://~', $url)) {
$url = 'https://' . $url;
}

$validator = Validation::createValidator();
$violations = $validator->validate($url, new Url());
if (count($violations) > 0) {
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public function testMigrateSuccess(
$config,
$sourceJobRunnerMock,
$destJobRunnerMock,
'xxx-b',
'yyy-b',
'https://dest-stack/',
'dest-token',
$loggerMock,
);

Expand Down Expand Up @@ -209,9 +209,9 @@ public function testMigrateSuccess(
$loggerMock->expects(self::exactly(3))
->method('debug')
->withConsecutive(
[self::equalTo('Configuration with ID \'101\' successfully migrated to stack \'xxx-b\'.')],
[self::equalTo('Configuration with ID \'102\' successfully migrated to stack \'xxx-b\'.')],
[self::equalTo('Configuration with ID \'201\' successfully migrated to stack \'xxx-b\'.')]
[self::equalTo('Configuration with ID \'101\' successfully migrated to stack \'dest-stack\'.')],
[self::equalTo('Configuration with ID \'102\' successfully migrated to stack \'dest-stack\'.')],
[self::equalTo('Configuration with ID \'201\' successfully migrated to stack \'dest-stack\'.')]
);
} else {
$migrationsClientMock->expects(self::never())->method('migrateConfiguration');
Expand Down
15 changes: 9 additions & 6 deletions tests/phpunit/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ public function testMissingDestinationApp(): void

public function testStackFromProjectUrl(): void
{
self::assertSame(
'connection.keboola.com',
Utils::getStackFromProjectUrl('connection.keboola.com/')
);

self::assertSame(
'connection.europe-west3.gcp.keboola.com',
Utils::getStackFromProjectUrl('https://connection.europe-west3.gcp.keboola.com/')
Expand All @@ -162,12 +157,20 @@ public function testStackFromProjectUrl(): void

self::assertSame(
'connection.e2e.us-east-1.aws.keboola.dev',
Utils::getStackFromProjectUrl('connection.e2e.us-east-1.aws.keboola.dev')
Utils::getStackFromProjectUrl('https://connection.e2e.us-east-1.aws.keboola.dev')
);
}

public function testStackFromInvalidProjectUrl(): void
{
$this->expectException(UserException::class);
$this->expectExceptionMessage('Invalid destination project URL: "connection.keboola.com/".');
Utils::getStackFromProjectUrl('connection.keboola.com/');

$this->expectException(UserException::class);
$this->expectExceptionMessage('Invalid destination project URL: "connection.e2e.us-east-1.aws.keboola.dev".');
Utils::getStackFromProjectUrl('connection.e2e.us-east-1.aws.keboola.dev');

$this->expectException(UserException::class);
$this->expectExceptionMessage('Invalid destination project URL: "https://htt://invalid-url.com".');
Utils::getStackFromProjectUrl('htt://invalid-url.com');
Expand Down

0 comments on commit b282c8b

Please sign in to comment.