use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project che-server by eclipse-che.
the class GithubPersonalAccessTokenFetcherTest method shouldNotValidateSCMServerWithTrailingSlash.
@Test
public void shouldNotValidateSCMServerWithTrailingSlash() throws Exception {
stubFor(get(urlEqualTo("/user")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("token " + githubOauthToken)).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withHeader(GithubApiClient.GITHUB_OAUTH_SCOPES_HEADER, "repo").withBodyFile("github/rest/user/response.json")));
PersonalAccessToken personalAccessToken = new PersonalAccessToken("https://github.com/", "cheUserId", "scmUserName", "scmUserId", "scmTokenName", "scmTokenId", githubOauthToken);
assertTrue(githubPATFetcher.isValid(personalAccessToken).isEmpty(), "Should not validate SCM server with trailing /");
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project che-server by eclipse-che.
the class GithubPersonalAccessTokenFetcherTest method shouldValidatePersonalToken.
@Test
public void shouldValidatePersonalToken() throws Exception {
stubFor(get(urlEqualTo("/user")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("token " + githubOauthToken)).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withHeader(GithubApiClient.GITHUB_OAUTH_SCOPES_HEADER, "repo").withBodyFile("github/rest/user/response.json")));
PersonalAccessToken token = new PersonalAccessToken("https://github.com", "cheUser", "username", "123456789", "token-name", "tid-23434", githubOauthToken);
assertTrue(githubPATFetcher.isValid(token).get());
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project che-server by eclipse-che.
the class GithubPersonalAccessTokenFetcherTest method shouldReturnToken.
@Test
public void shouldReturnToken() throws Exception {
Subject subject = new SubjectImpl("Username", "id1", "token", false);
OAuthToken oAuthToken = newDto(OAuthToken.class).withToken(githubOauthToken).withScope("repo");
when(oAuthAPI.getToken(anyString())).thenReturn(oAuthToken);
stubFor(get(urlEqualTo("/user")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("token " + githubOauthToken)).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withHeader(GithubApiClient.GITHUB_OAUTH_SCOPES_HEADER, "repo").withBodyFile("github/rest/user/response.json")));
PersonalAccessToken token = githubPATFetcher.fetchPersonalAccessToken(subject, GithubApiClient.GITHUB_SERVER);
assertNotNull(token);
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project che-server by eclipse-che.
the class GitlabOAuthTokenFetcherTest method shouldValidatePersonalToken.
@Test
public void shouldValidatePersonalToken() throws Exception {
stubFor(get(urlEqualTo("/api/v4/user")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer token123")).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withBodyFile("gitlab/rest/api/v4/user/response.json")));
PersonalAccessToken token = new PersonalAccessToken(wireMockServer.baseUrl(), "cheUser", "username", "1", "token-name", "tid-23434", "token123");
assertTrue(oAuthTokenFetcher.isValid(token).get());
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project che-server by eclipse-che.
the class GitlabScmFileResolverTest method shouldReturnContentFromUrlFetcher.
@Test
public void shouldReturnContentFromUrlFetcher() throws Exception {
final String rawContent = "raw_content";
final String filename = "devfile.yaml";
when(personalAccessTokenManager.get(any(Subject.class), anyString())).thenReturn(Optional.of(new PersonalAccessToken(SCM_URL, "root", "token123")));
when(urlFetcher.fetch(anyString(), eq("Bearer token123"))).thenReturn(rawContent);
String content = gitlabScmFileResolver.fileContent("http://gitlab.2mcl.com/test/proj/repo.git", filename);
assertEquals(content, rawContent);
}
Aggregations