logicmonclient_test.go 906 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. This Source Code Form is subject to the terms of the Mozilla Public
  3. License, v. 2.0. If a copy of the MPL was not distributed with this
  4. file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. */
  6. package logicmonclient
  7. import "testing"
  8. func TestGeneratesReferenceAuthentication(t *testing.T) {
  9. cred := NewLMv1TokenBasedCredential(
  10. "84GKZTJ7UNB43U84w8qC",
  11. "(8f~NrDi$5mr{6+S82W4XkB~%Ih8)6SItNX3XfKH",
  12. )
  13. verb := "GET"
  14. resource := "/dashboard/widgets"
  15. epoch := "1502813538347"
  16. // From https://www.logicmonitor.com/support/rest-api-developers-guide/overview/api-troubleshooting
  17. expected := "LMv1 84GKZTJ7UNB43U84w8qC:MzFmZWJlZmJlMTMxNmI3NjFmYTE5OTgyZWFlODU3ZDhiOTdmYWNiYzc2NGViOTFlNWYwNjJhZjQxNWNiZDMzYQ==:1502813538347"
  18. actual := generateAuthorization(
  19. epoch,
  20. verb,
  21. resource,
  22. []byte{},
  23. cred,
  24. )
  25. if expected != actual {
  26. t.Errorf("authorization does not match reference!")
  27. }
  28. }