Search in sources :

Example 1 with Document

use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.

the class TestDownloads method setupTest.

@Before
public void setupTest() throws IOException, Exception {
    nodesApi = applicationContext.getBean("Nodes", org.alfresco.rest.api.Nodes.class);
    setRequestContext(user1);
    Document zippableDoc1 = createTextFile(tDocLibNodeId, ZIPPABLE_DOC1_NAME, DUMMY_CONTENT);
    zippableDocId1 = zippableDoc1.getId();
    zippableDocId2 = createTextFile(tDocLibNodeId, "docTest2", DUMMY_CONTENT).getId();
    Folder zippableFolder1 = createFolder(tDocLibNodeId, FOLDER1_NAME);
    zippableFolderId1 = zippableFolder1.getId();
    zippableDocId3_InFolder1 = createTextFile(zippableFolderId1, DOC3_NAME, DUMMY_CONTENT).getId();
    Folder zippableFolder2_InFolder1 = createFolder(zippableFolderId1, SUB_FOLDER1_NAME);
    zippableFolderId2_InFolder1 = zippableFolder2_InFolder1.getId();
    zippableDocId4_InFolder2 = createTextFile(zippableFolderId2_InFolder1, DOC4_NAME, DUMMY_CONTENT).getId();
    Folder zippableFolder3 = createFolder(tDocLibNodeId, FOLDER3_NAME);
    zippableFolderId3 = zippableFolder3.getId();
    setRequestContext(user2);
    String user2Site = createSite("TestSite B - " + RUNID, SiteVisibility.PRIVATE).getId();
    String user2DocLib = getSiteContainerNodeId(user2Site, "documentLibrary");
    zippableDoc_user2 = createTextFile(user2DocLib, "user2doc", DUMMY_CONTENT).getId();
    setRequestContext(user1);
    AssocChild secChild = new AssocChild(zippableDoc1.getId(), ASSOC_TYPE_CM_CONTAINS);
    post(format(NODES_SECONDARY_CHILDREN, zippableFolder3.getId()), toJsonAsStringNonNull(secChild), HttpServletResponse.SC_CREATED);
}
Also used : AssocChild(org.alfresco.rest.api.model.AssocChild) Document(org.alfresco.rest.api.tests.client.data.Document) Folder(org.alfresco.rest.api.tests.client.data.Folder) Before(org.junit.Before)

Example 2 with Document

use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.

the class ActivitiesPostingTest method testNonSite.

/**
 * Tests non-site file activites. So no events.
 */
@Test
public void testNonSite() throws Exception {
    setRequestContext(user1);
    List<Activity> activities = getMyActivities();
    String folder1 = "nonSitefolder" + System.currentTimeMillis() + "_1";
    // Create a folder outside a site
    Folder createdFolder = createFolder(Nodes.PATH_MY, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    String docName = "nonsite_d1.txt";
    Document documentResp = createEmptyTextFile(f1Id, docName);
    assertNotNull(documentResp);
    // Update the file
    Document dUpdate = new Document();
    dUpdate.setName("nonsite_d2.txt");
    put(URL_NODES, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
    List<Activity> activitiesAgain = getMyActivities();
    assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain);
}
Also used : Activity(org.alfresco.rest.api.tests.client.data.Activity) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 3 with Document

use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.

the class AuthenticationsTest method testCreateValidateDeleteTicket.

/**
 * Tests login (create ticket), logout (delete ticket), and validate (get ticket).
 *
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets}
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets/-me-}
 *
 * <p>DELETE:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets/-me-}
 */
@Test
public void testCreateValidateDeleteTicket() throws Exception {
    Paging paging = getPaging(0, 100);
    setRequestContext(null);
    // Unauthorized call
    getAll(SiteEntityResource.class, paging, null, 401);
    /*
         *  user1 login - via alf_ticket parameter
         */
    // User1 login request
    LoginTicket loginRequest = new LoginTicket();
    // Invalid login details
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400);
    loginRequest.setUserId(null);
    loginRequest.setPassword("user1Password");
    // Invalid login details
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400);
    loginRequest.setUserId(user1);
    loginRequest.setPassword(null);
    // Invalid login details
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400);
    loginRequest.setUserId(user1);
    loginRequest.setPassword("user1Password");
    // Authenticate and create a ticket
    HttpResponse response = post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201);
    LoginTicketResponse loginResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertNotNull(loginResponse.getId());
    assertNotNull(loginResponse.getUserId());
    // Get list of sites by appending the alf_ticket to the URL
    // e.g. .../alfresco/versions/1/sites/?alf_ticket=TICKET_57866258ea56c28491bb3e75d8355ebf6fbaaa23
    Map<String, String> ticket = Collections.singletonMap("alf_ticket", loginResponse.getId());
    getAll(SiteEntityResource.class, paging, ticket, 200);
    // Unauthorized - Invalid ticket
    getAll(SiteEntityResource.class, paging, Collections.singletonMap("alf_ticket", "TICKET_" + System.currentTimeMillis()), 401);
    // Validate ticket - Invalid parameter. Only '-me-' is supported
    getSingle(TICKETS_URL, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400);
    // Validate ticket
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 200);
    LoginTicketResponse validatedTicket = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertEquals(loginResponse.getId(), validatedTicket.getId());
    // Validate ticket - Invalid parameter. Only '-me-' is supported
    getSingle(TICKETS_URL, loginResponse.getId(), ticket, null, TICKETS_API_NAME, 400);
    // Delete the ticket  - Logout
    delete(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 204);
    // Validate ticket - 401 as ticket has been invalidated so the API call is unauthorized
    getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 401);
    setRequestContext(user1);
    // Check the ticket has been invalidated - the difference with the above is that the API call is authorized
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404);
    PublicApiClient.ExpectedErrorResponse error = RestApiUtil.parseErrorResponse(response.getJsonResponse());
    // Double check that we've retrieved a standard error response (REPO-1773)
    assertEquals(404, error.getStatusCode());
    // Ticket has already been invalidated
    delete(TICKETS_URL, People.DEFAULT_USER, ticket, null, TICKETS_API_NAME, 404);
    setRequestContext(null);
    // Get list of site by appending the invalidated ticket
    getAll(SiteEntityResource.class, paging, ticket, 401);
    /*
         *  user2 login - Via Authorization header
         */
    setRequestContext(user2);
    // User2 create a folder within his home folder (-my-)
    Folder folderResp = createFolder(Nodes.PATH_MY, "F2", null);
    assertNotNull(folderResp.getId());
    setRequestContext(null);
    getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 401);
    // User2 login request
    loginRequest = new LoginTicket();
    loginRequest.setUserId(user2);
    loginRequest.setPassword("wrongPassword");
    // Authentication failed - wrong password
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403);
    loginRequest.setUserId(user1);
    loginRequest.setPassword("user2Password");
    // Authentication failed - userId/password mismatch
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403);
    // Set the correct details
    loginRequest.setUserId(user2);
    loginRequest.setPassword("user2Password");
    // Authenticate and create a ticket
    response = post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201);
    loginResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertNotNull(loginResponse.getId());
    assertNotNull(loginResponse.getUserId());
    String encodedTicket = encodeB64(loginResponse.getId());
    // Set the authorization (encoded ticket only) header rather than appending the ticket to the URL
    Map<String, String> header = Collections.singletonMap("Authorization", "Basic " + encodedTicket);
    // Get children of user2 home folder
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200);
    List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    // Validate ticket - Invalid parameter. Only '-me-' is supported
    getSingle(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400);
    // Validate ticket - user2
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 200);
    validatedTicket = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertEquals(loginResponse.getId(), validatedTicket.getId());
    // Try list children for user2 again.
    // Encode Alfresco predefined userId for ticket authentication, ROLE_TICKET, and the ticket
    String encodedUserIdAndTicket = encodeB64("ROLE_TICKET:" + loginResponse.getId());
    // Set the authorization (encoded userId:ticket) header rather than appending the ticket to the URL
    header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket);
    // Get children of user2 home folder
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    // Try list children for user2 again - appending ticket
    ticket = Collections.singletonMap("alf_ticket", loginResponse.getId());
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, ticket, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    setRequestContext(user2);
    // Try to validate the ticket without supplying the Authorization header or the alf_ticket param
    getSingle(TICKETS_URL, People.DEFAULT_USER, null, null, TICKETS_API_NAME, 400);
    setRequestContext(null);
    // Delete the ticket  - Invalid parameter. Only '-me-' is supported
    header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket);
    delete(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400);
    // Delete the ticket  - Logout
    delete(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 204);
    // Get children of user2 home folder - invalidated ticket
    getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 401);
}
Also used : LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) LoginTicket(org.alfresco.rest.api.model.LoginTicket) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 4 with Document

