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 2745230
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2745230

Please sign in to comment.