Exemple #1
0
    def test_create(self):
        user = self.users.get(id="1")
        role = self.roles.first()

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_create(IgnoreArg(), user.name, user.email, user.password, self.tenant.id, True).AndReturn(user)
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()).AndReturn(role)
        api.add_tenant_user_role(IgnoreArg(), self.tenant.id, user.id, role.id)

        self.mox.ReplayAll()

        formData = {
            "method": "CreateUserForm",
            "name": user.name,
            "email": user.email,
            "password": user.password,
            "tenant_id": self.tenant.id,
            "role_id": self.roles.first().id,
            "confirm_password": user.password,
        }
        res = self.client.post(USER_CREATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)
Exemple #2
0
    def test_create(self):
        user = self.users.get(id="1")
        role = self.roles.first()

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_create(IgnoreArg(), user.name, user.email, user.password,
                        self.tenant.id, True).AndReturn(user)
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()).AndReturn(role)
        api.add_tenant_user_role(IgnoreArg(), self.tenant.id, user.id, role.id)

        self.mox.ReplayAll()

        formData = {
            'method': 'CreateUserForm',
            'name': user.name,
            'email': user.email,
            'password': user.password,
            'tenant_id': self.tenant.id,
            'role_id': self.roles.first().id,
            'confirm_password': user.password
        }
        res = self.client.post(USER_CREATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)
Exemple #3
0
    def test_create_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()) \
                    .AndReturn(self.roles.first())

        self.mox.ReplayAll()

        # check password min-len verification
        formData = {
            'method': 'CreateUserForm',
            'name': user.name,
            'email': user.email,
            'password': '******',
            'tenant_id': self.tenant.id,
            'role_id': self.roles.first().id,
            'confirm_password': '******'
        }

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(res, "form", 'password',
                             ['Password must be between 8 and 18 characters.'])
Exemple #4
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(
            IsA(http.HttpRequest), user.id, email=u"*****@*****.**", name=u"test_user"
        ).AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest), user.id, IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            "method": "UpdateUserForm",
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemple #5
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(),
                        admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest),
                                    user.id,
                                    self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest),
                                 user.id,
                                 IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemple #6
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest), user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id,
                                    self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest), user.id,
                                 IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'password': '******',
            'tenant_id': self.tenant.id,
            'confirm_password': '******'
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemple #7
0
    def test_update_with_keystone_can_edit_user_false(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone_can_edit_user().AndReturn(False)
        api.keystone_can_edit_user().AndReturn(False)
        api.user_update_tenant(IsA(http.HttpRequest), user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id,
                                    self.tenant.id).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'tenant_id': self.tenant.id,
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemple #8
0
    def test_create_user_field_validation(self):
        user = self.users.get(id="1")
        self.mox.StubOutWithMock(api, 'tenant_list')
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        # check password min-len verification
        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_CREATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])

        # check password max-len verification
        formData['password'] = '******'
        formData['confirm_password'] = '******'

        res = self.client.post(USER_CREATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])
Exemple #9
0
    def test_update_with_keystone_can_edit_user_false(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest),
                     '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone_can_edit_user().AndReturn(False)
        api.keystone_can_edit_user().AndReturn(False)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest),
                                    user.id,
                                    self.tenant.id).AndReturn(None)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'tenant_id': self.tenant.id, }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemple #10
0
    def test_create_user(self):
        user = self.users.get(id="1")
        role = self.roles.first()
        self.mox.StubOutWithMock(api, 'user_create')
        self.mox.StubOutWithMock(api, 'tenant_list')
        self.mox.StubOutWithMock(api.keystone, 'get_default_role')
        self.mox.StubOutWithMock(api, 'add_tenant_user_role')
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_create(IgnoreArg(),
                        user.name,
                        user.email,
                        user.password,
                        self.tenant.id,
                        True).AndReturn(user)
        api.keystone.get_default_role(IgnoreArg()).AndReturn(role)
        api.add_tenant_user_role(IgnoreArg(), self.tenant.id, user.id, role.id)
        self.mox.ReplayAll()

        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': user.password,
                    'tenant_id': self.tenant.id,
                    'confirm_password': user.password}
        res = self.client.post(USER_CREATE_URL, formData)
        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)
