Example #1
0
    before(function(callback) {
        // Fill up global admin rest context
        globalAdminRestContext = TestsUtil.createGlobalAdminRestContext();
        // Fill up the anonymous context
        anonymousRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.localhost.host);
        // Cambridge tenant admin context
        camAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.cam.host);

        // An object that adheres to the RestAPI.Content.setPreviewItems.files parameter.
        suitable_files = {
            'file.small.jpg': getFileStream,
            'file.medium.jpg': getOAELogoStream,
            'thumbnail.png': getFileStream
        };
        suitable_sizes = {
            'file.small.jpg': 'small',
            'file.medium.jpg': 'medium',
            'thumbnail.png': 'thumbnail'
        };

        // Login on the camtest tenant
        RestAPI.Admin.loginOnTenant(globalAdminRestContext, 'localhost', function(err, ctx) {
            assert.ok(!err);
            globalAdminOnTenantRestContext = ctx;

            RestAPI.User.getMe(globalAdminOnTenantRestContext, function(err, user) {
                assert.ok(!err);
                assert.ok(!user.anon);
                callback();
            });
        });
    });
Example #2
0
 it('verify anonymous users cannot generate a url', function(callback) {
     RestAPI.Admin.loginOnTenant(anonymousGlobalRestContext, 'localhost', function(err, restCtx) {
         assert.ok(err);
         assert.equal(err.code, 401);
         assert.ok(!restCtx);
         callback();
     });
 });
Example #3
0
 it('verify login on tenant works', function(callback) {
     RestAPI.Admin.loginOnTenant(globalAdminRestContext, 'localhost', function(err, restCtx) {
         assert.ok(!err);
         RestAPI.User.getMe(restCtx, function(err, user) {
             assert.ok(!err);
             assert.ok(!user.anon);
             assert.ok(user.isGlobalAdmin, 'The user should still be a global administrator');
             callback();
         });
     });
 });
Example #4
0
before(function(callback) {
    camAnonymousRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.cam.host);
    camAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.cam.host);
    gtAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.gt.host);

    // Authenticate the global admin into a tenant so we can perform user-tenant requests with a global admin to test their access
    RestAPI.Admin.loginOnTenant(TestsUtil.createGlobalAdminRestContext(), 'localhost', function(err, ctx) {
        assert.ok(!err);
        globalAdminOnTenantRestContext = ctx;
        return callback();
    });
});
Example #5
0
      it('verify login on tenant works', callback => {
        RestAPI.Admin.loginOnTenant(globalAdminRestContext, 'localhost', null, (err, restCtx) => {
          assert.ok(!err);

          RestAPI.User.getMe(restCtx, (err, user) => {
            assert.ok(!err);
            assert.ok(!user.anon);
            assert.ok(user.isGlobalAdmin, 'The user should still be a global administrator');
            return callback();
          });
        });
      });
Example #6
0
 before(function(callback) {
     // Fill up cam admin rest context
     camAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.cam.host);
     // Fill up global admin rest context
     globalAdminRestContext = TestsUtil.createGlobalAdminRestContext();
     // Fill up anonymous localhost cam rest context
     anonymousLocalRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.localhost.host);
     // Fill up localhost tenant admin rest context
     RestAPI.Admin.loginOnTenant(globalAdminRestContext, 'localhost', null, function(err, restContext) {
         assert.ok(!err);
         localAdminRestContext = restContext;
         return callback();
     });
 });
    beforeEach(function(callback) {
        // Fill up anonymous rest context
        anonymousRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.cam.host);
        // Fill up tenant admin rest contexts
        camAdminRestContext = TestsUtil.createTenantAdminRestContext(global.oaeTests.tenants.cam.host);
        // Fill up global admin rest context
        globalAdminRestContext = TestsUtil.createGlobalAdminRestContext();

        // Log the global admin into a tenant so we can perform user-tenant requests with a global admin to test their access
        RestAPI.Admin.loginOnTenant(globalAdminRestContext, 'localhost', null, function(err, ctx) {
            assert.ok(!err);
            globalAdminOnTenantRestContext = ctx;
            return callback();
        });
    });
Example #8
0
    that.login = function(callback) {
        var tenantAlias = that.contentId.split(':')[1];
        log().trace({'contentId': contentId}, 'Logging into %s', tenantAlias);

        // Log in via signed auth, and get a new RestContext.
        RestAPI.Admin.loginOnTenant(globalRestContext, tenantAlias, function(err, restContext) {
            if (err) {
                log().error({'err': err, 'contentId': contentId}, 'We could not log in on the the tenant. The status of the content item will not be set.');
                return callback(err);
            }
            // Use this context
            that.tenantRestContext = restContext;

            callback();
        });
    };
Example #9
0
    it('verify thumbnail boosting', function(callback) {
        // Get the global admin context on a tenant
        RestAPI.Admin.loginOnTenant(globalAdminRestContext, global.oaeTests.tenants.localhost.alias, function(err, globalTenantAdminRestContext) {
            assert.ok(!err);

            TestsUtil.generateTestUsers(globalTenantAdminRestContext, 3, function(err, users) {
                assert.ok(!err);
                var userA = _.values(users)[0].restContext;
                var userB = _.values(users)[1].restContext;
                var userC = _.values(users)[2].restContext;

                var nameX = 'Green water is not uncommon in red caves';
                var nameY = 'Yellow water is not uncommon in red caves';

                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, noThumbnailContent) {
                        assert.ok(!err);
                        RestAPI.Content.createLink(userC, nameY, null, 'public', 'http://www.oaeproject.org', [], [], function(err, withThumbnailContent) {
                            assert.ok(!err);
                            RestAPI.Content.getRevisions(userC, withThumbnailContent.id, null, 1, function(err, revisions) {
                                assert.ok(!err);
                                var revisionId = revisions[0].revisionId;

                                // Give the Y-document of user C a thumbnail.
                                var files = {'thumbnail.png': getFileStream};
                                var sizes = {'thumbnail.png': 'thumbnail'};
                                RestAPI.Content.setPreviewItems(globalTenantAdminRestContext, withThumbnailContent.id, revisionId, 'done', files, sizes, {}, {}, function(err) {
                                    assert.ok(!err);

                                    SearchTestsUtil.searchAll(userA, 'relatedcontent', [baseContent.id], null, function(err, results) {
                                        assert.ok(!err);
                                        assert.equal(results.total, 2);
                                        assert.equal(results.results[0].id, withThumbnailContent.id);
                                        assert.equal(results.results[1].id, noThumbnailContent.id);
                                        callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });