Use `login` instead of `name` in the GitHub scopes/username request (#537)
Change user.getName() to user.getLogin() in the GitHub getTokenScopes() API request, in order to fix a bug where NullPointer exception is appeared when a GitHub user request returns a user with null in the name field.7.72.x
parent
03cfb8e50e
commit
63d8a343e4
|
|
@ -228,7 +228,7 @@ public class GithubApiClient {
|
|||
String result =
|
||||
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
|
||||
GithubUser user = OBJECT_MAPPER.readValue(result, GithubUser.class);
|
||||
return Pair.of(user.getName(), scopes);
|
||||
return Pair.of(user.getLogin(), scopes);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.lang.reflect.Field;
|
|||
import org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException;
|
||||
import org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException;
|
||||
import org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException;
|
||||
import org.eclipse.che.commons.lang.Pair;
|
||||
import org.mockito.testng.MockitoTestNGListener;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
|
@ -165,11 +166,13 @@ public class GithubApiClientTest {
|
|||
.withHeader(GithubApiClient.GITHUB_OAUTH_SCOPES_HEADER, "repo, user:email")
|
||||
.withBodyFile("github/rest/user/response.json")));
|
||||
|
||||
String[] scopes = client.getTokenScopes("token1").second;
|
||||
Pair<String, String[]> pair = client.getTokenScopes("token1");
|
||||
String[] scopes = pair.second;
|
||||
String[] expectedScopes = {"repo", "user:email"};
|
||||
assertNotNull(scopes, "GitHub API should have returned a non-null scope array");
|
||||
assertEqualsNoOrder(
|
||||
scopes, expectedScopes, "Returned scope array does not match expected values");
|
||||
assertEquals(pair.first, "github-user");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue