use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequestTest method createPipeline.
@Test
public void createPipeline() throws UnirestException, IOException {
User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/jenkins/pipelines/").data(ImmutableMap.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("id", GitScm.ID, "uri", sampleRepo.toString()))).build(Map.class);
assertNotNull(r);
assertEquals("pipeline1", r.get("name"));
MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
GitSCMSource source = (GitSCMSource) mbp.getSCMSources().get(0);
List<SCMSourceTrait> traits = source.getTraits();
Assert.assertNotNull(SCMTrait.find(traits, BranchDiscoveryTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate2.
@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate2() throws IOException, UnirestException {
User user = login();
this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", "abcd").put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
String credentialId = (String) resp.get("id");
Assert.assertNotNull(credentialId);
post("/organizations/" + getOrgName() + "/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate1.
@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate1() throws IOException, UnirestException {
User user = login();
this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
String credentialId = (String) resp.get("id");
Assert.assertNotNull(credentialId);
post("/organizations/" + getOrgName() + "/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class GitScmTest method shouldFailForBadCredentialIdOnCreate.
@Test
public void shouldFailForBadCredentialIdOnCreate() throws IOException, UnirestException {
User user = login();
Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
String credentialId = (String) resp.get("id");
Assert.assertNotNull(credentialId);
resp = new RequestBuilder(baseUrl).status(400).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/" + getOrgName() + "/pipelines/").data(ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId))).build(Map.class);
assertEquals(resp.get("code"), 400);
List<Map> errors = (List<Map>) resp.get("errors");
assertEquals(1, errors.size());
assertEquals("scmConfig.credentialId", errors.get(0).get("field"));
assertEquals("INVALID", errors.get(0).get("code"));
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class GitScmTest method shouldCreateWithRemoteGitRepo.
@Test
public void shouldCreateWithRemoteGitRepo() throws IOException, UnirestException {
String accessToken = needsGithubAccessToken();
User user = login();
this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", accessToken).put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
String credentialId = (String) resp.get("id");
Assert.assertNotNull(credentialId);
Map r = new RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/" + getOrgName() + "/pipelines/").data(ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "https://github.com/vivek/test-no-jenkins-file.git", "credentialId", credentialId))).build(Map.class);
assertEquals("demo", r.get("name"));
}
Aggregations