signature_does_not_match_wrapper_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package errors
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestWrap(t *testing.T) {
  7. wrapper := &SignatureDostNotMatchWrapper{}
  8. m := make(map[string]string)
  9. err := NewServerError(400, "content", "comment")
  10. se, ok := err.(*ServerError)
  11. assert.True(t, ok)
  12. wrapped := wrapper.tryWrap(se, m)
  13. assert.False(t, wrapped)
  14. }
  15. func TestWrapNotMatch(t *testing.T) {
  16. wrapper := &SignatureDostNotMatchWrapper{}
  17. err := NewServerError(400, `{"Code":"SignatureDoesNotMatch","Message":"Specified signature is not matched with our calculation. server string to sign is:hehe"}`, "comment")
  18. se, ok := err.(*ServerError)
  19. assert.True(t, ok)
  20. assert.Equal(t, "SignatureDoesNotMatch", se.ErrorCode())
  21. m := make(map[string]string)
  22. m["StringToSign"] = "not match"
  23. wrapped := wrapper.tryWrap(se, m)
  24. assert.True(t, wrapped)
  25. assert.Equal(t, "This may be a bug with the SDK and we hope you can submit this question in the github issue(https://github.com/aliyun/alibaba-cloud-sdk-go/issues), thanks very much", se.Recommend())
  26. }
  27. func TestWrapMatch(t *testing.T) {
  28. wrapper := &SignatureDostNotMatchWrapper{}
  29. err := NewServerError(400, `{"Code":"SignatureDoesNotMatch","Message":"Specified signature is not matched with our calculation. server string to sign is:match"}`, "comment")
  30. se, ok := err.(*ServerError)
  31. assert.True(t, ok)
  32. assert.Equal(t, "SignatureDoesNotMatch", se.ErrorCode())
  33. m := make(map[string]string)
  34. m["StringToSign"] = "match"
  35. wrapped := wrapper.tryWrap(se, m)
  36. assert.True(t, wrapped)
  37. assert.Equal(t, "InvalidAccessKeySecret: Please check you AccessKeySecret", se.Recommend())
  38. }
  39. func TestWrapMatchWhenCodeIsIncompleteSignature(t *testing.T) {
  40. wrapper := &SignatureDostNotMatchWrapper{}
  41. err := NewServerError(400, `{"Code":"IncompleteSignature","Message":"Specified signature is not matched with our calculation. server string to sign is:match"}`, "comment")
  42. se, ok := err.(*ServerError)
  43. assert.True(t, ok)
  44. assert.Equal(t, "IncompleteSignature", se.ErrorCode())
  45. m := make(map[string]string)
  46. m["StringToSign"] = "match"
  47. wrapped := wrapper.tryWrap(se, m)
  48. assert.True(t, wrapped)
  49. assert.Equal(t, "InvalidAccessKeySecret: Please check you AccessKeySecret", se.Recommend())
  50. }