rsa_utils_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package test
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_ht_api/common/utils/auth"
  5. "eta/eta_mini_ht_api/controllers/web_hook"
  6. "testing"
  7. "time"
  8. )
  9. func TestEncryptWithRSA(t *testing.T) {
  10. type args struct {
  11. data interface{}
  12. }
  13. tests := []struct {
  14. name string
  15. args args
  16. }{
  17. {
  18. name: "test",
  19. args: args{
  20. data: web_hook.AccountOpenInfoReq{
  21. MobileTel: "18267183251",
  22. //DealMobileTel string `json:"deal_mobile_tel"`
  23. ClientName: "陈晗",
  24. IdKind: 1,
  25. IdNo: "330501199101080013",
  26. AccountStatus: "failed",
  27. //ErrorCode int `json:"error_code"`
  28. IdBeginDate: "2021-03-10",
  29. IdEndDate: "2029-03-10",
  30. ErrorMessage: "不合法的开户请求",
  31. Timestamp: time.Now().Unix(),
  32. },
  33. },
  34. },
  35. }
  36. for _, tt := range tests {
  37. t.Run(tt.name, func(t *testing.T) {
  38. pk, _ := auth.ParsePublicKeyFromPEM()
  39. bytes, _ := json.Marshal(tt.args.data)
  40. entry, _ := auth.EncryptWithRSA(pk, bytes)
  41. //fmt.Println(string(entry))
  42. got, _ := auth.EncryptWithRSA(pk, entry)
  43. t.Errorf("EncryptWithRSA() got = %v, ", got)
  44. //if (err != nil) != tt.wantErr {
  45. // t.Errorf("EncryptWithRSA() error = %v, wantErr %v", err, tt.wantErr)
  46. // return
  47. //}
  48. //if !reflect.DeepEqual(got, tt.want) {
  49. // t.Errorf("EncryptWithRSA() got = %v, want %v", got, tt.want)
  50. //}
  51. //fmt.Println(got)
  52. })
  53. }
  54. }