-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Support Basic authentication for devfile factory URL
- Loading branch information
Showing
1 changed file
with
19 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,34 +17,38 @@ | |
|
||
import java.util.Optional; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
/** Testing {@link DefaultFactoryUrl} */ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class DefaultFactoryUrlTest { | ||
@Test | ||
public void shouldCredentials() { | ||
@Test(dataProvider = "urlsProvider") | ||
public void shouldGetCredentials(String url, String credentials) { | ||
// given | ||
DefaultFactoryUrl factoryUrl = | ||
new DefaultFactoryUrl().withUrl("https://username:password@hostname/path"); | ||
DefaultFactoryUrl factoryUrl = new DefaultFactoryUrl().withUrl(url); | ||
// when | ||
Optional<String> credentialsOptional = factoryUrl.getCredentials(); | ||
// then | ||
assertTrue(credentialsOptional.isPresent()); | ||
assertEquals(credentialsOptional.get(), "username:password"); | ||
assertEquals(credentialsOptional.get(), credentials); | ||
} | ||
|
||
@Test | ||
public void shouldCredentialsWithoutPassword() { | ||
// given | ||
DefaultFactoryUrl factoryUrl = | ||
new DefaultFactoryUrl().withUrl("https://username@hostname/path"); | ||
// when | ||
Optional<String> credentialsOptional = factoryUrl.getCredentials(); | ||
// then | ||
assertTrue(credentialsOptional.isPresent()); | ||
assertEquals(credentialsOptional.get(), "username:"); | ||
@DataProvider(name = "urlsProvider") | ||
private Object[][] urlsProvider() { | ||
return new Object[][] { | ||
{"https://username:password@hostname/path", "username:password"}, | ||
{"https://token@hostname/path/user/repo/", "token:"}, | ||
{"http://token@hostname/path/user/repo/", "token:"}, | ||
{"https://[email protected]/user/repo/", "token:"}, | ||
{ | ||
"https://[email protected]/user/repo/branch/.devfile.yaml", | ||
"personal-access-token:" | ||
}, | ||
{"https://[email protected]/user/repo/", "token:"}, | ||
{"https://[email protected]/user/repo/", "token:"}, | ||
}; | ||
} | ||
|
||
@Test | ||
|