Search in sources :

Example 56 with User

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"));
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with User

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"));
}
Also used : Mailer(hudson.tasks.Mailer) User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 58 with User

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);
}
Also used : User(hudson.model.User) Test(org.junit.Test)

Example 59 with User

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);
}
Also used : BlueUser(io.jenkins.blueocean.rest.model.BlueUser) User(hudson.model.User) ACL(hudson.security.ACL) Jenkins(jenkins.model.Jenkins) Answer(org.mockito.stubbing.Answer) Authentication(org.acegisecurity.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Permission(hudson.security.Permission) BlueUserPermission(io.jenkins.blueocean.rest.model.BlueUserPermission) Before(org.junit.Before)

Example 60 with 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"));
}
Also used : User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

User (hudson.model.User)105 Test (org.junit.Test)71 Map (java.util.Map)42 ImmutableMap (com.google.common.collect.ImmutableMap)38 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)26 Mailer (hudson.tasks.Mailer)24 ServiceException (io.jenkins.blueocean.commons.ServiceException)21 StaplerRequest (org.kohsuke.stapler.StaplerRequest)14 MultiBranchProject (jenkins.branch.MultiBranchProject)13 List (java.util.List)12 JSONObject (net.sf.json.JSONObject)12 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)8 IOException (java.io.IOException)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)7 Authentication (org.acegisecurity.Authentication)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)6 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)6 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6