Esempio n. 1
0
    def test_user_manager_lock_user(self):
        tel = random_tel()
        username = random_username()
        password = self.encodePassword("password")
        token, userInfo = self.userRegister(tel, username, password=password)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        # 后台注销注册用户
        UserStatusDisabled = -1
        body = {
            "id": userInfo['id'],
            "status": UserStatusDisabled,
        }
        schema = get_ok_schema()
        res = self.http_put(url="/v1/man/account/user/status", headers=self.getAdminHeaders(), body=body, status=200, schema=schema)

        # 需要token的操作, 提示用户被锁定
        schema = get_fail_schema('ERR_USER_IS_LOCKED')
        res = self.http_get(url='/v1/account/user/userinfo', headers=headers, status=200, schema=schema)

        # 重新登录,提示用户被锁定
        body = {
            "tel": tel,
            "password": password,
        }
        schema = get_fail_schema('ERR_USER_IS_LOCKED')
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
        # print(res.req_debug)
Esempio n. 2
0
    def test_user_manager_reset_pwd_success(self):
        tel = random_tel()
        username = random_username()
        oldPassword = self.encodePassword("old-password")
        newPassword = self.encodePassword("new-password")
        token, _ = self.userRegister(tel, username, password=oldPassword)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        # 后台重置密码
        body = {
            "tel": tel,
            "password": newPassword,
        }
        schema = get_ok_schema()
        res = self.http_put(url="/v1/man/account/user/password/reset", headers=self.getAdminHeaders(), body=body, status=200, schema=schema)

        # 使用旧密码登录失败
        body = {
            "tel": tel,
            "password": oldPassword,
        }
        schema = get_fail_schema('ERR_PASSWORD_ERR')
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)

        # 使用新密码登录成功
        body = {
            "tel": tel,
            "password": newPassword,
        }
        schema = get_user_login_schema(enums={})
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
Esempio n. 3
0
    def test_user_reset_pwd_failed_tel_not_exist(self):
        tel = random_tel()
        username = random_username()
        headers = self.getDefaultHeaders()
        oldPassword = self.encodePassword("old-password")
        newPassword = self.encodePassword("new-password")

        # 发送验证码
        body = {
            "tel": tel,
            "bizType": "resetPwd",
        }
        schema = get_ok_schema()
        res = self.http_post(url='/v1/account/user/sms/send', headers=headers, body=body, status=200, schema=schema)

        # 通过后门接口, 查询验证码.
        args = {
            "bizType": "resetPwd",
            "tel": tel,
            "key": AccountTest.SUPER_KEY
        }
        schema = get_sms_code_schema()
        res = self.http_get(url='/v1/man/account/sms/get/code', headers=headers, args=args, status=200, schema=schema)
        code = res.json["data"]["code"]

        # 重置密码, 手机号不存在
        body = {
            "tel": tel,
            "code": code,
            "password": newPassword,
        }
        schema = get_fail_schema('ERR_TEL_NOT_EXIST')
        res = self.http_put(url="/v1/account/user/password/reset", headers=headers, body=body, status=200, schema=schema)
Esempio n. 4
0
    def test_user_register_login_success(self):
        tel = random_tel()
        username = random_username()
        headers = self.getDefaultHeaders()
        password = self.encodePassword("password")
        self.userRegister(tel, username, password=password)


        schema = get_fail_schema('ERR_ARGS_INVALID')
        body = {
            "password": password,
        }
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=400, schema=schema)

        # 手机号登录
        schema = get_user_login_schema()
        body = {
            "tel": tel,
            "password": password,
        }
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
        # 用户名登录
        body = {
            "username": username,
            "password": password,
        }
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
Esempio n. 5
0
    def test_user_set_invite_code(self):
        tel = random_tel()
        username = random_username()
        inv_tel = random_tel()
        inv_username = random_username()

        oldPassword = self.encodePassword("old-password")
        newPassword = self.encodePassword("new-password")
        # 邀请的用户
        token1, userInfo = self.userRegister(inv_tel, inv_username)
        inviteCode = userInfo["inviteCode"]
        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token1
        # 设置自己的邀请码
        body = { "inviteCode": inviteCode }
        schema = get_fail_schema('ERR_INVITE_CODE_INVALID')
        res = self.http_put(url="/v1/account/user/invite_code", headers=headers, body=body, status=200, schema=schema)

        # 被邀请的用户
        token2, _ = self.userRegister(tel, username, password=oldPassword)
        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token2

        # 检查是否可设置邀请码
        schema = get_invite_code_settable_schema(True)
        self.http_get(url="/v1/account/user/invite_code/settable", headers=headers, status=200, schema=schema)

        # 设置不存在的邀请码
        body = { "inviteCode": 'not-exist-invite-code' }
        schema = get_fail_schema('ERR_INVITE_CODE_INVALID')
        res = self.http_put(url="/v1/account/user/invite_code", headers=headers, body=body, status=200, schema=schema)

        # 设置成功
        body = { "inviteCode": inviteCode}
        schema = get_ok_schema()
        res = self.http_put(url="/v1/account/user/invite_code", headers=headers, body=body, status=200, schema=schema)

        # 重复设置成功
        body = { "inviteCode": inviteCode}
        schema = get_ok_schema()
        res = self.http_put(url="/v1/account/user/invite_code", headers=headers, body=body, status=200, schema=schema)
Esempio n. 6
0
 def test_sms_login_failed_code_invalid(self):
     headers = self.getDefaultHeaders()
     body = {
         "tel": self.tel,
         "code": "000000",
     }
     schema = get_fail_schema('ERR_CODE_INVALID')
     res = self.http_post(url='/v1/account/user/sms/login',
                          headers=headers,
                          body=body,
                          status=200,
                          schema=schema)