Exemple #11
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'tenant_list')
        api.tenant_list(IsA(http.HttpRequest)).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, 'syspanel/projects/index.html')
        self.assertItemsEqual(res.context['table'].data, self.tenants.list())
Exemple #12
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'tenant_list')
        api.tenant_list(IsA(http.HttpRequest)).AndReturn(self.tenants)

        self.mox.ReplayAll()

        res = self.client.get(INDEX_URL)

        self.assertTemplateUsed(res, 'syspanel/projects/index.html')
        self.assertItemsEqual(res.context['table'].data, self.tenants)
Exemple #13
0
    def test_create_user_password_mismatch(self):
        user = self.users.get(id="1")
        self.mox.StubOutWithMock(api, 'tenant_list')
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': user.password,
                    'tenant_id': self.tenant.id,
                    'confirm_password': "******"}

        res = self.client.post(USER_CREATE_URL, formData)
        self.assertFormError(res, "form", None, ['Passwords do not match.'])
Exemple #14
0
 def get_data(self):
     tenants = []
     try:
         tenants = api.tenant_list(self.request)
     except api_exceptions.AuthorizationFailure, e:
         LOG.exception("Unauthorized attempt to list tenants.")
         messages.error(self.request, _("Unable to get tenant info: %s") % e.message)
Exemple #15
0
def create(request):
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        messages.error(request, _('Unable to retrieve tenant list: %s') %
                                 e.message)
        return shortcuts.redirect('horizon:syspanel:users:index')
Exemple #16
0
 def __init__(self, request, *args, **kwargs):
     super(DownloadOpenRCForm, self).__init__(*args, **kwargs)
     # Populate tenant choices
     tenant_choices = []
     for tenant in api.tenant_list(request):
         if tenant.enabled:
             tenant_choices.append((tenant.id, tenant.name))
     self.fields["tenant"].choices = tenant_choices
Exemple #17
0
 def get_data(self):
     tenants = []
     try:
         tenants = api.tenant_list(self.request)
     except api_exceptions.AuthorizationFailure, e:
         LOG.exception("Unauthorized attempt to list tenants.")
         messages.error(self.request,
                        _('Unable to get tenant info: %s') % e.message)
Exemple #18
0
 def __init__(self, request, *args, **kwargs):
     super(BaseUserForm, self).__init__(*args, **kwargs)
     # Populate tenant choices
     tenant_choices = [("", "Select a tenant")]
     for tenant in api.tenant_list(request):
         if tenant.enabled:
             tenant_choices.append((tenant.id, tenant.name))
     self.fields["tenant_id"].choices = tenant_choices
 def __init__(self, request, *args, **kwargs):
     super(BaseUserForm, self).__init__(*args, **kwargs)
     # Populate tenant choices
     tenant_choices = [('', _("Select a project"))]
     for tenant in api.tenant_list(request, admin=True):
         if tenant.enabled:
             tenant_choices.append((tenant.id, tenant.name))
     self.fields['tenant_id'].choices = tenant_choices
Exemple #20
0
    def test_user_password_validation(self):
        user = self.users.get(id="1")
        self.mox.StubOutWithMock(api, 'tenant_list')
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': "******"}

        res = self.client.post(USER_CREATE_URL, formData)
        self.assertFormError(
                res, "form", 'password',
                ['Your password must be at least 6 characters long.'])
Exemple #21
0
 def __init__(self, request, *args, **kwargs):
     super(DownloadOpenRCForm, self).__init__(*args, **kwargs)
     # Populate tenant choices
     tenant_choices = []
     for tenant in api.tenant_list(request):
         if tenant.enabled:
             tenant_choices.append((tenant.id, tenant.name))
     self.fields['tenant'].choices = tenant_choices
 def __init__(self, request, *args, **kwargs):
     super(BaseUserForm, self).__init__(*args, **kwargs)
     # Populate tenant choices
     tenant_choices = [('', _("Select a project"))]
     for tenant in api.tenant_list(request, admin=True):
         if tenant.enabled:
             tenant_choices.append((tenant.id, tenant.name))
     self.fields['tenant_id'].choices = tenant_choices
Exemple #23
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserUpdateForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(request,
                             _('Updated %(attrib)s for %(user)s.') %
                             {"attrib": ', '.join(updated), "user": user_id})
            return shortcuts.redirect('horizon:syspanel:users:index')
        else:
            # TODO add better error management
            messages.error(request,
                           _('Unable to update user, please try again.'))

            return shortcuts.render(request,
                                    'syspanel/users/update.html', {
                                        'form': form,
                                        'user_id': user_id})

    else:
        user = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        form = UserUpdateForm(tenant_list=tenants,
                              initial={'id': user_id,
                                       'tenant_id': getattr(user,
                                                            'tenantId',
                                                            None),
                                       'email': getattr(user, 'email', '')})
        return shortcuts.render(request,
                                'syspanel/users/update.html', {
                                    'form': form,
                                    'user_id': user_id})
Exemple #24
0
    def test_create_validation_for_password_too_short(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        # check password min-len verification
        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])
Exemple #25
0
    def test_create_with_password_mismatch(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()) \
                    .AndReturn(self.roles.first())

        self.mox.ReplayAll()

        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': user.password,
                    'tenant_id': self.tenant.id,
                    'role_id': self.roles.first().id,
                    'confirm_password': "******"}

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(res, "form", None, ['Passwords do not match.'])
Exemple #26
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {
            "method": "UpdateUserForm",
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(res, "form", "password", ["Password must be between 8 and 18 characters."])
Exemple #27
0
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
Exemple #28
0
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
Exemple #29
0
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.AuthorizationFailure, e:
        LOG.exception("Unauthorized attempt to list tenants.")
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
Exemple #30
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'password': '******',
            'tenant_id': self.tenant.id,
            'confirm_password': '******'
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(res, "form", 'password',
                             ['Password must be between 8 and 18 characters.'])
Exemple #31
0
    def test_create_with_password_mismatch(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()).AndReturn(self.roles.first())

        self.mox.ReplayAll()

        formData = {
            "method": "CreateUserForm",
            "name": user.name,
            "email": user.email,
            "password": user.password,
            "tenant_id": self.tenant.id,
            "role_id": self.roles.first().id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(res, "form", None, ["Passwords do not match."])
Exemple #32
0
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.AuthorizationFailure, e:
        LOG.exception("Unauthorized attempt to list tenants.")
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
Exemple #33
0
    def test_create_with_password_mismatch(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()) \
                    .AndReturn(self.roles.first())

        self.mox.ReplayAll()

        formData = {
            'method': 'CreateUserForm',
            'name': user.name,
            'email': user.email,
            'password': user.password,
            'tenant_id': self.tenant.id,
            'role_id': self.roles.first().id,
            'confirm_password': "******"
        }

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(res, "form", None, ['Passwords do not match.'])
Exemple #34
0
    def test_create_validation_for_password_too_short(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()).AndReturn(self.roles.first())

        self.mox.ReplayAll()

        # check password min-len verification
        formData = {
            "method": "CreateUserForm",
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "role_id": self.roles.first().id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(res, "form", "password", ["Password must be between 8 and 18 characters."])
Exemple #35
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(),
                        admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(
                res, "form", 'password',
                ['Password must be between 8 and 18 characters.'])
Exemple #36
0
    def test_update_user_field_validation(self):
        user = self.users.get(id="1")
        self.mox.StubOutWithMock(api, 'tenant_list')
        self.mox.StubOutWithMock(api, 'user_get')
        self.mox.StubOutWithMock(api.keystone, 'user_update')
        self.mox.StubOutWithMock(api, 'user_update_tenant')
        self.mox.StubOutWithMock(api, 'user_update_password')

        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 confirm_password=u'normalpwd',
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest),
                               user.id,
                               IgnoreArg()).AndReturn(None)
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()
        user.tenantId = 1

        formData = {'method': 'UpdateUserForm',
                    'id': 1,
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        # check successful update
        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertNoFormErrors(res)

        # check password min-len verification
        formData['password'] = '******'
        formData['confirm_password'] = '******'

        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])

        # check password max-len verification
        formData['password'] = '******'
        formData['confirm_password'] = '******'

        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])
Exemple #37
0
    def test_create_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
        api.keystone.get_default_role(IgnoreArg()) \
                    .AndReturn(self.roles.first())

        self.mox.ReplayAll()

        # check password min-len verification
        formData = {'method': 'CreateUserForm',
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'role_id': self.roles.first().id,
                    'confirm_password': '******'}

        res = self.client.post(USER_CREATE_URL, formData)

        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])