signature_test.go 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package signature
  2. import (
  3. "net/url"
  4. "testing"
  5. "time"
  6. )
  7. const (
  8. key = "blog"
  9. secret = "i1ydX9RtHyuJTrw7frcu"
  10. ttl = time.Minute * 10
  11. )
  12. func TestSignature_Generate(t *testing.T) {
  13. path := "/echo"
  14. method := "POST"
  15. params := url.Values{}
  16. params.Add("a", "a1")
  17. params.Add("d", "d1")
  18. params.Add("c", "c1 c2")
  19. authorization, date, err := New(key, secret, ttl).Generate(path, method, params)
  20. t.Log("authorization:", authorization)
  21. t.Log("date:", date)
  22. t.Log("err:", err)
  23. }
  24. func TestSignature_Verify(t *testing.T) {
  25. authorization := "blog y7a326f3aWvIxdeNIgRo0P7FSDnCNSsN8gJi/4y+cZo="
  26. date := "2021-04-06 16:15:26"
  27. path := "/echo"
  28. method := "post"
  29. params := url.Values{}
  30. params.Add("a", "a1")
  31. params.Add("d", "d1")
  32. params.Add("c", "c1 c2*")
  33. ok, err := New(key, secret, ttl).Verify(authorization, date, path, method, params)
  34. t.Log(ok)
  35. t.Log(err)
  36. }