user_service_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package service
  2. import (
  3. "crypto/sha1"
  4. "encoding/hex"
  5. "fmt"
  6. "testing"
  7. "xiaoniaokuaiyan.com/xiaoniao/entity"
  8. "xiaoniaokuaiyan.com/xiaoniao/util"
  9. )
  10. func TestLogin(t *testing.T) {
  11. m := "18310592480"
  12. if !util.IsMobile(m) {
  13. t.Fatal("")
  14. }
  15. return
  16. var (
  17. mobile string = "18310412108"
  18. password string = "7c4a8d09ca3762af61e59520943dc26494f8941b"
  19. )
  20. user, err := userService.Login(map[string]string{
  21. "mobile": mobile,
  22. "password": password,
  23. })
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. t.Log(user)
  28. }
  29. func TestUpdateUinfo(t *testing.T) {
  30. data, err := userService.UpdateUserinfo(&entity.User{
  31. Id: 336,
  32. Avatar: "ssdf",
  33. })
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. fmt.Println(data)
  38. }
  39. func TestRegist(t *testing.T) {
  40. var (
  41. mobile string = "18310412108"
  42. password string = "7c4a8d09ca3762af61e59520943dc26494f8941b"
  43. vcode string = "123456"
  44. )
  45. user, err := userService.Regist(mobile, password, vcode)
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. t.Log(user)
  50. }
  51. func TestShaPassword(t *testing.T) {
  52. var expectSize = 40
  53. dst := sha1.Sum([]byte("123456"))
  54. dstStr := hex.EncodeToString(dst[0:])
  55. fmt.Println(dstStr)
  56. if expectSize != len(dstStr) {
  57. t.Fatalf("unexpteced size")
  58. }
  59. }
  60. func TestEncryptPassword(t *testing.T) {
  61. dst := sha1.Sum([]byte("123456"))
  62. dstStr := hex.EncodeToString(dst[0:])
  63. dstStr = encryptPassword(PASSWORD_KEY + dstStr + "807654")
  64. /*if dstStr != "C0B90EC7439DA4CE30D555F30DE04CB517D81234" {
  65. t.Fatal("w")
  66. }*/
  67. fmt.Println(dstStr)
  68. }
  69. /*func TestGetLoginSession(t *testing.T) {
  70. var token = "3sCIzC5fSEm9k-42pHbTE"
  71. session, err := userService.GetLoginSession(token)
  72. if err != nil {
  73. t.Fatal(err)
  74. }
  75. fmt.Println(session)
  76. }*/