-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from keboola/adamvyborny-DBT-26
Escape username and password in repository URL
- Loading branch information
Showing
2 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,27 @@ public function testListBranchesEmptyGitProject(): void | |
self::assertEmpty($branches); | ||
} | ||
|
||
/** | ||
* @dataProvider getUrlValidParameters | ||
*/ | ||
public function testGetRepositoryUrl( | ||
string $url, | ||
?string $username, | ||
?string $password, | ||
string $expectedUrl | ||
): void { | ||
$gitService = new GitRepositoryService($this->dataDir); | ||
self::assertSame($expectedUrl, $gitService->getUrl($url, $username, $password)); | ||
} | ||
|
||
public function testGetInvalidRepositoryUrl(): void | ||
{ | ||
$this->expectException(UserException::class); | ||
$this->expectExceptionMessage('Wrong URL format "invalid url"'); | ||
$gitService = new GitRepositoryService($this->dataDir); | ||
$gitService->getUrl('invalid url'); | ||
} | ||
|
||
/** | ||
* @dataProvider privateRepositoryInvalidCredentials | ||
*/ | ||
|
@@ -156,4 +177,33 @@ public function privateRepositoryInvalidCredentials(): Generator | |
'errorMsg' => 'Wrong URL format "some random string"', | ||
]; | ||
} | ||
|
||
public function getUrlValidParameters(): Generator | ||
{ | ||
yield 'public repository' => [ | ||
'url' => 'https://github.com/keboola/dbt-test-project-public', | ||
'username' => null, | ||
'password' => null, | ||
'expectedUrl' => 'https://github.com/keboola/dbt-test-project-public', | ||
]; | ||
|
||
yield 'private repository' => [ | ||
'url' => 'https://github.com/keboola/dbt-test-project.git', | ||
'username' => getenv('GITHUB_USERNAME') ?: '', | ||
'password' => getenv('GITHUB_PASSWORD') ?: '', | ||
'expectedUrl' => sprintf( | ||
'https://%s:%s@%s', | ||
getenv('GITHUB_USERNAME') ?: '', | ||
getenv('GITHUB_PASSWORD') ?: '', | ||
'github.com/keboola/dbt-test-project.git', | ||
), | ||
]; | ||
|
||
yield 'private repository with special chars' => [ | ||
'url' => 'https://github.com/keboola/dbt-test-project.git', | ||
'username' => '[email protected]', | ||
'password' => '/some@password!', | ||
'expectedUrl' => 'https://user%40company.com:%2Fsome%40password%[email protected]/keboola/dbt-test-project.git', | ||
]; | ||
} | ||
} |