hmacsha1signer_ut.cc 844 B

12345678910111213141516171819202122232425
  1. #include "gtest/gtest.h"
  2. #include "alibabacloud/core/HmacSha1Signer.h"
  3. #include <openssl/hmac.h>
  4. using namespace std;
  5. using namespace AlibabaCloud;
  6. TEST(HmacSha1Signer, assign) {
  7. HmacSha1Signer sig;
  8. string sign = sig.generate("GET&%2F&AccessKeyId%3Dtestid%26Action%3DDescribeRegions"
  9. "%26Format%3DXML%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1"
  10. "%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0"
  11. "%26TimeStamp%3D2012-12-26T10%253A33%253A56Z%26Version%3D2013-01-10",
  12. "testsecret&");
  13. EXPECT_TRUE("axE3FUHgDyfm9/+Iep0HpZXrRwE=" == sign);
  14. EXPECT_TRUE(sig.type() == HmacSha1Signer::HmacSha1);
  15. EXPECT_TRUE(sig.name() == "HMAC-SHA1");
  16. EXPECT_TRUE(sig.version() == "1.0");
  17. }
  18. TEST(HmacSha1Signer, edge_from_empty_string) {
  19. HmacSha1Signer sign;
  20. EXPECT_TRUE(sign.generate("", "") == "");
  21. }