test_actor.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package ipnauth
  4. import (
  5. "cmp"
  6. "context"
  7. "errors"
  8. "tailscale.com/ipn"
  9. )
  10. var _ Actor = (*TestActor)(nil)
  11. // TestActor is an [Actor] used exclusively for testing purposes.
  12. type TestActor struct {
  13. UID ipn.WindowsUserID // OS-specific UID of the user, if the actor represents a local Windows user
  14. Name string // username associated with the actor, or ""
  15. NameErr error // error to be returned by [TestActor.Username]
  16. CID ClientID // non-zero if the actor represents a connected LocalAPI client
  17. Ctx context.Context // context associated with the actor
  18. LocalSystem bool // whether the actor represents the special Local System account on Windows
  19. LocalAdmin bool // whether the actor has local admin access
  20. }
  21. // UserID implements [Actor].
  22. func (a *TestActor) UserID() ipn.WindowsUserID { return a.UID }
  23. // Username implements [Actor].
  24. func (a *TestActor) Username() (string, error) { return a.Name, a.NameErr }
  25. // ClientID implements [Actor].
  26. func (a *TestActor) ClientID() (_ ClientID, ok bool) { return a.CID, a.CID != NoClientID }
  27. // Context implements [Actor].
  28. func (a *TestActor) Context() context.Context { return cmp.Or(a.Ctx, context.Background()) }
  29. // CheckProfileAccess implements [Actor].
  30. func (a *TestActor) CheckProfileAccess(profile ipn.LoginProfileView, _ ProfileAccess, _ AuditLogFunc) error {
  31. return errors.New("profile access denied")
  32. }
  33. // IsLocalSystem implements [Actor].
  34. func (a *TestActor) IsLocalSystem() bool { return a.LocalSystem }
  35. // IsLocalAdmin implements [Actor].
  36. func (a *TestActor) IsLocalAdmin(operatorUID string) bool { return a.LocalAdmin }