Search in sources :

Example 51 with PersonalAccessToken

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);
}
Also used : PersonalAccessToken(org.eclipse.che.api.factory.server.scm.PersonalAccessToken) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Subject(org.eclipse.che.commons.subject.Subject) Test(org.testng.annotations.Test)

Example 52 with PersonalAccessToken

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);
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) PersonalAccessToken(org.eclipse.che.api.factory.server.scm.PersonalAccessToken) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject) Test(org.testng.annotations.Test)

Example 53 with PersonalAccessToken

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);
}
Also used : PersonalAccessToken(org.eclipse.che.api.factory.server.scm.PersonalAccessToken) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Subject(org.eclipse.che.commons.subject.Subject) Test(org.testng.annotations.Test)

Example 54 with PersonalAccessToken

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);
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) PersonalAccessToken(org.eclipse.che.api.factory.server.scm.PersonalAccessToken) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject) Test(org.testng.annotations.Test)

Aggregations

PersonalAccessToken (org.eclipse.che.api.factory.server.scm.PersonalAccessToken)54 Test (org.testng.annotations.Test)42 Secret (io.fabric8.kubernetes.api.model.Secret)20 KubernetesNamespaceMeta (org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta)20 Subject (org.eclipse.che.commons.subject.Subject)16 KubernetesNamespaceMetaImpl (org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)12 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)12 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)12 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)12 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 OAuthToken (org.eclipse.che.api.auth.shared.dto.OAuthToken)8 BitbucketPersonalAccessToken (org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken)8 KubernetesNamespace (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace)8 KubernetesSecrets (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesSecrets)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Optional (java.util.Optional)6 ScmBadRequestException (org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)6 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)6 ScmItemNotFoundException (org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException)6