it('verify validation of updating a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                // Ensure valid global admin id
                AdminsTestsUtil.assertUpdateGlobalAdminFails(globalAdminClient, '', 'display name', 400, function() {
                    AdminsTestsUtil.assertUpdateGlobalAdminFails(globalAdminClient, 'not an id', 'display name', 400, function() {
                        AdminsTestsUtil.assertUpdateGlobalAdminFails(globalAdminClient, -1, 'display name', 404, function() {
                            AdminsTestsUtil.assertUpdateGlobalAdminFails(globalAdminClient, ADMIN_ID_NONEXISTENT, 'display name', 404, function() {

                                // Ensure valid display name
                                AdminsTestsUtil.assertUpdateGlobalAdminFails(globalAdminClient, createdGlobalAdmin.id, '', 400, function() {

                                    // Ensure the display name hasn't changed
                                    AdminsTestsUtil.assertGetMe(createdGlobalAdminClient, function(me) {
                                        AdminsTestsUtil.assertMe(me, {'authenticated': createdGlobalAdmin});

                                        // Sanity check we can udpate the display name
                                        AdminsTestsUtil.assertUpdateGlobalAdmin(globalAdminClient, createdGlobalAdmin.id, 'display name', function() {
                                            return callback();
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
        it('verify validation when changing a global administrator\'s password', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                var newPassword = '******';

                // Invalid global administrator id
                AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, 'Not a number', newPassword, globalAdminClient.options.password, 400, function() {
                    // Unknown global administrator id
                    AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, -1, newPassword, globalAdminClient.options.password, 404, function() {
                        AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, 123123123, newPassword, globalAdminClient.options.password, 404, function() {

                            // Missing new password
                            AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, createdGlobalAdmin.id, null, globalAdminClient.options.password, 400, function() {

                                // Too short new password
                                AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, createdGlobalAdmin.id, 's', globalAdminClient.options.password, 400, function() {

                                    // Missing password of the global administrator making the change
                                    AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, createdGlobalAdmin.id, newPassword, null, 400, function() {
                                        return callback();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
 it('verify a global admin can delete their own user account', function(callback) {
     // Create a global admin to try and delete
     var username = TestsUtil.generateTestUserId();
     AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {
         return AdminsTestsUtil.assertDeleteGlobalAdmin(createdGlobalAdminClient, createdGlobalAdmin.id, callback);
     });
 });
        it('verify a global administrator\'s password can be updated', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                AdminsTestsUtil.assertChangePassword(globalAdminClient, createdGlobalAdmin.id, 'a new password', globalAdminClient.options.password, function(newClient) {
                    return callback();
                });
            });
        });
        it('verify a global admin can delete another global admin', function(callback) {
            // Create a global admin user that we can delete
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin) {

                // Delete the global admin, ensuring they no longer exist
                return AdminsTestsUtil.assertDeleteGlobalAdmin(globalAdminClient, createdGlobalAdmin.id, callback);
            });
        });
        it('verify the "me" feed will specify the expected admin\'s profile information', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                // Ensure the Me feed indicates the admin is logged in
                AdminsTestsUtil.assertGetMe(createdGlobalAdminClient, function(me) {
                    AdminsTestsUtil.assertMe(me, {'authenticated': createdGlobalAdmin});
                    return callback();
                });
            });
        });
        it('verify authorization of deleting a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin) {

                // Ensure anonymous cannot delete a global admin
                AdminsTestsUtil.assertDeleteGlobalAdminFails(anonymousGlobalAdminClient, createdGlobalAdmin.id, 401, function() {

                    // Sanity check we can delete the global admin
                    return AdminsTestsUtil.assertDeleteGlobalAdmin(globalAdminClient, createdGlobalAdmin.id, callback);
                });
            });
        });
        it('verify updating a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                // Ensure a global admin can update their own properties, as well as another
                AdminsTestsUtil.assertUpdateGlobalAdmin(globalAdminClient, createdGlobalAdmin.id, 'display name', function() {
                    AdminsTestsUtil.assertUpdateGlobalAdmin(createdGlobalAdminClient, createdGlobalAdmin.id, username, function() {
                        return callback();
                    });
                });
            });
        });
        it('verify authorization of creating a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();

            // Ensure anonymous can't create a global admin
            AdminsTestsUtil.assertCreateGlobalAdminFails(anonymousGlobalAdminClient, username, 'password', 'display name', 401, function(createdGlobalAdmin) {

                // Sanity check global admin can create one
                AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin) {
                    return callback();
                });
            });
        });
        it('verify validation of deleting a global admin', function(callback) {
            // Create a global administrator to sanity check deletes with
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin) {

                AdminsTestsUtil.assertDeleteGlobalAdminFails(globalAdminClient, 'not an id', 400, function() {
                    AdminsTestsUtil.assertDeleteGlobalAdminFails(globalAdminClient, -1, 404, function() {
                        AdminsTestsUtil.assertDeleteGlobalAdminFails(globalAdminClient, ADMIN_ID_NONEXISTENT, 404, function() {

                            // Sanity check we can delete a global admin
                            return AdminsTestsUtil.assertDeleteGlobalAdmin(globalAdminClient, createdGlobalAdmin.id, callback);
                        });
                    });
                });
            });
        });
            AdminsTestsUtil.assertGetMe(globalAdminClient, function(globalAdmin) {
                var username = TestsUtil.generateTestUserId();
                AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin) {
                    // Get all global admins in pages, ensuring each page contains just 1 global
                    // admin, including the initial one and the created one
                    AdminsTestsUtil.assertGetAllGlobalAdmins(globalAdminClient, {'batchSize': 1}, function(allGlobalAdmins, responses) {
                        assert.ok(responses.length > 1);

                        // When fetching with size 1, we'll always have one extra request for the
                        // empty response. So subtract `responses.length` by 1 for the assertion
                        assert.strictEqual(allGlobalAdmins.length, responses.length - 1);
                        AdminsTestsUtil.assertGlobalAdmin(_.findWhere(allGlobalAdmins, {'id': globalAdmin.id}), {'exists': true});
                        AdminsTestsUtil.assertGlobalAdmin(_.findWhere(allGlobalAdmins, {'id': createdGlobalAdmin.id}), {'exists': true});
                        return callback();
                    });
                });
            });
        it('verify authorization of updating a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                // Ensure anonymous user can't update a global admin
                AdminsTestsUtil.assertUpdateGlobalAdminFails(anonymousGlobalAdminClient, createdGlobalAdmin.id, 'display name', 401, function() {

                    // Ensure the created global admin hasn't changed
                    AdminsTestsUtil.assertGetMe(createdGlobalAdminClient, function(me) {
                        AdminsTestsUtil.assertMe(me, {'authenticated': createdGlobalAdmin});

                        // Sanity check we can update the created global admin
                        AdminsTestsUtil.assertUpdateGlobalAdmin(createdGlobalAdminClient, createdGlobalAdmin.id, 'display name', function() {
                            return callback();
                        });
                    });
                });
            });
        });
        it('verify validation of creating a global admin', function(callback) {
            var username = TestsUtil.generateTestUserId();

            // Ensure parameter validation
            AdminsTestsUtil.assertCreateGlobalAdminFails(globalAdminClient, '', 'password', 'display name', 400, function() {
                AdminsTestsUtil.assertCreateGlobalAdminFails(globalAdminClient, username, '', 'display name', 400, function() {
                    AdminsTestsUtil.assertCreateGlobalAdminFails(globalAdminClient, username, '5char', 'display name', 400, function() {
                        AdminsTestsUtil.assertCreateGlobalAdminFails(globalAdminClient, username, 'password', '', 400, function() {

                            // Sanity check creation succeeds
                            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, '6chars', 'display name', function(createdGlobalAdmin) {

                                // Ensure we cannot create an admin with the same username
                                return AdminsTestsUtil.assertCreateGlobalAdminFails(globalAdminClient, username, 'password', 'display name', 400, callback);
                            });
                        });
                    });
                });
            });
        });
        it('verify authorization when changing a global administrator\'s password', function(callback) {
            var username = TestsUtil.generateTestUserId();
            AdminsTestsUtil.assertCreateGlobalAdmin(globalAdminClient, username, 'password', 'display name', function(createdGlobalAdmin, createdGlobalAdminClient) {

                var newPassword = '******';

                // Anonymous users can't change global administrator password
                TestsUtil.getAnonymousAppUserClient(global.tests.apps.cam2014, function(anonymousClient) {
                    AdminsTestsUtil.assertChangePasswordFails(anonymousClient, createdGlobalAdmin.id, newPassword, globalAdminClient.options.password, 404, function() {
                        TestsUtil.getAnonymousGlobalAdminRestClient(function(anonymousGlobalAdminClient) {
                            AdminsTestsUtil.assertChangePasswordFails(anonymousGlobalAdminClient, createdGlobalAdmin.id, newPassword, globalAdminClient.options.password, 401, function() {

                                // Regular users can't change global administrators their password
                                TestsUtil.generateTestUsers(global.tests.apps.cam2013, 1, false, function(simon) {
                                    AdminsTestsUtil.assertChangePasswordFails(simon.client, createdGlobalAdmin.id, newPassword, globalAdminClient.options.password, 404, function() {

                                        // Application administrators can't change global administrators their password
                                        AdminsTestsUtil.assertChangePasswordFails(global.tests.admins.oxford2013.client, createdGlobalAdmin.id, newPassword, globalAdminClient.options.password, 404, function() {

                                            TestsUtil.getGlobalAdminRestClient(function(globalAdminClient) {
                                                // Incorrect password of the global administrator making the change
                                                AdminsTestsUtil.assertChangePasswordFails(globalAdminClient, createdGlobalAdmin.id, newPassword, 'wrong password', 401, function() {
                                                    AdminsTestsUtil.assertChangePassword(globalAdminClient, createdGlobalAdmin.id, newPassword, globalAdminClient.options.password, function() {
                                                        return callback();
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });