use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project devspaces-images by redhat-developer.
the class BitbucketServerScmFileResolverTest 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 = serverScmFileResolver.fileContent("https://foo.bar/scm/test/repo.git", filename);
assertEquals(content, rawContent);
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project devspaces-images by redhat-developer.
the class GitlabOAuthTokenFetcherTest method shouldReturnToken.
@Test
public void shouldReturnToken() throws Exception {
Subject subject = new SubjectImpl("Username", "id1", "token", false);
OAuthToken oAuthToken = newDto(OAuthToken.class).withToken("oauthtoken").withScope("api write_repository openid");
when(oAuthAPI.getToken(anyString())).thenReturn(oAuthToken);
stubFor(get(urlEqualTo("/oauth/token/info")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer oauthtoken")).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withBodyFile("gitlab/rest/api/v4/user/token_info.json")));
stubFor(get(urlEqualTo("/api/v4/user")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer oauthtoken")).willReturn(aResponse().withHeader("Content-Type", "application/json; charset=utf-8").withBodyFile("gitlab/rest/api/v4/user/response.json")));
PersonalAccessToken token = oAuthTokenFetcher.fetchPersonalAccessToken(subject, wireMockServer.url("/"));
assertNotNull(token);
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project devspaces-images by redhat-developer.
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);
}
use of org.eclipse.che.api.factory.server.scm.PersonalAccessToken in project devspaces-images by redhat-developer.
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);
}
Aggregations