mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
fix: add ocr auth
This commit is contained in:
@@ -3,6 +3,8 @@ package builtin
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/csv"
|
||||
builtinJSON "encoding/json"
|
||||
@@ -15,6 +17,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -565,3 +568,18 @@ func SplitInteger(m, n int) (ints []int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func sha256HMAC(key []byte, data []byte) []byte {
|
||||
mac := hmac.New(sha256.New, key)
|
||||
mac.Write(data)
|
||||
return []byte(fmt.Sprintf("%x", mac.Sum(nil)))
|
||||
}
|
||||
|
||||
// ver: auth-v1or auth-v2
|
||||
func Sign(ver string, ak string, sk string, body []byte) string {
|
||||
expiration := 1800
|
||||
signKeyInfo := fmt.Sprintf("%s/%s/%d/%d", ver, ak, time.Now().Unix(), expiration)
|
||||
signKey := sha256HMAC([]byte(sk), []byte(signKeyInfo))
|
||||
signResult := sha256HMAC(signKey, body)
|
||||
return fmt.Sprintf("%v/%v", signKeyInfo, string(signResult))
|
||||
}
|
||||
|
||||
2
hrp/internal/env/env.go
vendored
2
hrp/internal/env/env.go
vendored
@@ -5,6 +5,8 @@ import "os"
|
||||
var (
|
||||
WDA_USB_DRIVER = os.Getenv("WDA_USB_DRIVER")
|
||||
VEDEM_OCR_URL = os.Getenv("VEDEM_OCR_URL")
|
||||
VEDEM_OCR_AK = os.Getenv("VEDEM_OCR_AK")
|
||||
VEDEM_OCR_SK = os.Getenv("VEDEM_OCR_SK")
|
||||
DISABLE_GA = os.Getenv("DISABLE_GA")
|
||||
DISABLE_SENTRY = os.Getenv("DISABLE_SENTRY")
|
||||
PYPI_INDEX_URL = os.Getenv("PYPI_INDEX_URL")
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||
)
|
||||
@@ -64,6 +65,9 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
|
||||
return nil, fmt.Errorf("construct request error: %v", err)
|
||||
}
|
||||
|
||||
token := builtin.Sign("auth-v2", env.VEDEM_OCR_AK, env.VEDEM_OCR_SK, bodyBuf.Bytes())
|
||||
|
||||
req.Header.Add("Agw-Auth", token)
|
||||
req.Header.Add("Content-Type", bodyWriter.FormDataContentType())
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -575,7 +575,6 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
|
||||
// init wda/uia driver
|
||||
uiDriver, err := s.hrpRunner.initUIClient(mobileStep.Serial, osType)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user