Skip to content

Commit

Permalink
fixup! Support Basic authentication for devfile factory URL
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Feb 22, 2023
1 parent 419ec92 commit 4ec09ca
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,35 @@

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://token@dev.azure.com/user/repo/", "token:"},
{"https://token@github.com/user/repo/", "token:"},
{"https://token@gitlub.com/user/repo/", "token:"},
{"https://token@bitbucket.org/user/repo/", "token:"},
};
}

@Test
Expand Down

0 comments on commit 4ec09ca

Please sign in to comment.