api_auth_test.go 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package api
  7. import (
  8. "testing"
  9. "github.com/syncthing/syncthing/lib/config"
  10. )
  11. var guiCfg config.GUIConfiguration
  12. func init() {
  13. guiCfg.User = "user"
  14. guiCfg.HashAndSetPassword("pass")
  15. }
  16. func TestStaticAuthOK(t *testing.T) {
  17. t.Parallel()
  18. ok := authStatic("user", "pass", guiCfg)
  19. if !ok {
  20. t.Fatalf("should pass auth")
  21. }
  22. }
  23. func TestSimpleAuthUsernameFail(t *testing.T) {
  24. t.Parallel()
  25. ok := authStatic("userWRONG", "pass", guiCfg)
  26. if ok {
  27. t.Fatalf("should fail auth")
  28. }
  29. }
  30. func TestStaticAuthPasswordFail(t *testing.T) {
  31. t.Parallel()
  32. ok := authStatic("user", "passWRONG", guiCfg)
  33. if ok {
  34. t.Fatalf("should fail auth")
  35. }
  36. }