补充插件通信审查证据与覆盖记录
This commit is contained in:
1 parent
8e50cc6081
commit
9849f8f11c
30 files changed
+3899
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package http_server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/config"
|
||||
"git.pcux.cn/xuans/Smail/dto/response"
|
||||
"git.pcux.cn/xuans/Smail/session"
|
||||
"github.com/alexedwards/scs/v2"
|
||||
)
|
||||
|
||||
// 审查专用:使用内存会话和真实路由,不发送验证码。
|
||||
func TestAuditAnonymousLoginResendMustReachController(t *testing.T) {
|
||||
previousConfig, previousInit := config.Instance, config.IsInit
|
||||
previousSession, previousManager := session.Instance, config.CurrentManager()
|
||||
t.Cleanup(func() {
|
||||
config.Instance = previousConfig
|
||||
config.SetInitState(previousInit)
|
||||
session.Instance = previousSession
|
||||
config.SetRuntimeManager(previousManager)
|
||||
})
|
||||
config.SetRuntimeManager(nil)
|
||||
config.Instance = &config.Config{Domain: "localhost"}
|
||||
config.SetInitState(true)
|
||||
session.Instance = scs.New()
|
||||
mux := http.NewServeMux()
|
||||
registerV1Routes(mux)
|
||||
request := httptest.NewRequest(http.MethodPost, "https://localhost/api/v1/security/login/resend", strings.NewReader(`{"id":"audit-invalid","account":"audit"}`))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
recorder := httptest.NewRecorder()
|
||||
session.Instance.LoadAndSave(mux).ServeHTTP(recorder, request)
|
||||
var result response.Response
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("HTTP=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
if result.ErrorNo == response.NeedLogin {
|
||||
t.Fatal("尚未完成二次验证的用户无法调用验证码重发接口")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user