use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.

the class NodeApiTest method createDocument.

/**
 * Created an empty document in the given url path
 *
 * @param url
 * @return
 * @throws Exception
 */
private String createDocument(String url) throws Exception {
    Document d1 = new Document();
    d1.setName("testDoc" + GUID.generate());
    d1.setNodeType(TYPE_CM_CONTENT);
    HttpResponse response = post(url, toJsonAsStringNonNull(d1), 201);
    Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    return documentResp.getId();
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document)

Example 5 with Document

use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testUpdatePermissionsDefaultInheritFromParent.

/**
 * Test default inherit from parent
 *
 * @throws Exception
 */
private void testUpdatePermissionsDefaultInheritFromParent() throws Exception {
    // create folder
    Folder folder = new Folder();
    folder.setName("testFolder" + GUID.generate());
    folder.setNodeType(TYPE_CM_FOLDER);
    // set permissions on previously created folder
    NodePermissions nodePermissions = new NodePermissions();
    List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
    locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.EDITOR, AccessStatus.DENIED.toString()));
    nodePermissions.setLocallySet(locallySetPermissions);
    folder.setPermissions(nodePermissions);
    HttpResponse response = post(getNodeChildrenUrl(Nodes.PATH_MY), RestApiUtil.toJsonAsStringNonNull(folder), 201);
    Folder f = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
    // create a new document in testFolder
    String docId = createDocument(getNodeChildrenUrl(f.getId()));
    Map params = new HashMap<>();
    params.put("include", "permissions");
    response = getSingle(NodesEntityResource.class, docId, params, 200);
    Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertTrue("Inheritance hasn't been enabled!", docResp.getPermissions().getIsInheritanceEnabled());
    assertTrue("Permissions were not inherited from parent!", docResp.getPermissions().getInherited().size() > 0);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Document (org.alfresco.rest.api.tests.client.data.Document)60 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)49 Test (org.junit.Test)46 HashMap (java.util.HashMap)34 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)30 Folder (org.alfresco.rest.api.tests.client.data.Folder)25 LinkedHashMap (java.util.LinkedHashMap)22 File (java.io.File)20 ArrayList (java.util.ArrayList)20 Node (org.alfresco.rest.api.tests.client.data.Node)19 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)18 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)15 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)14 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)13 NodePermissions (org.alfresco.rest.api.model.NodePermissions)12 FileData (org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData)11 MultiPartRequest (org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest)11 Rendition (org.alfresco.rest.api.tests.client.data.Rendition)10 JSONObject (org.json.simple.JSONObject)9 ByteArrayInputStream (java.io.ByteArrayInputStream)6