123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- package realname
- import (
- "context"
- "flag"
- "io/ioutil"
- "os"
- "testing"
- "go-common/app/interface/main/account/conf"
- "go-common/app/interface/main/account/model"
- . "github.com/smartystreets/goconvey/convey"
- )
- var (
- s *Service
- ctx = context.Background()
- rsaPub, rsaPriv = ``, ``
- alipayPub = ``
- alipayOwnPriv = ``
- )
- func TestMain(m *testing.M) {
- var err error
- flag.Set("conf", "../../cmd/account-interface-example.toml")
- if err = conf.Init(); err != nil {
- panic(err)
- }
- s = New(conf.Conf, rsaPub, rsaPriv, alipayPub, alipayOwnPriv)
- m.Run()
- os.Exit(0)
- }
- func TestEncrypt(t *testing.T) {
- var (
- raw []byte
- err error
- )
- if raw, err = ioutil.ReadFile("./test.jpg"); err != nil {
- panic(err)
- }
- Convey("encrypt", t, func() {
- var (
- encrpted []byte
- outputs []byte
- )
- if encrpted, err = s.mainCryptor.IMGEncrypt(raw); err != nil {
- panic(err)
- }
- if err = ioutil.WriteFile("./encrypted", encrpted, os.ModePerm); err != nil {
- panic(err)
- }
- if outputs, err = s.mainCryptor.IMGDecrypt(encrpted); err != nil {
- panic(err)
- }
- if err = ioutil.WriteFile("./output.jpg", outputs, os.ModePerm); err != nil {
- panic(err)
- }
- })
- }
- func TestRealname(t *testing.T) {
- Convey("realname", t, func() {
- var (
- mid int64
- err error
- )
- _, err = s.TelInfo(ctx, mid)
- So(err, ShouldBeNil)
- err = s.TelCapture(ctx, mid)
- So(err, ShouldBeNil)
- s.CountryList(ctx)
- s.CardTypes(ctx, "pc", "", "", 1234)
- })
- }
- func TestRealnameMask(t *testing.T) {
- Convey("realname mask", t, func() {
- var (
- realname1 = ""
- realname2 = "托"
- realname3 = "托米"
- realname4 = "托了一地的米"
- card1 = ""
- card2 = "t"
- card3 = "tom"
- card4 = "tommmmmy233"
- )
- r, c := maskRealnameInfo(realname1, card1)
- So(r, ShouldEqual, "")
- So(c, ShouldEqual, "")
- r, c = maskRealnameInfo(realname2, card2)
- So(r, ShouldEqual, "*")
- So(c, ShouldEqual, "*")
- r, c = maskRealnameInfo(realname3, card3)
- So(r, ShouldEqual, "*米")
- So(c, ShouldEqual, "t**")
- r, c = maskRealnameInfo(realname4, card4)
- So(r, ShouldEqual, "*了一地的米")
- So(c, ShouldEqual, "t********33")
- })
- }
- func TestAlipay(t *testing.T) {
- Convey("alipay", t, func() {
- // bizno, err := s.alipayInit(context.Background(), "沐阳", "340702199110120011")
- // So(err, ShouldBeNil)
- // t.Log(bizno)
- // url, err := s.alipayCertifyURL(context.Background(), conf.Conf.Realname.Alipay.AppID, bizno)
- // So(err, ShouldBeNil)
- // t.Log(url)
- bizno := "ZM201808153000000757500643766753"
- pass, reason, err := s.alipayQuery(context.Background(), bizno)
- So(err, ShouldBeNil)
- t.Log(pass, reason)
- })
- }
- func TestGeetest(t *testing.T) {
- Convey("gt", t, func() {
- var (
- mid int64 = 111001723
- )
- // urlStr, err := s.CaptchaGTRegister(ctx, mid, "127.0.0.1", "h5")
- // So(err, ShouldBeNil)
- // t.Log(urlStr)
- // challenge, gt, success, err := s.CaptchaGTRefresh(ctx, mid, "127.0.0.1", "h5", "fake hash")
- // So(err, ShouldBeNil)
- // t.Log(challenge, gt, success)
- var (
- validateArg = &model.ParamRealnameCaptchaGTCheck{
- Remote: 1,
- Challenge: "58fb29d758ef977717b8fd98d5d1371b9c",
- Validate: "6171ad7e1243a50c8ca9b124cb6ae411",
- Seccode: "6171ad7e1243a50c8ca9b124cb6ae411|jordan",
- }
- )
- res, err := s.CaptchaGTValidate(ctx, mid, "127.0.0.1", "h5", validateArg)
- So(err, ShouldBeNil)
- t.Log(res)
- })
- }
- func BenchmarkEncrypt(b *testing.B) {
- var (
- err error
- raw []byte
- )
- if raw, err = ioutil.ReadFile("./test.jpg"); err != nil {
- panic(err)
- }
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- if _, err = s.mainCryptor.IMGEncrypt(raw); err != nil {
- panic(err)
- }
- }
- })
- }
- func BenchmarkDecrypt(b *testing.B) {
- var (
- err error
- raw []byte
- )
- if raw, err = ioutil.ReadFile("./encrypted"); err != nil {
- panic(err)
- }
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- if _, err = s.mainCryptor.IMGDecrypt(raw); err != nil {
- panic(err)
- }
- }
- })
- }
|