realname_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package realname
  2. import (
  3. "context"
  4. "flag"
  5. "io/ioutil"
  6. "os"
  7. "testing"
  8. "go-common/app/interface/main/account/conf"
  9. "go-common/app/interface/main/account/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. s *Service
  14. ctx = context.Background()
  15. rsaPub, rsaPriv = ``, ``
  16. alipayPub = ``
  17. alipayOwnPriv = ``
  18. )
  19. func TestMain(m *testing.M) {
  20. var err error
  21. flag.Set("conf", "../../cmd/account-interface-example.toml")
  22. if err = conf.Init(); err != nil {
  23. panic(err)
  24. }
  25. s = New(conf.Conf, rsaPub, rsaPriv, alipayPub, alipayOwnPriv)
  26. m.Run()
  27. os.Exit(0)
  28. }
  29. func TestEncrypt(t *testing.T) {
  30. var (
  31. raw []byte
  32. err error
  33. )
  34. if raw, err = ioutil.ReadFile("./test.jpg"); err != nil {
  35. panic(err)
  36. }
  37. Convey("encrypt", t, func() {
  38. var (
  39. encrpted []byte
  40. outputs []byte
  41. )
  42. if encrpted, err = s.mainCryptor.IMGEncrypt(raw); err != nil {
  43. panic(err)
  44. }
  45. if err = ioutil.WriteFile("./encrypted", encrpted, os.ModePerm); err != nil {
  46. panic(err)
  47. }
  48. if outputs, err = s.mainCryptor.IMGDecrypt(encrpted); err != nil {
  49. panic(err)
  50. }
  51. if err = ioutil.WriteFile("./output.jpg", outputs, os.ModePerm); err != nil {
  52. panic(err)
  53. }
  54. })
  55. }
  56. func TestRealname(t *testing.T) {
  57. Convey("realname", t, func() {
  58. var (
  59. mid int64
  60. err error
  61. )
  62. _, err = s.TelInfo(ctx, mid)
  63. So(err, ShouldBeNil)
  64. err = s.TelCapture(ctx, mid)
  65. So(err, ShouldBeNil)
  66. s.CountryList(ctx)
  67. s.CardTypes(ctx, "pc", "", "", 1234)
  68. })
  69. }
  70. func TestRealnameMask(t *testing.T) {
  71. Convey("realname mask", t, func() {
  72. var (
  73. realname1 = ""
  74. realname2 = "托"
  75. realname3 = "托米"
  76. realname4 = "托了一地的米"
  77. card1 = ""
  78. card2 = "t"
  79. card3 = "tom"
  80. card4 = "tommmmmy233"
  81. )
  82. r, c := maskRealnameInfo(realname1, card1)
  83. So(r, ShouldEqual, "")
  84. So(c, ShouldEqual, "")
  85. r, c = maskRealnameInfo(realname2, card2)
  86. So(r, ShouldEqual, "*")
  87. So(c, ShouldEqual, "*")
  88. r, c = maskRealnameInfo(realname3, card3)
  89. So(r, ShouldEqual, "*米")
  90. So(c, ShouldEqual, "t**")
  91. r, c = maskRealnameInfo(realname4, card4)
  92. So(r, ShouldEqual, "*了一地的米")
  93. So(c, ShouldEqual, "t********33")
  94. })
  95. }
  96. func TestAlipay(t *testing.T) {
  97. Convey("alipay", t, func() {
  98. // bizno, err := s.alipayInit(context.Background(), "沐阳", "340702199110120011")
  99. // So(err, ShouldBeNil)
  100. // t.Log(bizno)
  101. // url, err := s.alipayCertifyURL(context.Background(), conf.Conf.Realname.Alipay.AppID, bizno)
  102. // So(err, ShouldBeNil)
  103. // t.Log(url)
  104. bizno := "ZM201808153000000757500643766753"
  105. pass, reason, err := s.alipayQuery(context.Background(), bizno)
  106. So(err, ShouldBeNil)
  107. t.Log(pass, reason)
  108. })
  109. }
  110. func TestGeetest(t *testing.T) {
  111. Convey("gt", t, func() {
  112. var (
  113. mid int64 = 111001723
  114. )
  115. // urlStr, err := s.CaptchaGTRegister(ctx, mid, "127.0.0.1", "h5")
  116. // So(err, ShouldBeNil)
  117. // t.Log(urlStr)
  118. // challenge, gt, success, err := s.CaptchaGTRefresh(ctx, mid, "127.0.0.1", "h5", "fake hash")
  119. // So(err, ShouldBeNil)
  120. // t.Log(challenge, gt, success)
  121. var (
  122. validateArg = &model.ParamRealnameCaptchaGTCheck{
  123. Remote: 1,
  124. Challenge: "58fb29d758ef977717b8fd98d5d1371b9c",
  125. Validate: "6171ad7e1243a50c8ca9b124cb6ae411",
  126. Seccode: "6171ad7e1243a50c8ca9b124cb6ae411|jordan",
  127. }
  128. )
  129. res, err := s.CaptchaGTValidate(ctx, mid, "127.0.0.1", "h5", validateArg)
  130. So(err, ShouldBeNil)
  131. t.Log(res)
  132. })
  133. }
  134. func BenchmarkEncrypt(b *testing.B) {
  135. var (
  136. err error
  137. raw []byte
  138. )
  139. if raw, err = ioutil.ReadFile("./test.jpg"); err != nil {
  140. panic(err)
  141. }
  142. b.RunParallel(func(pb *testing.PB) {
  143. for pb.Next() {
  144. if _, err = s.mainCryptor.IMGEncrypt(raw); err != nil {
  145. panic(err)
  146. }
  147. }
  148. })
  149. }
  150. func BenchmarkDecrypt(b *testing.B) {
  151. var (
  152. err error
  153. raw []byte
  154. )
  155. if raw, err = ioutil.ReadFile("./encrypted"); err != nil {
  156. panic(err)
  157. }
  158. b.RunParallel(func(pb *testing.PB) {
  159. for pb.Next() {
  160. if _, err = s.mainCryptor.IMGDecrypt(raw); err != nil {
  161. panic(err)
  162. }
  163. }
  164. })
  165. }