-
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.
fix: typo in AzureDevOpsPersonalAccessTokenFetcher (#457)
* fix: typo in AzureDevOpsPersonalAccessTokenFetcher Signed-off-by: Anatolii Bazko <abazko@redhat.com> * fixup Signed-off-by: Anatolii Bazko <abazko@redhat.com> * fixup Signed-off-by: Anatolii Bazko <abazko@redhat.com> * fixup Signed-off-by: Anatolii Bazko <abazko@redhat.com> --------- Signed-off-by: Anatolii Bazko <abazko@redhat.com>
- Loading branch information
Showing
2 changed files
with
84 additions
and
7 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
77 changes: 77 additions & 0 deletions
77
...clipse/che/api/factory/server/azure/devops/AzureDevOpsPersonalAccessTokenFetcherTest.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,77 @@ | ||
/* | ||
* 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.azure.devops; | ||
|
||
import org.eclipse.che.api.auth.shared.dto.OAuthToken; | ||
import org.eclipse.che.api.factory.server.scm.PersonalAccessToken; | ||
import org.eclipse.che.api.factory.server.urlfactory.DevfileFilenamesProvider; | ||
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder; | ||
import org.eclipse.che.commons.subject.Subject; | ||
import org.eclipse.che.security.oauth.OAuthAPI; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.*; | ||
|
||
/** | ||
* @author Anatalii Bazko | ||
*/ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class AzureDevOpsPersonalAccessTokenFetcherTest { | ||
|
||
@Mock | ||
private AzureDevOpsApiClient azureDevOpsApiClient; | ||
@Mock | ||
private OAuthAPI oAuthAPI; | ||
@Mock | ||
private OAuthToken oAuthToken; | ||
@Mock | ||
private AzureDevOpsUser azureDevOpsUser; | ||
private AzureDevOpsPersonalAccessTokenFetcher personalAccessTokenFetcher; | ||
|
||
@BeforeMethod | ||
protected void start() { | ||
personalAccessTokenFetcher = new AzureDevOpsPersonalAccessTokenFetcher( | ||
"localhost", | ||
"https://dev.azure.com", | ||
new String[]{}, | ||
azureDevOpsApiClient, | ||
oAuthAPI); | ||
} | ||
|
||
@Test | ||
public void fetchPersonalAccessTokenShouldReturnNullIfScmServerUrlIsNotAzureDevOps() throws Exception { | ||
PersonalAccessToken personalAccessToken = personalAccessTokenFetcher.fetchPersonalAccessToken(mock(Subject.class), "https://eclipse.org"); | ||
|
||
assertNull(personalAccessToken); | ||
} | ||
|
||
@Test | ||
public void fetchPersonalAccessTokenShouldReturnToken() throws Exception { | ||
when(oAuthAPI.getToken(AzureDevOps.PROVIDER_NAME)).thenReturn(oAuthToken); | ||
when(azureDevOpsApiClient.getUserWithOAuthToken(any())).thenReturn(azureDevOpsUser); | ||
when(azureDevOpsApiClient.getTokenScopes(any())).thenReturn(new String[]{"vso.code_full"}); | ||
|
||
PersonalAccessToken personalAccessToken = personalAccessTokenFetcher.fetchPersonalAccessToken(mock(Subject.class), "https://dev.azure.com/"); | ||
|
||
assertNotNull(personalAccessToken); | ||
} | ||
} |