use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class ProfileApiTest method postCrumbTest.
// XXX: There is no method on User API to respond to POST or PUT or PATH. Since there are other tests that
// does POST, PUT for successful case, its ok to disable them.
// UX-159
@Test
@Ignore
public void postCrumbTest() throws Exception {
User system = User.get("SYSTEM");
Map response = post("/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 getAuthenticatedUser.
@Test
public void getAuthenticatedUser() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
hudson.model.User user = User.get("alice");
user.setFullName("Alice Cooper");
user.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
// String token = getJwtToken(j.jenkins,"alice", "alice");
Map u = new RequestBuilder(baseUrl).get("/organizations/jenkins/user/").authAlice().status(200).build(Map.class);
assertEquals(user.getFullName(), u.get("fullName"));
assertEquals("alice@jenkins-ci.org", u.get("email"));
assertEquals(user.getId(), u.get("id"));
Map permission = (Map) u.get("permission");
assertNotNull(permission);
assertTrue((Boolean) permission.get("administrator"));
Map pipelinePerm = (Map) permission.get("pipeline");
assertEquals(true, pipelinePerm.get("start"));
assertEquals(true, pipelinePerm.get("create"));
assertEquals(true, pipelinePerm.get("read"));
assertEquals(true, pipelinePerm.get("stop"));
assertEquals(true, pipelinePerm.get("configure"));
Map credentialPerm = (Map) permission.get("credential");
assertEquals(true, credentialPerm.get("create"));
assertEquals(true, credentialPerm.get("view"));
assertEquals(true, credentialPerm.get("update"));
assertEquals(true, credentialPerm.get("manageDomains"));
assertEquals(true, credentialPerm.get("delete"));
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class ProfileApiTest method patchMimeFailTest.
@Test
public void patchMimeFailTest() throws Exception {
User system = User.get("SYSTEM");
new RequestBuilder(baseUrl).contentType("text/plain").status(415).patch("/users/" + system.getId()).build(Map.class);
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class UserImplPermissionTest method setup.
@Before
public void setup() throws IOException {
testOrganization = new TestOrganization("org", "orgDisplayName");
user = mock(User.class);
when(user.getId()).thenReturn("some_user");
authentication = new Authentication() {
public String getName() {
return "some_user";
}
public GrantedAuthority[] getAuthorities() {
return null;
}
public Object getCredentials() {
return null;
}
public Object getDetails() {
return null;
}
public Object getPrincipal() {
return null;
}
public boolean isAuthenticated() {
return false;
}
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
}
};
jenkins = mock(Jenkins.class);
when(jenkins.getACL()).thenReturn(new ACL() {
public boolean hasPermission(Authentication a, Permission permission) {
return false;
}
});
mockStatic(Jenkins.class);
when(Jenkins.getAuthentication()).thenReturn(authentication);
when(Jenkins.getInstance()).thenReturn(jenkins);
try {
// After Jenkins 2.77 hasPermission is no longer in Node.class and is not final so we need to mock it
// prior to it is called as being final and mocking it will fail for the same reason.
// TODO remove after core base line is >= 2.77
Node.class.getDeclaredMethod("hasPermission", Permission.class);
} catch (NoSuchMethodException e) {
when(jenkins.hasPermission(Mockito.any())).thenAnswer(new Answer<Boolean>() {
public Boolean answer(InvocationOnMock invocation) {
Permission permission = invocation.getArgumentAt(0, Permission.class);
Jenkins j = (Jenkins) invocation.getMock();
return j.getACL().hasPermission(permission);
}
});
}
mockStatic(User.class);
when(User.get("some_user", false, Collections.EMPTY_MAP)).thenReturn(user);
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class CredentialApiTest method createSshCredentialUsingDefaultSshOnMasterInUserStore.
@Test
public void createSshCredentialUsingDefaultSshOnMasterInUserStore() throws IOException, UnirestException {
User user = login();
Map resp = new RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/jenkins/credentials/user/").data(ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$UsersPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build())).build(Map.class);
Assert.assertEquals("SSH Username with private key", resp.get("typeName"));
Assert.assertEquals("blueocean-domain", resp.get("domain"));
}
Aggregations