TestsUtil.generateTestUsers(camAdminRestContext, 2, function(err, users) {
            assert.ok(!err);
            var simonCtx = _.values(users)[0].restContext;
            var brandenCtx = _.values(users)[1].restContext;

            // Simon creates a collaborative document that's private.
            var name = TestsUtil.generateTestUserId();
            RestAPI.Content.createCollabDoc(simonCtx, name, 'description', 'private', [], [], function(err, contentObj) {
                assert.ok(!err);

                RestAPI.Content.joinCollabDoc(simonCtx, contentObj.id, function(err, data) {
                    assert.ok(!err);
                    assert.ok(data);

                    // Branden has no access yet, so joining should result in a 401
                    RestAPI.Content.joinCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                        assert.equal(err.code, 401);
                        assert.ok(!data);

                        // Share it with branden, viewers still can't edit(=join) though
                        var members = {};
                        members[_.keys(users)[1]] = 'viewer';
                        RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                            assert.ok(!err);

                            // Branden can see the document, but he cannot join in and start editing it
                            RestAPI.Content.joinCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                assert.equal(err.code, 401);
                                assert.ok(!data);

                                // Now that we make Branden a manager, he should be able to join
                                members[_.keys(users)[1]] = 'manager';
                                RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                                    assert.ok(!err);

                                    // Branden should now be able to access it
                                    RestAPI.Content.joinCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                        assert.ok(!err);
                                        assert.ok(data);
                                        callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
Example #2
0
                                RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                                    assert.ok(!err);

                                    // Branden should now be able to access it.
                                    RestAPI.Content.publishCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                        assert.ok(!err);
                                        assert.ok(data);

                                        // By now we should have 3 revisions (not 4, as Branden's first publish was unauthorized)
                                        RestAPI.Content.getRevisions(simonCtx, contentObj.id, null, null, function(err, revisions) {
                                            assert.ok(!err);
                                            assert.equal(revisions.length, 3);
                                            callback();
                                        });
                                    });
                                });
Example #3
0
                                    clientB.close(function() {

                                        clientB.on('message', function() {
                                            assert.fail('The socket on client B has been closed, this socket should not receive any more messages');
                                        });

                                        // Do something that ends up in the `activity`  activitystream
                                        RestAPI.Content.createLink(mrvisser.restContext, 'Yahoo', 'Yahoo', 'public', 'http://www.yahoo.ca', [], [], [], function(err, link) {
                                            assert.ok(!err);
                                        });

                                        clientA.once('message', function(message) {
                                            assert.ok(!message.error);
                                            clientA.close(callback);
                                        });
                                    });
Example #4
0
                    RestAPI.Content.updateContent(simonCtx, contentObj.id, {'etherpadPadId': 'bleh'}, function(err) {
                        assert.equal(err.code, 400);
                        // Update a regular property
                        RestAPI.Content.updateContent(simonCtx, contentObj.id, {'displayName': 'bleh'}, function(err, updatedContentObj) {
                            assert.ok(!err);
                            assert.ok(!updatedContentObj.downloadPath);

                            // Double-check the the content item didn't change.
                            RestAPI.Content.getContent(simonCtx, contentObj.id, function(err, latestContentObj) {
                                assert.ok(!err);
                                assert.equal(contentObj.etherpadGroupId, latestContentObj.etherpadGroupId);
                                assert.equal(contentObj.etherpadPadId, latestContentObj.etherpadPadId);
                                callback();
                            });
                        });
                    });
Example #5
0
            setupFixture(function(contexts, contentObj, client) {

                // Trigger an update
                RestAPI.Content.updateContent(contexts['branden'].restContext, contentObj.id, {'displayName': 'Laaike whatevs'}, function(err) {
                    assert.ok(!err);
                });

                client.on('message', function(message) {
                    ActivityTestsUtil.assertActivity(message.activities[0], ContentConstants.activity.ACTIVITY_CONTENT_UPDATE, ActivityConstants.verbs.UPDATE, contexts['branden'].user.id, contentObj.id);

                    // Verify the updated display name is present on the activity object
                    assert.equal(message.activities[0].object.displayName, 'Laaike whatevs');

                    client.close(callback);
                });
            });
Example #6
0
                            RestAPI.Content.downloadPreviewItem(contexts['nicolaas'].restContext, contentObj.id,contentObj.latestRevisionId, previews.files[0].filename, { 'signature': 'wrong', 'expires': previews.signature.expires, 'lastModified': previews.signature.lastModified }, function(err, body, response) {
                                assert.ok(err.code, 401);
                                assert.ok(!body);

                                // Malformed ids.
                                RestAPI.Content.downloadPreviewItem(contexts['nicolaas'].restContext, 'invalid content id', contentObj.latestRevisionId, previews.files[0].filename, previews.signature, function(err, body, response) {
                                    assert.equal(err.code, 400);
                                    assert.ok(!body);

                                    RestAPI.Content.downloadPreviewItem(contexts['nicolaas'].restContext, contentObj.id, 'invalid revision id', previews.files[0].filename, previews.signature, function(err, body, response) {
                                        assert.equal(err.code, 400);
                                        assert.ok(!body);
                                        callback();
                                    });
                                });
                            });
                                _verifySignedDownloadUrl(contexts['nicolaas'].restContext, revision.mediumUrl, function() {

                                    // Restore the revision
                                    RestAPI.Content.restoreRevision(contexts['nicolaas'].restContext, content.id, revisions.results[0].revisionId, function(err, restoredRevision) {
                                        assert.ok(!err);

                                        // Make sure the restored revision contains all the image urls and not the back-end uris
                                        assert.ok(restoredRevision);
                                        assert.ok(!restoredRevision.thumbnailUri);
                                        assert.ok(restoredRevision.thumbnailUrl);
                                        assert.ok(!restoredRevision.mediumUri);
                                        assert.ok(restoredRevision.mediumUrl);
                                        assert.equal(restoredRevision.previews.status, 'done');
                                        return callback();
                                    });
                                });
Example #8
0
            setupFixture(function(contexts, contentObj, client) {

                // Trigger an update
                RestAPI.Content.updateContent(contexts['branden'].restContext, contentObj.id, {'visibility': 'loggedin'}, function(err) {
                    assert.ok(!err);
                });

                client.on('message', function(message) {
                    ActivityTestsUtil.assertActivity(message.activities[0], ContentConstants.activity.ACTIVITY_CONTENT_UPDATE_VISIBILITY, ActivityConstants.verbs.UPDATE, contexts['branden'].user.id, contentObj.id);

                    // Verify the updated visibility setting is present on the activity object
                    assert.equal(message.activities[0].object.visibility, 'loggedin');

                    client.close(callback);
                });
            });
Example #9
0
 err => {
   assert.ok(!err);
   RestAPI.Content.updateContent(
     contexts.nicolaas.restContext,
     contentObj.id,
     { link: 'http://www.google.com' },
     err => {
       assert.ok(!err);
       RestAPI.Content.getContent(contexts.nicolaas.restContext, contentObj.id, (err, contentObj) => {
         assert.ok(!err);
         assert.strictEqual(contentObj.previews.status, 'done');
         return callback();
       });
     }
   );
 }
Example #10
0
                    RestAPI.Content.getRevisions(simonCtx, contentObj.id, null, null, function(err, revisions) {
                        assert.ok(!err);
                        assert.equal(revisions.length, 2);

                        // Branden is no manager, so he cannot restore anything.
                        RestAPI.Content.restoreRevision(brandenCtx, contentObj.id, revisions[0].revisionId, function(err) {
                            assert.equal(err.code, 401);

                            // Sanity check
                            RestAPI.Content.getRevisions(simonCtx, contentObj.id, null, null, function(err, revisions) {
                                assert.ok(!err);
                                assert.equal(revisions.length, 2);
                                callback();
                            });
                        });
                    });
Example #11
0
            RestAPI.Content.createCollabDoc(simonCtx, name, 'description', 'private', [], [], function(err, contentObj) {
                assert.ok(!err);

                RestAPI.Content.publishCollabDoc(simonCtx, contentObj.id, function(err, data) {
                    assert.ok(!err);
                    assert.ok(data);

                    // Branden has no access yet, so this should be a 401
                    RestAPI.Content.publishCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                        assert.equal(err.code, 401);
                        assert.ok(!data);

                        // Make Branden a viewer.
                        // He should still not be able to publish it.
                        var members = {};
                        members[_.keys(users)[1]] = 'viewer';
                        RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                            assert.ok(!err);

                            // Branden can't publish this document yet.
                            RestAPI.Content.publishCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                assert.equal(err.code, 401);
                                assert.ok(!data);

                                // Now make him a manager
                                members[_.keys(users)[1]] = 'manager';
                                RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                                    assert.ok(!err);

                                    // Branden should now be able to access it.
                                    RestAPI.Content.publishCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                        assert.ok(!err);
                                        assert.ok(data);

                                        // By now we should have 3 revisions (not 4, as Branden's first publish was unauthorized)
                                        RestAPI.Content.getRevisions(simonCtx, contentObj.id, null, null, function(err, revisions) {
                                            assert.ok(!err);
                                            assert.equal(revisions.length, 3);
                                            callback();
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
            });
Example #12
0
                    ActivityTestsUtil.getFullySetupPushClient(data, function(client) {

                        // Create a content item and get its full profile so we have a signature that we can use to register for push notifications
                        RestAPI.Content.createLink(simong.restContext, 'content', 'A piece of content', 'private', 'http://www.google.com', [branden.user.id], [], [], function(err, contentObj) {
                            assert.ok(!err);
                            RestAPI.Content.getContent(simong.restContext, contentObj.id, function(err, contentObj) {
                                assert.ok(!err);

                                // Ensure we get a 400 error with an invalid activity stream id
                                client.subscribe(contentObj.id, null, contentObj.signature, null, function(err) {
                                    assert.equal(err.code, 400);

                                    // Ensure we get a 400 error with a missing resource id
                                    client.subscribe(null, 'activity', contentObj.signature, null, function(err) {
                                        assert.equal(err.code, 400);

                                        // Ensure we get a 400 error with an invalid token
                                        client.subscribe(contentObj.id, 'activity', {'signature': 'foo'}, null, function(err) {
                                            assert.equal(err.code, 401);
                                            client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000}, null, function(err) {
                                                assert.equal(err.code, 401);

                                                // Ensure we get a 401 error with an incorrect signature
                                                client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000, 'signature': 'foo'}, null, function(err) {
                                                    assert.equal(err.code, 401);

                                                    // Simon should not be able to use a signature that was generated for Branden
                                                    RestAPI.Content.getContent(branden.restContext, contentObj.id, function(err, contentObjForBranden) {
                                                        assert.ok(!err);
                                                        client.subscribe(contentObj.id, 'activity', contentObjForBranden.signature, null, function(err) {
                                                            assert.equal(err.code, 401);

                                                            // Sanity check a valid signature works
                                                            client.subscribe(contentObj.id, 'activity', contentObj.signature, null, function(err) {
                                                                assert.ok(!err);
                                                                return callback();
                                                            });
                                                        });
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
Example #13
0
      TestsUtil.generateTestUsers(camAdminRestContext, 1, (err, user) => {
        assert.ok(!err);
        user = _.values(user)[0];

        // Create the content item that we'll test with
        RestAPI.Content.createFile(
          user.restContext,
          'test video',
          null,
          'private',
          _getVideoStream,
          null,
          null,
          null,
          (err, content) => {
            assert.ok(!err);

            // Set a MediaCore id on the content item
            ContentDAO.Previews.storeMetadata(
              content,
              content.latestRevisionId,
              'done',
              null,
              null,
              { mediaCoreId: 12345 },
              {},
              err => {
                assert.ok(!err);

                // Add a handler for the embed code endpoint that returns 200 but invalid JSON
                mediaCoreApp.get('/api2/media/:mediaCoreId/embedcode', (req, res) => {
                  assert.strictEqual(req.params.mediaCoreId, '12345');
                  res.status(502).send({ reason: 'you are DOSd' });
                });

                // Verify we get 500 when fetching embed code for a MediaCore server that has gone awry
                RestAPI.MediaCore.getEmbedCode(user.restContext, content.id, err => {
                  assert.ok(err);
                  assert.strictEqual(err.code, 500);
                  return callback();
                });
              }
            );
          }
        );
      });
Example #14
0
                            RestAPI.Content.joinCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                assert.equal(err.code, 401);
                                assert.ok(!data);

                                // Now that we make Branden a manager, he should be able to join.
                                members[_.keys(users)[1]] = 'manager';
                                RestAPI.Content.updateMembers(simonCtx, contentObj.id, members, function(err) {
                                    assert.ok(!err);

                                    // Branden should now be able to access it.
                                    RestAPI.Content.joinCollabDoc(brandenCtx, contentObj.id, function(err, data) {
                                        assert.ok(!err);
                                        assert.ok(data);
                                        callback();
                                    });
                                });
                            });
                    RestAPI.Content.getPreviewItems(contexts['nicolaas'].restContext, contentObj.id, contentObj.latestRevisionId, function(err, previews) {
                        assert.ok(!err);
                        assert.equal(previews.files.length, 2);

                        // Ensure that the thumbnail and status parameters are set
                        RestAPI.Content.getContent(contexts['nicolaas'].restContext, contentObj.id, function(err, updatedContent) {
                            assert.ok(!err);
                            assert.ok(!updatedContent.previews.thumbnailUri);
                            assert.ok(updatedContent.previews.thumbnailUrl);
                            assert.equal(updatedContent.previews.status, 'done');
                            assert.ok(!updatedContent.previews.smallUri);
                            assert.ok(updatedContent.previews.smallUrl);
                            assert.ok(!updatedContent.previews.mediumUri);
                            assert.ok(updatedContent.previews.mediumUrl);
                            return callback(contexts, updatedContent, previews);
                        });
                    });
Example #16
0
                        (err, body, response) => {
                          assert.strictEqual(err.code, 400);
                          assert.ok(!body);

                          RestAPI.Content.downloadPreviewItem(
                            contexts.nicolaas.restContext,
                            contentObj.id,
                            'invalid revision id',
                            previews.files[0].filename,
                            previews.signature,
                            (err, body, response) => {
                              assert.strictEqual(err.code, 400);
                              assert.ok(!body);
                              return callback();
                            }
                          );
                        }
Example #17
0
        (err, contentObj) => {
          assert.ok(!err);

          // Verify that a new link results in an empty previews object
          RestAPI.Content.updateContent(
            contexts.nicolaas.restContext,
            contentObj.id,
            { link: 'http://www.google.com' },
            err => {
              assert.ok(!err);
              RestAPI.Content.getContent(contexts.nicolaas.restContext, contentObj.id, (err, contentObj) => {
                assert.ok(!err);
                assert.strictEqual(contentObj.previews.status, 'pending');

                // Verify that an update with the same link doesn't change the previews object
                // First, set the status to done manually so we can verify a no-change on a non-update
                RestAPI.Content.setPreviewItems(
                  globalAdminOnTenantRestContext,
                  contentObj.id,
                  contentObj.latestRevisionId,
                  'done',
                  {},
                  {},
                  {},
                  {},
                  err => {
                    assert.ok(!err);
                    RestAPI.Content.updateContent(
                      contexts.nicolaas.restContext,
                      contentObj.id,
                      { link: 'http://www.google.com' },
                      err => {
                        assert.ok(!err);
                        RestAPI.Content.getContent(contexts.nicolaas.restContext, contentObj.id, (err, contentObj) => {
                          assert.ok(!err);
                          assert.strictEqual(contentObj.previews.status, 'done');
                          return callback();
                        });
                      }
                    );
                  }
                );
              });
            }
          );
        }
Example #18
0
    createPreviews((contexts, contentObj, previews) => {
      // Only global admins should be allowed to create previews.
      RestAPI.Content.setPreviewItems(
        anonymousRestContext,
        contentObj.id,
        contentObj.latestRevisionId,
        'done',
        suitable_files,
        suitable_sizes,
        {},
        {},
        err => {
          assert.ok(err);
          assert.strictEqual(err.code, 401);

          // Download one.
          RestAPI.Content.downloadPreviewItem(
            contexts.nicolaas.restContext,
            contentObj.id,
            contentObj.latestRevisionId,
            previews.files[0].filename,
            previews.signature,
            (err, body, response) => {
              assert.ok(!err);
              assert.ok(!body); // Nginx streams the actual file body, the app server just returns a 204.
              assert.strictEqual(response.statusCode, 204);
              assert.ok(response.headers['x-accel-redirect']);

              // Make sure that nobody else can see a private item, even if they have the signature.
              RestAPI.Content.downloadPreviewItem(
                contexts.simon.restContext,
                contentObj.id,
                contentObj.latestRevisionId,
                previews.files[0].filename,
                previews.signature,
                (err, body, response) => {
                  assert.strictEqual(err.code, 401);
                  assert.ok(!body);
                  callback();
                }
              );
            }
          );
        }
      );
    });
Example #19
0
                (err, previews) => {
                  assert.ok(!err);
                  assert.strictEqual(previews.files.length, 2);

                  // Ensure that the thumbnail and status parameters are set
                  RestAPI.Content.getContent(contexts.nicolaas.restContext, contentObj.id, (err, updatedContent) => {
                    assert.ok(!err);
                    assert.ok(!updatedContent.previews.thumbnailUri);
                    assert.ok(updatedContent.previews.thumbnailUrl);
                    assert.strictEqual(updatedContent.previews.status, 'done');
                    assert.ok(!updatedContent.previews.smallUri);
                    assert.ok(updatedContent.previews.smallUrl);
                    assert.ok(!updatedContent.previews.mediumUri);
                    assert.ok(updatedContent.previews.mediumUrl);
                    return callback(contexts, updatedContent, previews);
                  });
                }
Example #20
0
                                                            RestAPI.Discussions.createDiscussion(simong.restContext, 'Test discussion', 'Test discussion description', 'public', [], [mrvisser.user.id], function(err, discussion) {
                                                                assert.ok(!err);
                                                                RestAPI.Content.createLink(simong.restContext, 'Test link', 'Test link', 'public', 'https://google.com', [], [mrvisser.user.id], [], function(err, discussion) {
                                                                    assert.ok(!err);
                                                                    ActivityTestUtil.collectAndGetNotificationStream(mrvisser.restContext, null, function(err, activityStream) {
                                                                        assert.ok(!err);
                                                                    });

                                                                    client.once('message', function(message) {
                                                                        assert.ok(message);
                                                                        assert.strictEqual(message.numNewActivities, 2);
                                                                        assert.strictEqual(message.activities.length, 2);

                                                                        return callback();
                                                                    });
                                                                });
                                                            });
Example #21
0
            setupFixture(function(contexts, folder, client) {

                // Add an item to a folder
                RestAPI.Content.createLink(contexts['simon'].restContext, 'test', 'test', 'public', 'http://www.google.ca', null, null, [folder.id], function(err, nicosLink) {
                    assert.ok(!err);
                });

                client.on('message', function(message) {
                    assert.notEqual(message.activities[0]['oae:activityType'], FoldersConstants.activity.ACTIVITY_FOLDER_ADD_TO_FOLDER);
                });

                // This timeout is not ideal, but we need to give the activity router some time
                // to let it do its thing
                setTimeout(function() {
                    client.close(callback);
                }, 300);
            });
Example #22
0
            RestAPI.Content.createLink(userA, nameX, null, 'public', 'http://www.oaeproject.org', [], [], function(err, baseContent) {
                assert.ok(!err);

                RestAPI.Content.createLink(userB, nameY, null, 'public', 'http://www.oaeproject.org', [], [], function(err, noDescriptionContent) {
                    assert.ok(!err);
                    RestAPI.Content.createLink(userC, nameY, 'description or some such', 'public', 'http://www.oaeproject.org', [], [], function(err, withDescriptionContent) {
                        assert.ok(!err);

                        SearchTestsUtil.searchAll(anonymousCamRestContext, 'relatedcontent', [baseContent.id], null, function(err, results) {
                            assert.ok(!err);
                            assert.equal(results.results[0].id, withDescriptionContent.id);
                            assert.equal(results.results[1].id, noDescriptionContent.id);
                            callback();
                        });
                    });
                });
            });
Example #23
0
            RestAPI.Content.createLink(userA, alfa, null, 'public', 'http://www.oaeproject.org', [], [], function(err, baseContent) {
                assert.ok(!err);

                RestAPI.Content.createLink(userA, beta, null, 'public', 'http://www.oaeproject.org', [], [], function(err, sameCreatorContent) {
                    assert.ok(!err);
                    RestAPI.Content.createLink(userB, beta, null, 'public', 'http://www.oaeproject.org', [], [], function(err, otherCreatorContent) {
                        assert.ok(!err);

                        SearchTestsUtil.searchAll(anonymousCamRestContext, 'relatedcontent', [baseContent.id], null, function(err, results) {
                            assert.ok(!err);
                            assert.equal(results.results[0].id, sameCreatorContent.id);
                            assert.equal(results.results[1].id, otherCreatorContent.id);
                            callback();
                        });
                    });
                });
            });
Example #24
0
                        RestAPI.Content.updateFileBody(mrvisser.restContext, contentObj.id, getStream, function(err) {
                            assert.ok(!err);
                            RestAPI.Content.updateFileBody(mrvisser.restContext, contentObj.id, getStream, function(err) {
                                assert.ok(!err);

                                ContentDAO.Revisions.getAllRevisionsForContent([contentObj.id], function(err, data) {
                                    assert.ok(!err);
                                    assert.ok(data[contentObj.id]);
                                    assert.ok(data[contentObj.id].length, 5);
                                    _.each(data[contentObj.id], function(revision) {
                                        assert.equal(revision.contentId, contentObj.id);
                                        assert.equal(revision.filename, 'apereo.jpg');
                                    });
                                    return callback();
                                });
                            });
                        });
Example #25
0
                                                    client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000, 'signature': 'foo', 'lastModified': Date.now()}, null, function(err) {
                                                        assert.equal(err.code, 401);

                                                        // Simon should not be able to use a signature that was generated for Branden
                                                        RestAPI.Content.getContent(branden.restContext, contentObj.id, function(err, contentObjForBranden) {
                                                            assert.ok(!err);
                                                            client.subscribe(contentObj.id, 'activity', contentObjForBranden.signature, null, function(err) {
                                                                assert.equal(err.code, 401);

                                                                // Sanity check
                                                                client.subscribe(contentObj.id, 'activity', contentObj.signature, null, function(err) {
                                                                    assert.ok(!err);
                                                                    return callback();
                                                                });
                                                            });
                                                        });
                                                    });
Example #26
0
                        RestAPI.Content.createLink(simong.restContext, 'content', 'A piece of content', 'private', 'http://www.google.com', [branden.user.id], [], function(err, contentObj) {
                            assert.ok(!err);
                            RestAPI.Content.getContent(simong.restContext, contentObj.id, function(err, contentObj) {
                                assert.ok(!err);

                                // Ensure we get a 400 error with an invalid activity stream id
                                client.subscribe(contentObj.id, null, contentObj.signature, null, function(err) {
                                    assert.equal(err.code, 400);

                                    // Ensure we get a 400 error with a missing resource id
                                    client.subscribe(null, 'activity', contentObj.signature, null, function(err) {
                                        assert.equal(err.code, 400);

                                        // Ensure we get a 400 error with an invalid token
                                        client.subscribe(contentObj.id, 'activity', {'signature': 'foo', 'lastModified': Date.now()}, null, function(err) {
                                            assert.equal(err.code, 400);
                                            client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000, 'lastModified': Date.now()}, null, function(err) {
                                                assert.equal(err.code, 400);
                                                client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000, 'signature': 'foo'}, null, function(err) {
                                                    assert.equal(err.code, 400);

                                                    // Ensure we get a 401 error with an incorrect signature
                                                    client.subscribe(contentObj.id, 'activity', {'expires': Date.now() + 10000, 'signature': 'foo', 'lastModified': Date.now()}, null, function(err) {
                                                        assert.equal(err.code, 401);

                                                        // Simon should not be able to use a signature that was generated for Branden
                                                        RestAPI.Content.getContent(branden.restContext, contentObj.id, function(err, contentObjForBranden) {
                                                            assert.ok(!err);
                                                            client.subscribe(contentObj.id, 'activity', contentObjForBranden.signature, null, function(err) {
                                                                assert.equal(err.code, 401);

                                                                // Sanity check
                                                                client.subscribe(contentObj.id, 'activity', contentObj.signature, null, function(err) {
                                                                    assert.ok(!err);
                                                                    return callback();
                                                                });
                                                            });
                                                        });
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
                        });
        createPreviews(function(contexts, content, previews) {

            // Verify a list of revisions
            RestAPI.Content.getRevisions(contexts['nicolaas'].restContext, content.id, null, null, function(err, revisions) {
                assert.ok(!err);
                assert.ok(!revisions.results[0].thumbnailUri);
                assert.ok(revisions.results[0].thumbnailUrl);
                assert.ok(!revisions.results[0].mediumUri);
                assert.ok(revisions.results[0].mediumUrl);

                _verifySignedDownloadUrl(contexts['nicolaas'].restContext, revisions.results[0].thumbnailUrl, function() {
                    _verifySignedDownloadUrl(contexts['nicolaas'].restContext, revisions.results[0].mediumUrl, function() {

                        // Verify a single revision
                        RestAPI.Content.getRevision(contexts['nicolaas'].restContext, content.id, revisions.results[0].revisionId, function(err, revision) {
                            assert.ok(!err);
                            assert.ok(!revision.thumbnailUri);
                            assert.ok(revision.thumbnailUrl);
                            assert.ok(!revision.mediumUri);
                            assert.ok(revision.mediumUrl);

                            // Verify the URLs can resolve to a successful response
                            _verifySignedDownloadUrl(contexts['nicolaas'].restContext, revision.thumbnailUrl, function() {
                                _verifySignedDownloadUrl(contexts['nicolaas'].restContext, revision.mediumUrl, function() {

                                    // Restore the revision
                                    RestAPI.Content.restoreRevision(contexts['nicolaas'].restContext, content.id, revisions.results[0].revisionId, function(err, restoredRevision) {
                                        assert.ok(!err);

                                        // Make sure the restored revision contains all the image urls and not the back-end uris
                                        assert.ok(restoredRevision);
                                        assert.ok(!restoredRevision.thumbnailUri);
                                        assert.ok(restoredRevision.thumbnailUrl);
                                        assert.ok(!restoredRevision.mediumUri);
                                        assert.ok(restoredRevision.mediumUrl);
                                        assert.equal(restoredRevision.previews.status, 'done');
                                        return callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
Example #28
0
            TestsUtil.generateTestUsers(camAdminRestContext, 1, function(err, user) {
                assert.ok(!err);
                user = _.values(user)[0];

                // Create the content item that we'll test with
                RestAPI.Content.createFile(user.restContext, 'test video', null, 'private', _getVideoStream, null, null, null, function(err, content) {
                    assert.ok(!err);

                    var mediaCoreId = '23456';

                    // Set a MediaCore id on the content item
                    ContentDAO.Previews.storeMetadata(content, content.latestRevisionId, 'done', null, null, {'mediaCoreId': mediaCoreId}, {}, function(err) {
                        assert.ok(!err);

                        // Map id 23456 to the content item
                        MediaCoreDAO.saveContentRevisionId(mediaCoreId, content.id, content.latestRevisionId, function(err) {
                            assert.ok(!err);

                            // Ensure an invalid id results in a 400
                            RestAPI.MediaCore.notifyEncodingComplete(user.restContext, 'not-an-id', function(err) {
                                assert.ok(err);
                                assert.equal(err.code, 400);

                                // Ensure a non-existing id results in a 404
                                RestAPI.MediaCore.notifyEncodingComplete(user.restContext, 0, function(err) {
                                    assert.ok(err);
                                    assert.equal(err.code, 404);

                                    var fetchedThumbnails = false;

                                    // Add a handler that listens for the expected thumbnail request returning a successful response
                                    mediaCoreApp.get('/api2/media/:mediaCoreId/thumbs', function(req, res) {
                                        res.status(200).send({'sizes': {}});
                                    });

                                    RestAPI.MediaCore.notifyEncodingComplete(user.restContext, mediaCoreId, function(err) {
                                        assert.ok(!err);
                                        return callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
Example #29
0
        TestsUtil.generateTestUsers(camAdminRestContext, 1, function(err, users) {
            assert.ok(!err);
            var simonCtx = _.values(users)[0].restContext;

            // Simon creates a collaborative document that's private.
            var name = TestsUtil.generateTestUserId();
            RestAPI.Content.createCollabDoc(simonCtx, name, 'description', 'private', [], [], function(err, contentObj) {
                assert.ok(!err);

                // Verify there is no HTML present yet.
                getContentWithLatestRevision(simonCtx, contentObj.id, function(contentObj, revision) {
                    assert.ok(!contentObj.latestRevision.etherpadHtml);
                    assert.ok(!revision.etherpadHtml);

                    // Do some edits in etherpad.
                    var text = 'Only two things are infinite, the universe and human stupidity, and I am not sure about the former.';
                    editAndPublish(simonCtx, contentObj, [text], function() {

                        getContentWithLatestRevision(simonCtx, contentObj.id, function(updatedContentObj, updatedRevision) {
                            assert.ok(updatedContentObj.latestRevision.etherpadHtml);
                            assert.ok(updatedRevision.etherpadHtml);
                            assert.notEqual(updatedContentObj.latestRevision.etherpadHtml, revision.etherpadHtml);
                            assert.notEqual(updatedRevision.etherpadHtml, revision.etherpadHtml);

                            // Remove linebreaks and check if the text is correct.
                            var html = updatedRevision.etherpadHtml.replace('<br>', '');
                            assert.equal(html, text);

                            // If we make any further updates in etherpad they shouldn't show up yet from our API.
                            setEtherpadText(contentObj, 'There are no facts, only interpretations.', function(err) {
                                assert.ok(!err);

                                getContentWithLatestRevision(simonCtx, contentObj.id, function(latestContentObj, latestRevision) {
                                    assert.ok(latestContentObj.latestRevision.etherpadHtml);
                                    assert.ok(latestRevision.etherpadHtml);
                                    assert.equal(latestContentObj.latestRevision.etherpadHtml, updatedContentObj.latestRevision.etherpadHtml);
                                    assert.equal(latestRevision.etherpadHtml, updatedRevision.etherpadHtml);
                                    callback();
                                });
                            });
                        });
                    });
                });
            });
        });
Example #30
0
        TestsUtil.generateTestUsers(camAdminRestContext, 1, function(err, users) {
            assert.ok(!err);
            var simonCtx = _.values(users)[0].restContext;

            var name = TestsUtil.generateTestUserId('collabdoc');
            RestAPI.Content.createCollabDoc(simonCtx, name, 'description', 'private', [], [], function(err, contentObj) {
                assert.ok(!err);

                var texts = [
                    'Always do sober what you said you\'d do drunk. That will teach you to keep your mouth shut.',
                    'Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions.',
                    'I don\'t have to play by these rules or do these things... I can actually have my own kind of version.'
                ];
                editAndPublish(simonCtx, contentObj, texts, function() {
                    RestAPI.Content.getRevisions(simonCtx, contentObj.id, null, null, function(err, revisions) {
                        assert.ok(!err);

                        // We published our document 3 times, this should result in 4 revisions. (1 create + 3 publications)
                        assert.equal(revisions.length, 4);

                        // Restore the second revision.
                        // The html on the content item and in etherpad should be updated.
                        RestAPI.Content.restoreRevision(simonCtx, contentObj.id, revisions[1].revisionId, function(err) {
                            assert.ok(!err);

                            getContentWithLatestRevision(simonCtx, contentObj.id, function(updatedContent, updatedRevision) {
                                // Make sure the revisions feed doesn't have etherpadHtml in it
                                assert.ok(!revisions[1].etherpadHtml);
                                // Fetch the individual revision so we can verify the etherpadHtml is correct
                                RestAPI.Content.getRevision(simonCtx, revisions[1].contentId, revisions[1].revisionId, function(err, fullRev) {
                                    assert.equal(updatedContent.latestRevision.etherpadHtml, fullRev.etherpadHtml);
                                    assert.equal(updatedRevision.etherpadHtml, fullRev.etherpadHtml);

                                    getEtherpadText(contentObj, function(err, data) {
                                        assert.ok(!err);
                                        assert.equal(data.text, texts[1] + '\n');
                                        callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });