mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-29 04:01:24 +00:00
* add create oauth/ldap/saml user in UserManager * improve admin add/import users * improve dingtalk/weixin/work_weixin login/create user * improve saml login/create user * improve oauth login/create user * login ldap user in seahub * improve invite user * fix code * fix github test action * fix test * fix saml login * optimize code * specify the version of python-ldap * fix code * improve code * add get_old_user * optimize oauth login code * optimize code * remove LDAP_USER_UNIQUE_ID * remove test_primary_id * improve authenticate user * improve saml login * optimize code
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import json
|
|
|
|
from django.urls import reverse
|
|
import pytest
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE,
|
|
VAL_FORCE_PASSWD_CHANGE)
|
|
from seahub.test_utils import BaseTestCase
|
|
|
|
|
|
class UserAddTest(BaseTestCase):
|
|
def setUp(self):
|
|
self.clear_cache()
|
|
from constance import config
|
|
self.config = config
|
|
|
|
self.new_user = 'new_user@test.com'
|
|
self.login_as(self.admin)
|
|
self.remove_user(self.new_user)
|
|
|
|
def test_can_add_when_pwd_change_required(self):
|
|
self.config.FORCE_PASSWORD_CHANGE = 1
|
|
|
|
assert len(UserOptions.objects.filter(
|
|
email=self.new_user, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0
|
|
|
|
resp = self.client.post(
|
|
reverse('api-v2.1-admin-users',), {
|
|
'email': self.new_user,
|
|
'password': '123',
|
|
}
|
|
)
|
|
|
|
self.assertEqual(200, resp.status_code)
|
|
json_resp = json.loads(resp.content)
|
|
assert UserOptions.objects.get(
|
|
email=json_resp['email'],
|
|
option_key=KEY_FORCE_PASSWD_CHANGE).option_val == VAL_FORCE_PASSWD_CHANGE
|
|
|
|
def test_can_add_when_pwd_change_not_required(self):
|
|
self.config.FORCE_PASSWORD_CHANGE = 0
|
|
|
|
assert len(UserOptions.objects.filter(
|
|
email=self.new_user, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0
|
|
|
|
resp = self.client.post(
|
|
reverse('api-v2.1-admin-users',), {
|
|
'email': self.new_user,
|
|
'password': '123',
|
|
}
|
|
)
|
|
|
|
self.assertEqual(200, resp.status_code)
|
|
json_resp = json.loads(resp.content)
|
|
assert len(UserOptions.objects.filter(
|
|
email=json_resp['email'], option_key=KEY_FORCE_PASSWD_CHANGE)) == 0
|