修复 AuthKey为空的时候 也可以过.
This commit is contained in:
@@ -9,32 +9,32 @@ type StatusResponse struct {
|
||||
var (
|
||||
CodeOK = &StatusResponse{200, "success"} // 成功
|
||||
CodeApiErr = &StatusResponse{500, "api error"} // API错误
|
||||
CodeSaveErr = &StatusResponse{501, "fail to save"} // 保存失败
|
||||
CodeSaveErr = &StatusResponse{501, "failed to save"} // 保存失败
|
||||
CodeServiceErr = &StatusResponse{510, "server logic error"} // 服务逻辑错误
|
||||
CodeUnAuth = &StatusResponse{401, "unauthorized"} // 未授权
|
||||
|
||||
CodeEmailNotFoundErr = &StatusResponse{5050, "the email was not found"} // 未找到email
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "the user was not found"} // 未找到用户
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 无效密码
|
||||
CodeEmailNotFoundErr = &StatusResponse{5050, "email not found"} // 未找到email
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "user not found"} // 未找到用户
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 无效密码
|
||||
|
||||
CodeSafeValueRangeErr = &StatusResponse{5040, "the value was not in values"} // 值不在范围内
|
||||
CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内
|
||||
|
||||
CodeOrderNotFoundErr = &StatusResponse{5030, "the order not found"} //未找到订单
|
||||
CodeOrderNotCancelledErr = &StatusResponse{5031, "The current order cannot be cancelled"} // 当前订单无法取消
|
||||
CodeOrderNotFoundErr = &StatusResponse{5030, "order not found"} //未找到订单
|
||||
CodeOrderNotCancelledErr = &StatusResponse{5031, "current order cannot be cancelled"} // 当前订单无法取消
|
||||
|
||||
CodePayNotFoundErr = &StatusResponse{5020, "The pay not found"} // 支付信息无法查询
|
||||
CodePayCancelOk = &StatusResponse{5021, "Cancel successfully"} // 支付取消
|
||||
CodePayCancelNotOk = &StatusResponse{5022, "Cancel failure"} // 支付取消
|
||||
CodePayNotFoundErr = &StatusResponse{5020, "pay info not found"} // 支付信息无法查询
|
||||
CodePayCancelOk = &StatusResponse{5021, "cancellation successful"} // 支付取消成功
|
||||
CodePayCancelNotOk = &StatusResponse{5022, "cancellation failed"} // 支付取消失败
|
||||
|
||||
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是访客用户,不需要重复申请
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 访客ID序列化失败
|
||||
CodeGuestDupErr = &StatusResponse{5010, "user is already guest and does not need to reapply"} // 用户已经是访客用户,无需重复申请
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest ID"} // 访客ID序列化失败
|
||||
|
||||
CodeDbUpdateErr = &StatusResponse{5000, "update database error"} // 数据库更新错误
|
||||
// 5001
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // 请求参数无效
|
||||
CodeDbRecordNotFoundErr = &StatusResponse{5003, "db record not found"} //未在数据库中找到记录
|
||||
CodeDbCreateErr = &StatusResponse{5004, "create one in database error"} // 在数据库中创建错误
|
||||
CodeDbSqlErr = &StatusResponse{5005, "database is error"} // 数据库错误
|
||||
CodeDbUpdateErr = &StatusResponse{5000, "database update error"} // 数据库更新错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request parameters"} // 请求参数无效
|
||||
CodeDbRecordNotFoundErr = &StatusResponse{5003, "database record not found"} //数据库中未找到记录
|
||||
CodeDbCreateErr = &StatusResponse{5004, "failed to create record in database"} // 数据库中创建记录失败
|
||||
CodeDbSqlErr = &StatusResponse{5005, "database error"} // 数据库错误
|
||||
CodeJsonErr = &StatusResponse{5006, "JSON error"} // JSON解析错误
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
||||
57
utils/tests/basic.go
Normal file
57
utils/tests/basic.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package fstests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
)
|
||||
|
||||
func GetSesssion() *requests.Session {
|
||||
ses := requests.NewSession()
|
||||
return ses
|
||||
}
|
||||
|
||||
func GetSesssionWithUserToken(t *testing.T, server requests.ITestServer, Host string, Port int) *requests.Session {
|
||||
ses := requests.NewSession()
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/user/login", Host, Port))
|
||||
tp.SetBodyJson(map[string]interface{}{
|
||||
"name": "devenv@sina.cn",
|
||||
"pwd": "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC",
|
||||
})
|
||||
resp, err := tp.TestExecute(server)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
result := resp.Json()
|
||||
code := result.Get("code").Int()
|
||||
if code != 200 {
|
||||
t.Error("code is not 200")
|
||||
}
|
||||
|
||||
token := result.Get("data.token")
|
||||
if !token.Exists() {
|
||||
t.Error("data.token is not exists")
|
||||
}
|
||||
ses.Header.Add("Authorization", token.String())
|
||||
|
||||
return ses
|
||||
}
|
||||
|
||||
func GetSesssionWithGuestToken(t *testing.T, server requests.ITestServer, Host string, Port int) *requests.Session {
|
||||
ses := requests.NewSession()
|
||||
tp := ses.Post(fmt.Sprintf("http://%s:%d/accept/cookie", Host, Port))
|
||||
|
||||
resp, err := tp.TestExecute(server)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
result := resp.Json()
|
||||
token := result.Get("data.token")
|
||||
if !token.Exists() {
|
||||
t.Error("data.token is not exists")
|
||||
}
|
||||
ses.Header.Add("Authorization", token.String())
|
||||
|
||||
return ses
|
||||
}
|
||||
Reference in New Issue
Block a user