Example #1
0
        createUsers(function(contexts) {
            var selectedArea = createSelectedArea(10, 10, 200, 200);
            RestAPI.User.uploadPicture(contexts['simon'].restContext, contexts['simon'].user.id, getPictureStream, selectedArea, function(err) {
                assert.ok(!err);

                // Download the different sizes.
                RestAPI.User.downloadPicture(contexts['simon'].restContext, contexts['simon'].user.id, 'small', function(err, body, response) {
                    assert.ok(!err);
                    assert.equal(response.statusCode, 204);
                    RestAPI.User.downloadPicture(contexts['simon'].restContext, contexts['simon'].user.id, 'medium', function(err, body, response) {
                        assert.ok(!err);
                        assert.equal(response.statusCode, 204);
                        RestAPI.User.downloadPicture(contexts['simon'].restContext, contexts['simon'].user.id, 'large', function(err, body, response) {
                            assert.ok(!err);
                            assert.equal(response.statusCode, 204);

                            // Now try downloading it with some invalid parameters.
                            RestAPI.User.downloadPicture(contexts['simon'].restContext, 'invalid-user-id', 'small', function(err, body, response) {
                                assert.equal(err.code, 400);
                                RestAPI.User.downloadPicture(contexts['simon'].restContext, contexts['simon'].user.id, null, function(err, body, response) {
                                    assert.equal(err.code, 400);

                                    // Nicolaas has no picture, this should result in a 404
                                    RestAPI.User.downloadPicture(contexts['simon'].restContext, contexts['nicolaas'].user.id, 'small', function(err, body, response) {
                                        assert.equal(err.code, 404);
                                        callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
Example #2
0
        createUser(function(ctx) {
            var selectedArea = createSelectedArea(10, 10, 200, 200);
            RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
                assert.ok(!err);

                // Get the user metadata and thus the picture url.
                RestAPI.User.getUser(ctx, ctx.user.id, function(err, firstRequestUser) {
                    assert.ok(!err);

                    // Upload a new picture.
                    RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
                        assert.ok(!err);

                        // Get the new user metadata.
                        RestAPI.User.getUser(ctx, ctx.user.id, function(err, secondRequestUser) {
                            assert.ok(!err);

                            // Get the URIs and check that they are not removed on the filesystem.
                            var smallPicturePath = rootFilesDir + '/' + firstRequestUser.picture.smallUri.split(':')[1];
                            var mediumPicturePath = rootFilesDir + '/' + firstRequestUser.picture.mediumUri.split(':')[1];
                            assert.equal(fs.existsSync(smallPicturePath), true, 'The small picture should still exist when uploading a large image.');
                            assert.equal(fs.existsSync(mediumPicturePath), true, 'The medium picture should still exist when uploading a large image.');
                            callback();
                        });
                    });
                });
            });
        });
            TestsUtil.generateTestGroups(simon.restContext, 4, function(oaeTeam, backendTeam, uiTeam, qaTeam) {

                // Upload pictures for the sub teams
                var selectedArea = _createSelectedArea(10, 10, 200, 200);
                RestAPI.User.uploadPicture(simon.restContext, backendTeam.group.id, _getPictureStream, selectedArea, function(err) {
                    assert.ok(!err);

                    RestAPI.User.uploadPicture(simon.restContext, uiTeam.group.id, _getPictureStream, selectedArea, function(err) {
                        assert.ok(!err);

                        RestAPI.User.uploadPicture(simon.restContext, qaTeam.group.id, _getPictureStream, selectedArea, function(err) {
                            assert.ok(!err);

                            // Make the uiTeam loggedin.
                            RestAPI.Group.updateGroup(simon.restContext, uiTeam.group.id, { 'visibility': 'loggedin'}, function(err) {
                                assert.ok(!err);

                                // Make the qa team private.
                                RestAPI.Group.updateGroup(simon.restContext, qaTeam.group.id, { 'visibility': 'private'}, function(err) {
                                    assert.ok(!err);

                                    // Make the backend, ui and qa teams member of oae team.
                                    var changes = {};
                                    changes[backendTeam.group.id] = 'member';
                                    changes[uiTeam.group.id] = 'member';
                                    changes[qaTeam.group.id] = 'member';
                                    RestAPI.Group.setGroupMembers(simon.restContext, oaeTeam.group.id, changes, function(err) {
                                        assert.ok(!err);

                                        // Search through the memberlist of oaeTeam and filter the results so we only get the backend team group back.
                                        SearchTestsUtil.searchAll(simon.restContext, 'members-library', [oaeTeam.group.id], { 'q': '' }, function(err, results) {
                                            assert.ok(!err);
                                            assert.equal(results.total, 4);

                                            // We only need the groups
                                            results.results = _.filter(results.results, function(result) { return result.resourceType !== 'user'; });

                                            // All the groups should expose their thumbnail regardless of their visibility setting.
                                            assert.ok(results.results[0].thumbnailUrl);
                                            assert.ok(results.results[1].thumbnailUrl);
                                            assert.ok(results.results[2].thumbnailUrl);

                                            // Try downloading it by just using the returned url.
                                            RestUtil.RestRequest(simon.restContext, results.results[0].thumbnailUrl, 'GET', null, function(err, body, response) {
                                                assert.ok(!err);
                                                // Downloading happens via nginx, so we can't verify the response body.
                                                // We can verify if the status code is a 204 and if the appropriate headers are present.
                                                assert.equal(response.statusCode, 204);
                                                assert.ok(response.headers['x-accel-redirect']);
                                                assert.ok(response.headers['content-disposition']);
                                                callback();
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
            });
Example #4
0
 createUser(function(ctx) {
     var selectedArea = createSelectedArea(10, 10, 200);
     RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
         assert.ok(!err);
         callback();
     });
 });
                        RestAPI.User.uploadPicture(loggedInUser.restContext, loggedInUser.user.id, _getPictureStream, selectedArea, function(err) {
                            assert.ok(!err);

                            RestAPI.User.uploadPicture(privateUser.restContext, privateUser.user.id, _getPictureStream, selectedArea, function(err) {
                                assert.ok(!err);

                                // Create a group with the two other members
                                var groupName = TestsUtil.generateTestUserId('someGroupName');
                                RestAPI.Group.createGroup(privateUser.restContext, groupName, groupName, 'public', 'no', [], [loggedInUser.user.id, publicUser.user.id], function(err, group) {
                                    assert.ok(!err);

                                    // Perform one search where we wait for the search index to refresh so all subsequent search requests don't have to wait
                                    SearchTestsUtil.whenIndexingComplete(function() {

                                        // The public member can only see his own thumbnail and the loggedin user
                                        _verifySearchThumbnails(publicUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                            // The 'logged in' user can see his own thumbnail and the public one
                                            _verifySearchThumbnails(loggedInUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                // The private user can see everyone's thumbnail
                                                return _verifySearchThumbnails(privateUser.restContext, group.id, true, true, true, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, callback);
                                            });
                                        });
                                    });
                                });
                            });
                        });
 TestsUtil.generateTestGroups(ctx, 1, function() {
     var groupId = _.first(arguments).group.id;
     RestAPI.User.uploadPicture(ctx, groupId, _getPictureStream, null, function(err) {
         assert.ok(!err);
         return callback();
     });
 });
Example #7
0
                            RestAPI.User.uploadPicture(loggedInUser.restContext, loggedInUser.user.id, getPictureStream, selectedArea, function(err) {
                                assert.ok(!err);

                                RestAPI.User.uploadPicture(privateUser.restContext, privateUser.user.id, getPictureStream, selectedArea, function(err) {
                                    assert.ok(!err);

                                    // Create a group with the two other members.
                                    var groupName = TestsUtil.generateTestUserId('someGroupName');
                                    RestAPI.Group.createGroup(privateUser.restContext, groupName, groupName, groupName, 'public', 'no', [], [loggedInUser.user.id, publicUser.user.id], function(err, group) {
                                        assert.ok(!err);

                                        // anonymous can search the group membership list but can only see the public user his picture.
                                        verifySearchThumbnails(anonymousRestContext, group.id, true, false, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                            // a logged in user can see the public and 'logged in' user.
                                            verifySearchThumbnails(nonMemberUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                // The public member can only see his own thumbnail and the loggedin user.
                                                verifySearchThumbnails(publicUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                    // The 'logged in' user can see his own thumbnail and the public one.
                                                    verifySearchThumbnails(loggedInUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                        // The private user can see everyone's thumbnail.
                                                        verifySearchThumbnails(privateUser.restContext, group.id, true, true, true, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, callback);
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
Example #8
0
 createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
         assert.ok(!err);
         var selectedArea = createSelectedArea(10, 10, 200);
         verifyCropping(ctx, ctx.user, selectedArea, 200, callback);
     });
 });
Example #9
0
                        RestAPI.User.uploadPicture(loggedInUser.restContext, loggedInUser.user.id, getPictureStream, selectedArea, function(err) {
                            assert.ok(!err);

                            RestAPI.User.uploadPicture(privateUser.restContext, privateUser.user.id, getPictureStream, selectedArea, function(err) {
                                assert.ok(!err);

                                // Create a group with the two other members.
                                var groupName = TestsUtil.generateTestUserId('someGroupName');
                                RestAPI.Group.createGroup(privateUser.restContext, groupName, groupName, 'public', 'no', [], [loggedInUser.user.id, publicUser.user.id], function(err, group) {
                                    assert.ok(!err);
                                    // Perform one search where we wait for the search index to refresh.
                                    // All subsequent search requests don't have to wait.
                                    SearchTestsUtil.searchAll(anonymousRestContext, 'members', [group.id], null, function(err, results) {
                                        assert.ok(!err);

                                        // anonymous can search the group membership list but can only see the public user his picture.
                                        verifySearchThumbnails(anonymousRestContext, group.id, true, false, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                            // a logged in user can see the public and 'logged in' user.
                                            verifySearchThumbnails(nonMemberUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                // The public member can only see his own thumbnail and the loggedin user.
                                                verifySearchThumbnails(publicUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                    // The 'logged in' user can see his own thumbnail and the public one.
                                                    verifySearchThumbnails(loggedInUser.restContext, group.id, true, true, false, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, function() {
                                                        // The private user can see everyone's thumbnail.
                                                        verifySearchThumbnails(privateUser.restContext, group.id, true, true, true, publicUser.user.id, loggedInUser.user.id, privateUser.user.id, callback);
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
                        });
 _createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, _getPictureStream, null, function(err) {
         assert.ok(!err);
         _verifyCropping(ctx, ctx.user, _createSelectedArea(20000, 10, 100), 400, function() {
             _verifyCropping(ctx, ctx.user, _createSelectedArea(10, 200000, 100), 400, callback);
         });
     });
 });
Example #11
0
 TestsUtil.generateTestGroups(ctx, 1, function(err, groups) {
     assert.ok(!err);
     var groupId = _.keys(groups)[0];
     RestAPI.User.uploadPicture(ctx, groupId, getPictureStream, null, function(err) {
         assert.ok(!err);
         callback();
     });
 });
Example #12
0
File: util.js Project: bp323/Hilary
var uploadAndCropPicture = module.exports.uploadAndCropPicture = function(restCtx, principalId, getPictureStream, selectedArea, callback) {
    RestAPI.User.uploadPicture(restCtx, principalId, getPictureStream, null, function(err, uploadPicturePrincipal) {
        assert.ok(!err);
        RestAPI.Crop.cropPicture(restCtx, principalId, selectedArea, function(err, cropPicturePrincipal) {
            assert.ok(!err);
            return callback(uploadPicturePrincipal, cropPicturePrincipal);
        });
    });
};
Example #13
0
        createUsers(function(contexts) {
            var selectedArea = createSelectedArea(10, 10, 200, 200);
            RestAPI.User.uploadPicture(contexts['simon'].restContext, contexts['simon'].user.id, getPictureStream, selectedArea, function(err) {
                assert.ok(!err);

                RestAPI.User.updateUser(contexts['simon'].restContext, contexts['simon'].user.id, {'visibility': 'private'}, function(err) {
                    assert.ok(!err);

                    RestAPI.User.getUser(contexts['nicolaas'].restContext, contexts['simon'].user.id, function(err, user) {
                        assert.ok(!err);
                        assert.equal(user.picture.small, undefined);
                        assert.equal(user.picture.smallUri, undefined);
                        assert.equal(user.picture.medium, undefined);
                        assert.equal(user.picture.mediumUri, undefined);
                        assert.equal(user.picture.large, undefined);
                        assert.equal(user.picture.largeUri, undefined);

                        RestAPI.User.getUser(anonymousRestContext, contexts['simon'].user.id, function(err, user) {
                            assert.ok(!err);
                            assert.equal(user.picture.small, undefined);
                            assert.equal(user.picture.smallUri, undefined);
                            assert.equal(user.picture.medium, undefined);
                            assert.equal(user.picture.mediumUri, undefined);
                            assert.equal(user.picture.large, undefined);
                            assert.equal(user.picture.largeUri, undefined);

                            RestAPI.User.updateUser(contexts['simon'].restContext, contexts['simon'].user.id, {'visibility': 'loggedin'}, function(err) {
                                assert.ok(!err);

                                RestAPI.User.getUser(contexts['nicolaas'].restContext, contexts['simon'].user.id, function(err, user) {
                                    assert.ok(!err);
                                    assert.ok(user.picture.small);
                                    assert.ok(user.picture.smallUri);
                                    assert.ok(user.picture.medium);
                                    assert.ok(user.picture.mediumUri);
                                    assert.ok(user.picture.large);
                                    assert.ok(user.picture.largeUri);

                                    // The user who owns the pictures can see everything
                                    RestAPI.User.getUser(contexts['simon'].restContext, contexts['simon'].user.id, function(err, user) {
                                        assert.ok(!err);
                                        assert.ok(user.picture.small);
                                        assert.ok(user.picture.smallUri);
                                        assert.ok(user.picture.medium);
                                        assert.ok(user.picture.mediumUri);
                                        assert.ok(user.picture.large);
                                        assert.ok(user.picture.largeUri);
                                        callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
Example #14
0
 createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
         assert.ok(!err);
         verifyCropping(ctx, ctx.user, createSelectedArea('foo', 10, 200), 400, function() {
             verifyCropping(ctx, ctx.user, createSelectedArea(10, 'foo', 200), 400, function() {
                 verifyCropping(ctx, ctx.user, createSelectedArea(10, 10, 'foo'), 400, function() {
                     verifyCropping(ctx, ctx.user, createSelectedArea(10, 10, NaN), 400, callback);
                 });
             });
         });
     });
 });
Example #15
0
        _createUser(function(ctx) {
            // Verify uploading a picture for a user
            RestAPI.User.uploadPicture(ctx, ctx.user.id, _getPictureStream, null, function(err) {
                assert.ok(!err);

                // Verify it for a group
                TestsUtil.generateTestGroups(ctx, 1, function() {
                    var groupId = _.first(arguments).group.id;
                    RestAPI.User.uploadPicture(ctx, groupId, _getPictureStream, null, function(err) {
                        assert.ok(!err);
                        return callback();
                    });
                });
            });
        });
Example #16
0
        createUser(function(ctx) {
            // Verify uploading a picture for a user.
            RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
                assert.ok(!err);

                // Verify it for a group.
                TestsUtil.generateTestGroups(ctx, 1, function(err, groups) {
                    assert.ok(!err);
                    var groupId = _.keys(groups)[0];
                    RestAPI.User.uploadPicture(ctx, groupId, getPictureStream, null, function(err) {
                        assert.ok(!err);
                        callback();
                    });
                });
            });
        });
Example #17
0
        createUser(function(ctx) {
            var selectedArea = createSelectedArea(10, 10, 200, 200);
            RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
                assert.ok(!err);

                // Get my data twice, the url's for the pictures shouldn't change as that would mean they aren't cacheable.
                RestAPI.User.getUser(ctx, ctx.user.id, function(err, firstRequestUser) {
                    assert.ok(!err);
                    RestAPI.User.getUser(ctx, ctx.user.id, function(err, secondRequestUser) {
                        assert.ok(!err);
                        assert.equal(firstRequestUser.smallPicture, secondRequestUser.smallPicture);
                        assert.equal(firstRequestUser.mediumPicture, secondRequestUser.mediumPicture);
                        assert.equal(firstRequestUser.largePicture, secondRequestUser.largePicture);
                        callback();
                    });
                });
            });
        });
Example #18
0
            createUser(function(ctx) {
                var selectedArea = createSelectedArea(10, 10, 200, 200);
                RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
                    assert.ok(!err);

                    // Get the user metadata and thus the picture url.
                    RestAPI.User.getUser(ctx, ctx.user.id, function(err, firstRequestUser) {
                        assert.ok(!err);

                        // Upload a new picture.
                        RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
                            assert.ok(!err);

                            // Get the new user metadata.
                            RestAPI.User.getUser(ctx, ctx.user.id, function(err, secondRequestUser) {
                                assert.ok(!err);

                                // The picture URIs should be different.
                                assert.notEqual(firstRequestUser.smallPicture, secondRequestUser.smallPicture);
                                assert.notEqual(firstRequestUser.mediumPicture, secondRequestUser.mediumPicture);
                                assert.notEqual(firstRequestUser.largePicture, secondRequestUser.largePicture);

                                // Get the URIs and check if they are removed on the filesystem.
                                var smallPicturePath = rootFilesDir + '/' + firstRequestUser.profile.smallPictureUri.split(':')[1];
                                var mediumPicturePath = rootFilesDir + '/' + firstRequestUser.profile.mediumPictureUri.split(':')[1];
                                var largePicturePath = rootFilesDir  + '/'+ firstRequestUser.profile.largePictureUri.split(':')[1];
                                assert.equal(fs.existsSync(smallPicturePath), false, "The small picture has not been removed.");
                                assert.equal(fs.existsSync(mediumPicturePath), false, "The medium picture has not been removed.");
                                assert.equal(fs.existsSync(largePicturePath), false, "The large picture has not been removed.");

                                // To ensure that we didn't get the paths wrong in the test, we'll check if we can find the files for the second request.
                                smallPicturePath = rootFilesDir + '/' + secondRequestUser.profile.smallPictureUri.split(':')[1];
                                mediumPicturePath = rootFilesDir + '/' + secondRequestUser.profile.mediumPictureUri.split(':')[1];
                                largePicturePath = rootFilesDir + '/' + secondRequestUser.profile.largePictureUri.split(':')[1];
                                assert.equal(fs.existsSync(smallPicturePath), true, "The small picture could not be found.");
                                assert.equal(fs.existsSync(mediumPicturePath), true, "The medium picture could not be found.");
                                assert.equal(fs.existsSync(largePicturePath), true, "The large picture could not be found.");

                                callback();
                            });
                        });
                    });
                });
            });
                RestAPI.User.getUser(ctx, ctx.user.id, function(err, firstRequestUser) {
                    assert.ok(!err);

                    // Upload a new picture.
                    RestAPI.User.uploadPicture(ctx, ctx.user.id, _getPictureStream, null, function(err) {
                        assert.ok(!err);

                        // Get the new user metadata.
                        RestAPI.User.getUser(ctx, ctx.user.id, function(err, secondRequestUser) {
                            assert.ok(!err);

                            // Get the URIs and check that they are not removed on the filesystem
                            var smallPicturePath = rootFilesDir + '/' + _getUriFromDownloadUrl(firstRequestUser.picture.small).split(':')[1];
                            var mediumPicturePath = rootFilesDir + '/' + _getUriFromDownloadUrl(firstRequestUser.picture.medium).split(':')[1];
                            assert.equal(fs.existsSync(smallPicturePath), true, 'The small picture should still exist when uploading a large image');
                            assert.equal(fs.existsSync(mediumPicturePath), true, 'The medium picture should still exist when uploading a large image');
                            return callback();
                        });
                    });
                });
Example #20
0
                    RestAPI.User.getUser(ctx, ctx.user.id, function(err, firstRequestUser) {
                        assert.ok(!err);

                        // Upload a new picture.
                        RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
                            assert.ok(!err);

                            // Get the new user metadata.
                            RestAPI.User.getUser(ctx, ctx.user.id, function(err, secondRequestUser) {
                                assert.ok(!err);

                                // Get the URIs and check that they are not removed on the filesystem.
                                var smallPicturePath = rootFilesDir + '/' + firstRequestUser.picture.smallUri.split(':')[1];
                                var mediumPicturePath = rootFilesDir + '/' + firstRequestUser.picture.mediumUri.split(':')[1];
                                assert.equal(fs.existsSync(smallPicturePath), true, "The small picture has been removed.");
                                assert.equal(fs.existsSync(mediumPicturePath), true, "The medium picture has been removed.");

                                callback();
                            });
                        });
                    });
Example #21
0
            createUser(function(ctx) {
                var selectedArea = createSelectedArea(10, 10, 200, 200);
                RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, selectedArea, function(err) {
                    assert.ok(!err);

                    // Download the different sizes.
                    RestAPI.User.downloadPicture(ctx, ctx.user.id, 'small', function(err, body, response) {
                        assert.ok(!err);
                        assert.ok(response.statusCode, 204);
                        RestAPI.User.downloadPicture(ctx, ctx.user.id, 'medium', function(err, body, response) {
                            assert.ok(!err);
                            assert.ok(response.statusCode, 204);
                            RestAPI.User.downloadPicture(ctx, ctx.user.id, 'large', function(err, body, response) {
                                assert.ok(!err);
                                assert.ok(response.statusCode, 204);
                                callback();
                            });
                        });
                    });
                });
            });
Example #22
0
                RestAPI.Group.createGroup(camAdminRestContext, TestsUtil.generateTestGroupId('group'), TestsUtil.generateTestGroupId('group'), 'private', 'no', [], [], function(err, group) {
                    assert.ok(!err);

                    RestAPI.User.uploadPicture(camAdminRestContext, group.id, getPictureStream, sizes, function(err) {
                        assert.ok(!err);

                        RestAPI.Content.createLink(userRestContext, 'Google', 'Google', 'public', 'http://www.google.ca', [], [], function(err, link) {
                            assert.ok(!err);

                            RestAPI.Content.shareContent(camAdminRestContext, link.id, [group.id], function(err) {
                                assert.ok(!err);

                                ActivityTestsUtil.collectAndGetActivityStream(camAdminRestContext, user.id, null, function(err, activityStream) {
                                    assert.ok(!err);

                                    // Verify the target group is scrubbed
                                    var activity = _getActivity(activityStream, 'content-share', 'target', group.id);
                                    assert.ok(activity);

                                    var groupEntity = activity.target;
                                    var resourceId = AuthzUtil.getResourceFromId(group.id).resourceId;
                                    assert.ok(groupEntity.id);
                                    assert.equal(groupEntity['displayName'], group.displayName);
                                    assert.equal(groupEntity['objectType'], 'group');
                                    assert.equal(groupEntity['oae:id'], group.id);
                                    assert.equal(groupEntity['oae:visibility'], group.visibility);
                                    assert.equal(groupEntity['oae:joinable'], group.joinable);
                                    assert.equal(groupEntity['url'], 'http://' + global.oaeTests.tenants.cam.host + '/group/camtest/' + resourceId);
                                    assert.ok(groupEntity['image']);

                                    callback();
                                });
                            });
                        });
                    });
                });
Example #23
0
                RestAPI.Group.createGroup(camAdminRestContext, groupAlias, groupAlias, groupAlias, 'private', 'no', [], [], function(err, group) {
                    assert.ok(!err);

                    RestAPI.User.uploadPicture(camAdminRestContext, group.id, getPictureStream, sizes, function(err) {
                        assert.ok(!err);

                        RestAPI.Content.createLink(userRestContext, 'Google', 'Google', 'public', 'http://www.google.ca', [], [], function(err, link) {
                            assert.ok(!err);

                            RestAPI.Content.shareContent(camAdminRestContext, link.id, [group.id], function(err) {
                                assert.ok(!err);

                                ActivityTestsUtil.collectAndGetActivityStream(camAdminRestContext, user.id, null, function(err, activityStream) {
                                    assert.ok(!err);

                                    // Verify the target group is scrubbed
                                    var activity = _getActivity(activityStream, 'content-share', 'target', group.id);
                                    assert.ok(activity);

                                    var groupEntity = activity.target;
                                    assert.ok(groupEntity.id);
                                    assert.equal(groupEntity.objectType, 'group');
                                    assert.equal(groupEntity['oae:id'], group.id);

                                    assert.ok(!groupEntity['displayName']);
                                    assert.ok(!groupEntity['oae:visibility']);
                                    assert.ok(!groupEntity['url']);
                                    assert.ok(!groupEntity['image']);
                                    assert.ok(!groupEntity['profilePath']);

                                    callback();
                                });
                            });
                        });
                    });
                });
Example #24
0
                    RestAPI.User.createUser(camAdminRestContext, privateUsername, 'password', 'Jane Janerville', {'visibility': 'private', 'publicAlias': 'Jane'}, function(err, privateUser) {
                        assert.ok(!err);
                        var privateUserRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.cam.host, privateUsername, 'password');

                        // Add a profile picture to the private user so we can verify it gets hidden
                        RestAPI.User.uploadPicture(privateUserRestContext, privateUser.id, getPictureStream, sizes, function(err) {
                            assert.ok(!err);

                            // Create a group with the public user
                            RestAPI.Group.createGroup(camAdminRestContext, groupAlias, groupAlias, groupAlias, 'public', 'no', [publicUser.id], [], function(err, group) {
                                assert.ok(!err);

                                // Give the group a profile picture
                                RestAPI.Group.uploadPicture(camAdminRestContext, group.id, getPictureStream, sizes, function(err) {
                                    assert.ok(!err);

                                    // Add the private user
                                    var memberships = {};
                                    memberships[privateUser.id] = 'member';
                                    RestAPI.Group.setGroupMembers(publicUserRestContext, group.id, memberships, function(err) {
                                        assert.ok(!err);

                                        // Verify the public user feed, which will have the add group member activity. It will have the public user as the actor, the private user as the object and the group as the target
                                        ActivityTestsUtil.collectAndGetActivityStream(publicUserRestContext, publicUser.id, null, function(err, activityStream) {
                                            assert.ok(!err);
                                            
                                            var activity = activityStream.items[0];
                                            assert.ok(activity);

                                            var actor = activity.actor;     // Public user
                                            var object = activity.object;   // Private user
                                            var target = activity.target;   // Group
                                            assert.ok(actor);
                                            assert.ok(object);
                                            assert.ok(target);

                                            // Verify the public user model
                                            assert.equal(actor['oae:visibility'], publicUser.visibility);
                                            assert.ok(actor['url'].indexOf(publicUser.id) !== -1);
                                            assert.equal(actor['objectType'], 'user');
                                            assert.ok(actor['id'].indexOf(publicUser.id) !== -1);
                                            assert.equal(actor['oae:id'], publicUser.id);
                                            assert.equal(actor['oae:profilePath'], publicUser.profilePath);
                                            assert.equal(actor['displayName'], publicUser.displayName);
                                            assert.ok(actor['image']);

                                            // Verify the private user model
                                            assert.equal(object['oae:visibility'], privateUser.visibility);
                                            assert.equal(object['objectType'], 'user');
                                            assert.ok(object['id'].indexOf(privateUser.id) !== -1);
                                            assert.equal(object['oae:id'], privateUser.id);
                                            assert.equal(object['oae:profilePath'], undefined);
                                            assert.equal(object['displayName'], privateUser.publicAlias);
                                            assert.equal(object['displayName'], privateUser.publicAlias);

                                            // Url and image are not defined for unprivileged users in feeds
                                            assert.ok(!object['url']);
                                            assert.ok(!object['image']);

                                            // Verify the group model
                                            assert.equal(target['oae:visibility'], group.visibility);
                                            assert.equal(target['displayName'], group.displayName);
                                            assert.ok(target['url'].indexOf(group.id) !== -1);
                                            assert.equal(target['objectType'], 'group');
                                            assert.ok(target['id'].indexOf(group.id) !== -1);
                                            assert.equal(target['oae:id'], group.id);
                                            assert.equal(target['oae:profilePath'], group.profilePath);
                                            assert.ok(target['image']);

                                            callback();
                                        });
                                    });
                                });
                            });
                        });
                    });
 _createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, TestsUtil.createFileReadableStream('pic.png', 10 * 1024 * 1024 + 1), null, function(err) {
         assert.equal(err.code, 400);
         callback();
     });
 });
Example #26
0
                    RestAPI.User.createUser(camAdminRestContext, privateUsername, 'password', 'Jane Janerville', {'visibility': 'private', 'publicAlias': 'Jane'}, function(err, privateUser) {
                        assert.ok(!err);
                        var privateUserRestContext = TestsUtil.createTenantRestContext(global.oaeTests.tenants.cam.host, privateUsername, 'password');

                        // Add a profile picture to the private user so we can verify it gets hidden
                        RestAPI.User.uploadPicture(privateUserRestContext, privateUser.id, getPictureStream, sizes, function(err) {
                            assert.ok(!err);

                            // Create a group
                            RestAPI.Group.createGroup(camAdminRestContext, TestsUtil.generateTestGroupId('group'), TestsUtil.generateTestGroupId('group'), 'public', 'no', [], [], function(err, group) {
                                assert.ok(!err);

                                // Give the group a profile picture
                                RestAPI.Group.uploadPicture(camAdminRestContext, group.id, getPictureStream, sizes, function(err) {
                                    assert.ok(!err);

                                    // Add both the public and private users to the group. They should receive eachother's user entities in the feeds
                                    var permissionChanges = {};
                                    permissionChanges[publicUser.id] = 'manager';
                                    permissionChanges[privateUser.id] = 'manager';
                                    RestAPI.Group.setGroupMembers(camAdminRestContext, group.id, permissionChanges, function(err) {
                                        assert.ok(!err);

                                        // Verify the publicUser and group model in the public user group-add-member activity
                                        ActivityTestsUtil.collectAndGetActivityStream(publicUserRestContext, publicUser.id, null, function(err, activityStream) {
                                            assert.ok(!err);

                                            // Pluck the group-add-member activity from the user's feed
                                            var activity = activityStream.items[0];
                                            assert.ok(activity);

                                            var actor = activity.actor;     // Public user
                                            var object = activity.object;   // Private user
                                            var target = activity.target;   // Group
                                            assert.ok(actor);
                                            assert.ok(object);
                                            assert.ok(target);

                                            assert.equal(object['objectType'], 'collection');
                                            assert.equal(object['oae:collection'].length, 2);

                                            var hadPublicUser = false;
                                            var hadPrivateUser = false;
                                            _.each(object['oae:collection'], function(user) {
                                                var resourceId = AuthzUtil.getResourceFromId(user['oae:id']).resourceId;
                                                if (user['oae:id'] === publicUser.id) {
                                                    hadPublicUser = true;

                                                    // Verify the public user model
                                                    assert.ok(user['id'].indexOf(publicUser.id) !== -1);
                                                    assert.equal(user['displayName'], publicUser.displayName);
                                                    assert.equal(user['objectType'], 'user');
                                                    assert.equal(user['oae:id'], publicUser.id);
                                                    assert.equal(user['oae:profilePath'], publicUser.profilePath);
                                                    assert.equal(user['oae:visibility'], publicUser.visibility);
                                                    assert.equal(user['url'], 'http://' + global.oaeTests.tenants.cam.host + '/user/camtest/' + resourceId);
                                                    assert.ok(user['image']);
                                                } else if (user['oae:id'] === privateUser.id) {
                                                    hadPrivateUser = true;

                                                    // Verify the private user model
                                                    assert.ok(user['id'].indexOf(privateUser.id) !== -1);
                                                    assert.equal(user['displayName'], privateUser.publicAlias);
                                                    assert.equal(user['objectType'], 'user');
                                                    assert.equal(user['oae:id'], privateUser.id);
                                                    assert.equal(user['oae:profilePath'], undefined);
                                                    assert.equal(user['oae:visibility'], privateUser.visibility);

                                                    // Url and image are not defined for unprivileged users in feeds
                                                    assert.ok(!user['url']);
                                                    assert.ok(!user['image']);
                                                }
                                            });

                                            assert.ok(hadPublicUser);
                                            assert.ok(hadPrivateUser);

                                            // Verify the group model
                                            resourceId = AuthzUtil.getResourceFromId(group.id).resourceId;
                                            assert.ok(target['id'].indexOf(group.id) !== -1);
                                            assert.equal(target['displayName'], group.displayName);
                                            assert.equal(target['objectType'], 'group');
                                            assert.equal(target['oae:id'], group.id);
                                            assert.equal(target['oae:profilePath'], group.profilePath);
                                            assert.equal(target['oae:visibility'], group.visibility);
                                            assert.equal(target['url'], 'http://' + global.oaeTests.tenants.cam.host + '/group/camtest/' + resourceId);
                                            assert.ok(target['image']);

                                            callback();
                                        });
                                    });
                                });
                            });
                        });
                    });
Example #27
0
 createUsers(function(contexts) {
     RestAPI.User.uploadPicture(contexts['simon'].restContext, contexts['nicolaas'].user.id, getPictureStream, null, function(err) {
         assert.equal(err.code, 401);
         verifyCropping(contexts['simon'].restContext, contexts['nicolaas'].user, createSelectedArea(10, 10, 200), 401, callback);
     });
 });
Example #28
0
            link => {
              assert.ok(link);

              // Give one of the users a profile picture
              const cropArea = { x: 0, y: 0, width: 50, height: 50 };
              RestAPI.User.uploadPicture(brecke.restContext, brecke.user.id, getPictureStream, cropArea, err => {
                assert.ok(!err);

                // Get the object
                PrincipalsAPI.collectDataToExport(
                  brecke.restContext,
                  brecke.user.id,
                  EXPORT_CONTENT_SCOPE,
                  (err, data) => {
                    assert.ok(!err);

                    // Export data using 'content' export type
                    PrincipalsAPI.exportData(brecke.restContext, brecke.user.id, EXPORT_CONTENT_SCOPE, (err, zip) => {
                      assert.ok(!err);

                      // Verify the personal data on the zip file
                      zip
                        .file('link_data/' + link.displayName + '.txt')
                        .async(TO_STRING)
                        .then(extractedZipData => {
                          const contentChunks = parseExtractedContent(extractedZipData);

                          assert.strictEqual(link.displayName, contentChunks[0]);
                          assert.strictEqual(link.profilePath, contentChunks[1]);
                          assert.strictEqual('http://google.com', contentChunks[2]);
                          assert.strictEqual(link.visibility, contentChunks[3]);
                          assert.strictEqual(link.tenant.displayName, contentChunks[4]);

                          // Verify the collabdoc data on the zip file
                          zip
                            .file('collabdoc_data/' + collabdoc.displayName + '.txt')
                            .async(TO_STRING)
                            .then(extractedZip => {
                              const contentChunks = parseExtractedContent(extractedZip);

                              assert.strictEqual(extractedZip, data.collabdocs[0].text);
                              assert.strictEqual(collabdoc.displayName, contentChunks[0]);
                              assert.strictEqual(collabdoc.profilePath, contentChunks[1]);
                              assert.strictEqual(collabdoc.visibility, contentChunks[2]);
                              assert.strictEqual(collabdoc.tenant.displayName, contentChunks[3]);
                              assert.strictEqual('undefined', contentChunks[4]);

                              // Verify the collabsheet data on the zip file
                              zip
                                .file('collabsheet_data/' + collabsheet.displayName + '.txt')
                                .async(TO_STRING)
                                .then(extractedZip => {
                                  const contentChunks = parseExtractedContent(extractedZip);

                                  assert.strictEqual(extractedZip, data.collabsheets[0].text);
                                  assert.strictEqual(collabsheet.displayName, contentChunks[0]);
                                  assert.strictEqual(collabsheet.profilePath, contentChunks[1]);
                                  assert.strictEqual(collabsheet.visibility, contentChunks[2]);
                                  assert.strictEqual(collabsheet.tenant.displayName, contentChunks[3]);
                                  assert.strictEqual(DEFAULT_SNAPSHOT, contentChunks[4]);

                                  // Verify the personal data on the zip file
                                  zip
                                    .file('large.jpg')
                                    .async('uint8array')
                                    .then(zipPicture => {
                                      assert.ok(zipPicture);

                                      // Compare the object with the zip content
                                      assert.strictEqual(extractedZipData, data.links[0].text);

                                      return callback();
                                    });
                                });
                            });
                        });
                    });
                  }
                );
              });
            }
Example #29
0
 createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, getPictureStream, null, function(err) {
         assert.ok(!err);
         callback();
     });
 });
Example #30
0
 createUser(function(ctx) {
     RestAPI.User.uploadPicture(ctx, ctx.user.id, getTextStream, null, function(err) {
         assert.equal(err.code, 400);
         callback();
     });
 });