Esempio n. 7
0
    def test_user_reset_pwd_success(self):
        tel = random_tel()
        username = random_username()
        oldPassword = self.encodePassword("old-password")
        newPassword = self.encodePassword("new-password")
        token, _ = self.userRegister(tel, username, password=oldPassword)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        # 发送验证码
        body = {
            "tel": tel,
            "bizType": "resetPwd",
        }
        schema = get_ok_schema()
        res = self.http_post(url='/v1/account/user/sms/send', headers=headers, body=body, status=200, schema=schema)

        # 通过后门接口, 查询验证码.
        args = {
            "bizType": "resetPwd",
            "tel": tel,
            "key": AccountTest.SUPER_KEY
        }
        schema = get_sms_code_schema()
        res = self.http_get(url='/v1/man/account/sms/get/code', headers=headers, args=args, status=200, schema=schema)
        code = res.json["data"]["code"]

        # 重置密码
        body = {
            "tel": tel,
            "code": code,
            "password": newPassword,
        }
        schema = get_ok_schema()
        res = self.http_put(url="/v1/account/user/password/reset", headers=headers, body=body, status=200, schema=schema)

        # 使用旧密码登录失败
        body = {
            "tel": tel,
            "password": oldPassword,
        }
        schema = get_fail_schema('ERR_PASSWORD_ERR')
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)

        # 使用新密码登录成功
        body = {
            "tel": tel,
            "password": newPassword,
        }
        schema = get_user_login_schema(enums={})
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
Esempio n. 8
0
    def test_user_register_empty_password(self):
        tel = random_tel()
        username = random_username()
        headers = self.getDefaultHeaders()
        emptyPassword = self.encodePassword("empty-password")
        self.userRegister(tel, username)

        body = {
            "tel": tel,
            "password": emptyPassword,
        }
        schema = get_fail_schema('ERR_PASSWORD_ERR')
        res = self.http_post(url="/v1/account/user/login", headers=headers, body=body, status=200, schema=schema)
Esempio n. 9
0
    def test_user_register_failed_username_duplicate(self):
        headers = self.getDefaultHeaders()
        username = random_username()
        self.userRegister(random_tel(),username)

        body = {
            "tel": random_tel(),
            "code": self.SUPER_TEST_CODE,
            "username": username,
            "userType": 1,
        }
        schema = get_fail_schema('ERR_USERNAME_REGISTED')
        res = self.http_post(url='/v1/account/user/register', headers=headers, body=body, status=200, schema=schema)
Esempio n. 10
0
    def test_user_logout(self):
        tel = random_tel()
        username = random_username()
        token, _ = self.userRegister(tel, username)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token
        schema = get_ok_schema()
        body = {}
        res = self.http_post(url='/v1/account/user/logout', headers=headers, body=body, status=200, schema=schema)

        # 第二次logout失败.
        schema = get_fail_schema('ERR_TOKEN_EXPIRED')
        res = self.http_post(url='/v1/account/user/logout', headers=headers, body=body, status=401, schema=schema)
Esempio n. 11
0
    def test_user_set_username(self):
        tel = random_tel()
        token, _ = self.userRegister(tel, "")
        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        # 设置用户名
        username = random_username()
        body = { "username": username}
        schema = get_ok_schema()
        self.http_put(url="/v1/account/user/username", headers=headers, body=body, status=200, schema=schema)

        # 再次用户名,出错
        schema = get_fail_schema('ERR_USER_HAVE_USERNAME')
        self.http_put(url="/v1/account/user/username", headers=headers, body=body, status=200, schema=schema)
Esempio n. 12
0
    def test_user_manager_deregister(self):
        tel = random_tel()
        username = random_username()
        password = self.encodePassword("password")
        token, userInfo = self.userRegister(tel, username, password=password)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        # 后台注销注册用户
        body = {
            "id": userInfo['id']
        }
        schema = get_ok_schema()
        res = self.http_delete(url="/v1/man/account/user/deregister", headers=self.getAdminHeaders(), body=body, status=200, schema=schema)

        schema = get_fail_schema('ERR_TOKEN_EXPIRED')
        res = self.http_get(url='/v1/account/user/userinfo', headers=headers, status=401, schema=schema)
Esempio n. 13
0
    def test_user_change_pwd_failed_old_pwd_error(self):
        tel = random_tel()
        username = random_username()
        oldPassword = self.encodePassword("old-password")
        newPassword = self.encodePassword("new-password")
        errPassword = self.encodePassword("err-password")

        token, _ = self.userRegister(tel, username, password=oldPassword)

        headers = self.getDefaultHeaders()
        headers[CH("Token")] = token

        body = {
            "oldPassword": errPassword,
            "password": newPassword,
        }
        schema = get_fail_schema('ERR_PASSWORD_ERR')
        res = self.http_put(url="/v1/account/user/password", headers=headers, body=body, status=200, schema=schema)
Esempio n. 14
0
 def test_user_get_userinfo_failed_token_invlid(self):
     headers = self.getDefaultHeaders()
     headers[CH("Token")] = "TOKEN-INVALID"
     schema = get_fail_schema('ERR_TOKEN_INVALID')
     res = self.http_get(url='/v1/account/user/userinfo', headers=headers, status=401, schema=schema)
Esempio n. 15
0
 def test_user_get_userinfo_failed_token_missing(self):
     headers = self.getDefaultHeaders()
     schema = get_fail_schema('ERR_TOKEN_INVALID')
     res = self.http_get(url='/v1/account/user/userinfo', headers=headers, status=401, schema=schema)