-
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.
Support Basic authentication for devfile factory URL (#451)
Add a parsing rule to detect credentials in factory URLs if it is in a format https://<username>:<pasword>@hostname. Extract the credentials from factory URLs and pass them to the devfile content request.
- Loading branch information
Showing
20 changed files
with
226 additions
and
49 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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
...ry/src/test/java/org/eclipse/che/api/factory/server/urlfactory/DefaultFactoryUrlTest.java
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2012-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.api.factory.server.urlfactory; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
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(dataProvider = "urlsProvider") | ||
public void shouldGetCredentials(String url, String credentials) { | ||
// given | ||
DefaultFactoryUrl factoryUrl = new DefaultFactoryUrl().withUrl(url); | ||
// when | ||
Optional<String> credentialsOptional = factoryUrl.getCredentials(); | ||
// then | ||
assertTrue(credentialsOptional.isPresent()); | ||
assertEquals(credentialsOptional.get(), credentials); | ||
} | ||
|
||
@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?a=&b=b&c=/.devfile.yaml&api-version=7.0", "token:"}, | ||
{"https://[email protected]/user/repo/", "token:"}, | ||
{"https://[email protected]/user/repo/", "token:"}, | ||
{ | ||
"https://[email protected]/user/repo/branch/.devfile.yaml", | ||
"personal-access-token:" | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void shouldGetEmptyCredentials() { | ||
// given | ||
DefaultFactoryUrl factoryUrl = new DefaultFactoryUrl().withUrl("https://hostname/path"); | ||
// when | ||
Optional<String> credentialsOptional = factoryUrl.getCredentials(); | ||
// then | ||
assertFalse(credentialsOptional.isPresent()); | ||
} | ||
} |
Oops, something went wrong.