Skip to content

Commit

Permalink
Fix parameter mismatch mistake in the AbstractGitUserDataFetcher class
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Mar 7, 2025
1 parent eae5ba1 commit e9495a4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@ public void shouldFetchGitUserData() throws Exception {
assertEquals(gitUserData.getScmUsername(), "Github User");
assertEquals(gitUserData.getScmUserEmail(), "[email protected]");
}

@Test
public void shouldFetchGitUserDataByUrl() throws Exception {
// given
PersonalAccessToken token = mock(PersonalAccessToken.class);
when(token.getToken()).thenReturn(githubOauthToken);
when(personalAccessTokenManager.get(any(Subject.class), eq("github"), eq(null), eq(null)))
.thenReturn(Optional.empty());
when(personalAccessTokenManager.get(
any(Subject.class), eq(null), eq(wireMockServer.baseUrl()), eq(null)))
.thenReturn(Optional.of(token));
// when
GitUserData gitUserData = githubGUDFetcher.fetchGitUserData(null);
// then
assertEquals(gitUserData.getScmUsername(), "Github User");
assertEquals(gitUserData.getScmUserEmail(), "[email protected]");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2024 Red Hat, Inc.
* Copyright (c) 2012-2025 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/
Expand Down Expand Up @@ -39,8 +39,11 @@ public AbstractGitlabUserDataFetcher(
String apiEndpoint,
PersonalAccessTokenManager personalAccessTokenManager,
String providerName) {
super(providerName, serverUrl, personalAccessTokenManager);
this.serverUrl = isNullOrEmpty(serverUrl) ? GITLAB_SAAS_ENDPOINT : serverUrl;
super(
providerName,
isNullOrEmpty(serverUrl) ? GITLAB_SAAS_ENDPOINT : serverUrl,
personalAccessTokenManager);
this.serverUrl = super.oAuthProviderUrl;
this.apiEndpoint = apiEndpoint;
this.providerName = providerName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.che.api.factory.server.scm.PersonalAccessToken;
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
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.AfterMethod;
Expand All @@ -44,7 +43,6 @@
@Listeners(MockitoTestNGListener.class)
public class GitlabUserDataFetcherTest {

@Mock OAuthAPI oAuthTokenFetcher;
@Mock PersonalAccessTokenManager personalAccessTokenManager;

GitlabUserDataFetcher gitlabUserDataFetcher;
Expand Down Expand Up @@ -90,6 +88,23 @@ public void shouldFetchGitUserData() throws Exception {
assertEquals(gitUserData.getScmUserEmail(), "[email protected]");
}

@Test
public void shouldFetchGitUserDataByUrl() throws Exception {
// given
PersonalAccessToken token = mock(PersonalAccessToken.class);
when(token.getToken()).thenReturn("oauthtoken");
when(personalAccessTokenManager.get(any(Subject.class), eq("gitlab"), eq(null), eq(null)))
.thenReturn(Optional.empty());
when(personalAccessTokenManager.get(
any(Subject.class), eq(null), eq(wireMockServer.url("/")), eq(null)))
.thenReturn(Optional.of(token));
// when
GitUserData gitUserData = gitlabUserDataFetcher.fetchGitUserData(null);
// then
assertEquals(gitUserData.getScmUsername(), "John Smith");
assertEquals(gitUserData.getScmUserEmail(), "[email protected]");
}

@Test
public void shouldSetSAASUrlAsDefault() throws Exception {
gitlabUserDataFetcher =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public abstract class AbstractGitUserDataFetcher implements GitUserDataFetcher {
protected final String oAuthProviderName;
private final String oAuthProviderUrl;
protected final String oAuthProviderUrl;
protected final PersonalAccessTokenManager personalAccessTokenManager;

public AbstractGitUserDataFetcher(
Expand All @@ -46,7 +46,7 @@ public GitUserData fetchGitUserData(String namespaceName)
return fetchGitUserDataWithPersonalAccessToken(tokenOptional.get());
} else {
Optional<PersonalAccessToken> oAuthTokenOptional =
personalAccessTokenManager.get(cheSubject, oAuthProviderUrl, null, namespaceName);
personalAccessTokenManager.get(cheSubject, null, oAuthProviderUrl, namespaceName);
if (oAuthTokenOptional.isPresent()) {
return fetchGitUserDataWithOAuthToken(oAuthTokenOptional.get().getToken());
}
Expand Down

0 comments on commit e9495a4

Please sign in to comment.