Search in sources :

Example 6 with PersonalAccessToken

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 /");
}
Also used : PersonalAccessToken(org.eclipse.che.api.factory.server.scm.PersonalAccessToken) Test(org.testng.annotations.Test)

Example 7 with PersonalAccessToken

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

Example 8 with PersonalAccessToken

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);
}
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 9 with PersonalAccessToken

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

Example 10 with PersonalAccessToken

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);
}
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)

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