Search in sources :

Example 46 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class ProfileApiTest method patchMimeTest.

//UX-159
//    @Test
public void patchMimeTest() throws Exception {
    User system = j.jenkins.getUser("SYSTEM");
    Map response = patch("/users/" + system.getId() + "/", Collections.emptyMap());
    assertEquals(system.getId(), response.get("id"));
    assertEquals(system.getFullName(), response.get("fullName"));
}
Also used : User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 47 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class ProfileApiTest method createUserFavouriteTest.

@Test
public void createUserFavouriteTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("alice");
    user.setFullName("Alice Cooper");
    Project p = j.createFreeStyleProject("pipeline1");
    String token = getJwtToken(j.jenkins, "alice", "alice");
    Map map = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/pipeline1/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    assertEquals(1, l.size());
    Map pipeline = (Map) ((Map) l.get(0)).get("item");
    validatePipeline(p, pipeline);
    String href = getHrefFromLinks((Map) l.get(0), "self");
    assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/favorite/", href);
    map = new RequestBuilder(baseUrl).put(href.substring("/blue/rest".length())).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    assertEquals(0, l.size());
    new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(getJwtToken(j.jenkins, "bob", "bob")).status(403).build(String.class);
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 48 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class ProfileApiTest method getUserDetailsTest.

@Test
public void getUserDetailsTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User alice = j.jenkins.getUser("alice");
    alice.setFullName("Alice Cooper");
    alice.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
    hudson.model.User bob = j.jenkins.getUser("bob");
    bob.setFullName("Bob Smith");
    bob.addProperty(new Mailer.UserProperty("bob@jenkins-ci.org"));
    //Call is made as anonymous user, email should be null
    Map response = get("/users/" + alice.getId());
    assertEquals(alice.getId(), response.get("id"));
    assertEquals(alice.getFullName(), response.get("fullName"));
    Assert.assertNull(response.get("email"));
    //make a request on bob's behalf to get alice's user details, should get null email
    Map r = new RequestBuilder(baseUrl).status(200).jwtToken(getJwtToken(j.jenkins, "bob", "bob")).get("/users/" + alice.getId()).build(Map.class);
    assertEquals(alice.getId(), r.get("id"));
    assertEquals(alice.getFullName(), r.get("fullName"));
    Assert.assertTrue(bob.hasPermission(Jenkins.ADMINISTER));
    //bob is admin so can see alice email
    assertEquals("alice@jenkins-ci.org", r.get("email"));
    r = new RequestBuilder(baseUrl).status(200).jwtToken(getJwtToken(j.jenkins, "alice", "alice")).get("/users/" + alice.getId()).build(Map.class);
    assertEquals(alice.getId(), r.get("id"));
    assertEquals(alice.getFullName(), r.get("fullName"));
    assertEquals("alice@jenkins-ci.org", r.get("email"));
}
Also used : Mailer(hudson.tasks.Mailer) User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

User (hudson.model.User)48 Test (org.junit.Test)30 Map (java.util.Map)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)11 Mailer (hudson.tasks.Mailer)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)5 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Job (hudson.model.Job)4 ServiceException (io.jenkins.blueocean.commons.ServiceException)4 List (java.util.List)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 Cause (hudson.model.Cause)3 IOException (java.io.IOException)3 OrganizationFolder (jenkins.branch.OrganizationFolder)3 Authentication (org.acegisecurity.Authentication)3 MockFolder (org.jvnet.hudson.test.MockFolder)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3