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