Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
 def test_sms_send(self):
     body = {
         "tel": self.tel,
     }
     headers = self.getDefaultHeaders()
     schema = get_ok_schema()
     res = self.http_post(url='/v1/account/user/sms/send',
                          headers=headers,
                          body=body,
                          status=200,
                          schema=schema)
Exemple #6
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)
Exemple #7
0
def get_invite_code_settable_schema(settable=True):
    data_schema = {
        "type": "object",
        "properties": {
            "settable": {"type": "boolean"},
        },
        "required": [ "settable" ]
    }
    enums = {"settable": settable}
    set_schema_enums(data_schema['properties'], enums)
    schema = get_ok_schema(data_schema)
    return schema
Exemple #8
0
def get_check_tel_exist_schema(enums={}):
    data_schema = {
        "type": "object",
        "properties": {
            "exist": {"type": "boolean"},
            "tel": { "type": "string" },
            "userType": {"type": "integer"}
        },
        "required": [ "exist", "tel", "userType" ]
    }
    set_schema_enums(data_schema['properties'], enums)
    schema = get_ok_schema(data_schema)
    return schema
Exemple #9
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)
Exemple #10
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)
Exemple #11
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)
Exemple #12
0
    def test_sms_login_ok(self):
        headers = self.getDefaultHeaders()
        # 发送验证码
        body = {
            "tel": self.tel,
        }
        schema = get_ok_schema()
        res = self.http_post(url='/v1/account/user/sms/send',
                             headers=headers,
                             body=body,
                             status=200,
                             schema=schema)
        # 通过后门接口, 查询验证码.
        args = {
            "bizType": "login",
            "tel": self.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": self.tel,
            "code": code,
        }
        schema = get_user_login_schema()
        res = self.http_post(url='/v1/account/user/sms/login',
                             headers=headers,
                             body=body,
                             status=200,
                             schema=schema)