Documentation
¶
Overview ¶
Package clmtest provides an in-memory mock of the DocuSign eSignature /oauth/userinfo endpoint, CLM's account discovery endpoint, and the DocuSign CLM Object API, for use by tests in pkg/client and pkg/connector. It exists because no CLM production/sandbox tenant was available to validate this integration directly — this is how the CLM sync/provisioning code paths get exercised instead.
Anti-drift note ¶
This mock replicates the endpoint paths, query params, and response/request shapes documented for the real CLM API — not whatever the connector happens to call. If the connector and this mock ever disagree, treat that as a bug in the connector to fix, not something to paper over here.
Auth ¶
NewServer (used by this package's own Go tests) mocks no real OAuth flow: it returns a *client.Client already wired with a static token, and every endpoint handler requires "Authorization: Bearer <token>" matching that exact token — mirroring the strictness of the real API without needing a token endpoint.
RunStandalone (see cmd/test-server) is for manually pointing a real baton-docusign binary at this mock via --clm-base-url, while the connector still authenticates for real against DocuSign. Its bearer check only requires *a* token, not an exact value, since this mock has no way to independently validate a real DocuSign-issued token.
Endpoints ¶
GET /oauth/userinfo — eSignature account discovery (ensureInitialized)
GET /api/v2/{accountId}/account — CLM account discovery (ensureClmInitialized)
GET /v2/{accountId}/folders/type — GetRootFolder, FindSystemFolder
GET /v2/{accountId}/folders/{id} — GetFolder (supports ?expand=Security)
GET /v2/{accountId}/folders/{id}/folders — ListChildFolders (paginated)
POST /v2/{accountId}/changesecuritytasks — PatchFolderSecurity (create task; resolves inline)
GET /v2/{accountId}/changesecuritytasks/{id} — PatchFolderSecurity (poll a task — see PendingChangeSecurityPolls)
GET /v2/{accountId}/groups — ListGroups
GET /v2/{accountId}/groups/{id}/groupmembers — GetGroupMembers
GET /v2/{accountId}/members — ListMembers
GET /v2/{accountId}/members/{id}/groups — GetMemberGroups (paginated)
PATCH /v2/{accountId}/members/{id} — PatchMemberGroups (additive)
PUT /v2/{accountId}/members/{id} — PutMemberGroups (full-replace)
GET /v2/{accountId}/permissionsets — ListPermissionSets
GET /v2/{accountId}/members/{id}/workflowqueues — GetMemberWorkflowQueues (paginated)
Index ¶
- Constants
- func RunStandalone(addr string) error
- type Server
- func (s *Server) AddBulkWorkflowQueueMember(memberID string, queueCount int)
- func (s *Server) AddMemberWithoutHref(memberID string)
- func (s *Server) AddMemberWorkflowQueueWithEmptyHref(memberID string)
- func (s *Server) ClearMembers()
- func (s *Server) FolderHref(id string) string
- func (s *Server) FolderParents() map[string]string
- func (s *Server) FolderSecurity(folderID string) client.ClmFolderSecurity
- func (s *Server) ForceListChildFoldersError(folderID string, status, errorCode int)
- func (s *Server) ForceListMembersStatus(status int)
- func (s *Server) ForceMemberWorkflowQueuesStatus(memberID string, status int)
- func (s *Server) ForceSystemFolderError(systemFolderType string, status int, errorCode int)
- func (s *Server) GroupHref(id string) string
- func (s *Server) LastPatchedMemberGroupHrefs(memberID string) []string
- func (s *Server) MemberGroups(memberID string) []string
- func (s *Server) MemberGroupsRequestCount() int
- func (s *Server) MemberHref(id string) string
- func (s *Server) MemberWorkflowQueuesRequestCount() int
- func (s *Server) NewClientWithToken(token string) *client.Client
- func (s *Server) SeedFolderTree()
- func (s *Server) SetChangeSecurityTaskHrefOverride(href string)
- func (s *Server) SetFolderGroupSecurityHref(folderID, groupID, href string)
- func (s *Server) SetFolderUserSecurityHref(folderID, memberID, href string)
- func (s *Server) SetGroupHref(id, href string)
- func (s *Server) SetPendingChangeSecurityPolls(n int)
- func (s *Server) URL() string
- func (s *Server) WorkflowQueueHref(id string) string
Constants ¶
const AccountID = "acct-clm-test"
AccountID is the fixed eSignature/CLM account ID used by every seeded fixture.
Variables ¶
This section is empty.
Functions ¶
func RunStandalone ¶
RunStandalone starts the same CLM mock as NewServer, but as a real, long-lived HTTP server on addr (e.g. "localhost:8765") instead of an ephemeral in-process httptest.Server — for manually pointing a real baton-docusign binary at it via --clm-base-url to exercise the CLM sync/provisioning paths against an account that has no CLM subscription of its own. Also seeds SeedFolderTree. Blocks until the server errors or is shut down.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the mock CLM (+ eSignature account discovery) API.
func NewServer ¶
NewServer starts the mock server, seeds it (see seed.go), and returns both the raw Server (for direct state assertions) and a *client.Client wired to talk to it exactly as it would talk to the real DocuSign/CLM hosts.
func (*Server) AddBulkWorkflowQueueMember ¶ added in v0.1.9
AddBulkWorkflowQueueMember adds a new member (not part of the default seed) who belongs to queueCount newly created, distinct workflow queues — for pagination tests that need a member with more workflow-queue memberships than fit on one page, without perturbing the default seed's member count or distinct-queue count that other tests (both here and in pkg/connector) assert on. Call after NewServer returns.
func (*Server) AddMemberWithoutHref ¶ added in v0.1.9
AddMemberWithoutHref seeds a member with an empty Href — clmIDFromHref then reports an empty ID for it, exercising List()'s empty-memberID guard (a malformed record CLM's own API could plausibly return; this connector's endpoint shapes are documented-but-unexercised against a live tenant) without the scan ever reaching GetMemberWorkflowQueues for this member. Call after NewServer returns.
func (*Server) AddMemberWorkflowQueueWithEmptyHref ¶ added in v0.1.9
AddMemberWorkflowQueueWithEmptyHref seeds a new member (not part of the default seed) with a single workflow-queue membership whose Href is empty — clmIDFromHref then reports an empty ID for it, exercising clm_workflow_queue.List()'s skip-unusable-ID guard for one queue within an otherwise normal member scan. Mirrors AddMemberWithoutHref's equivalent case at the member level. Call after NewServer returns.
func (*Server) ClearMembers ¶ added in v0.3.1
func (s *Server) ClearMembers()
ClearMembers removes every seeded member.
func (*Server) FolderHref ¶
FolderHref, GroupHref, MemberHref build the Href a real CLM response would use for a given ID — tests use these to seed Security entries / assert on parsed IDs.
func (*Server) FolderParents ¶
FolderParents maps every folder ID to its parent's ID, or "" for the root and any system folder outside it — for asserting a folder walk reached the whole tree with the right parents.
func (*Server) FolderSecurity ¶
func (s *Server) FolderSecurity(folderID string) client.ClmFolderSecurity
FolderSecurity returns a defensive copy of the current (test-visible) Security state for a folder — three separate collections by principal type, see client.ClmFolderSecurity's doc — for assertions after a Grant/Revoke round trip.
func (*Server) ForceListChildFoldersError ¶
ForceListChildFoldersError makes GET .../folders/{id}/folders fail for exactly this folderID with the given HTTP status and CLM ErrorCode.
func (*Server) ForceListMembersStatus ¶ added in v0.3.1
ForceListMembersStatus makes GET .../members fail with the given HTTP status.
func (*Server) ForceMemberWorkflowQueuesStatus ¶ added in v0.1.9
ForceMemberWorkflowQueuesStatus makes GET .../members/{id}/workflowqueues fail with the given HTTP status for exactly this memberID — for tests that need a specific gRPC code (e.g. PermissionDenied/Unauthenticated) out of one particular member's call, distinct from the unknown-member 404 handleMemberWorkflowQueues already produces for an ID absent from the seed. Call after NewServer returns.
func (*Server) ForceSystemFolderError ¶
ForceSystemFolderError makes GET .../folders/type fail for exactly this systemFolder type with the given HTTP status and CLM ErrorCode.
func (*Server) LastPatchedMemberGroupHrefs ¶ added in v0.1.9
LastPatchedMemberGroupHrefs returns the raw Href strings the most recent PATCH .../members/{id} request body carried for memberID — unlike MemberGroups (which reduces everything to the trailing ID via idFromHref, the same as the real API's own comparison semantics), this exposes the exact Href the connector sent, so a test can tell a sample-derived Href from a base-URL-derived one even when the two mock helpers that build them happen to produce byte-identical strings.
func (*Server) MemberGroups ¶
MemberGroups returns the current (test-visible) group membership for a member, for assertions after a Grant/Revoke round trip.
func (*Server) MemberGroupsRequestCount ¶
MemberGroupsRequestCount returns how many times GET .../members/{id}/groups has been called, across all members — used to assert that GetMemberGroups actually issues multiple requests when a member has more groups than fit on one page, rather than silently returning a truncated single page.
func (*Server) MemberHref ¶
func (*Server) MemberWorkflowQueuesRequestCount ¶ added in v0.1.9
MemberWorkflowQueuesRequestCount is MemberGroupsRequestCount's equivalent for GET .../members/{id}/workflowqueues.
func (*Server) NewClientWithToken ¶
NewClientWithToken builds another *client.Client wired to this same running server (via the identical rewriteTransport, so it reaches the mock regardless of which real host it thinks it's talking to) but presenting an arbitrary bearer token instead of the fixed testBearerToken NewServer uses. Used to simulate an account/token that can't use CLM (wrong OAuth scope, no subscription) — requireAuth's strict mode rejects anything but the exact testBearerToken, so any other value exercises the connector's handling of a 401 from CLM.
func (*Server) SeedFolderTree ¶
func (s *Server) SeedFolderTree()
SeedFolderTree adds a deep, wide tree under the root (one folder has two pages of children) and a Home tree outside it to exercise the extra top-level path. Not in the default seed, so other tests' folder counts don't change.
func (*Server) SetChangeSecurityTaskHrefOverride ¶
SetChangeSecurityTaskHrefOverride makes the next change-security task response carry the given Href instead of this server's own — used to pin the client's host-validation guard (Client.validateClmURL) against a task Href pointing at an unexpected host.
func (*Server) SetFolderGroupSecurityHref ¶ added in v0.1.9
SetFolderGroupSecurityHref and SetFolderUserSecurityHref override the Href of an existing group/user security entry on a seeded folder (matched by ID via idFromHref), letting a test make it observably different from what client.GroupHref/MemberHref's fallback would produce for a different, derived ID — the same lever SetGroupHref gives GetMemberGroups-based tests, needed here because folder security entries carry no separate ID field of their own.
func (*Server) SetFolderUserSecurityHref ¶ added in v0.1.9
func (*Server) SetGroupHref ¶ added in v0.1.9
SetGroupHref overrides the Href a seeded group reports on GetMemberGroups, letting a test make it observably different from what GroupHref (and so client.GroupHref's fallback derivation, which builds the same shape from the discovered base URL) would produce — needed to distinguish a sample-derived Href from a fallback-derived one when both would otherwise be byte-identical.
func (*Server) SetPendingChangeSecurityPolls ¶ added in v0.1.9
SetPendingChangeSecurityPolls makes the next change-security task created by this server require n polls of GET .../changesecuritytasks/{id} before resolving to "success" — exercises PatchFolderSecurity's awaitClmChangeSecurityTask polling loop over the documented waiting/processing Status values.
func (*Server) URL ¶
URL returns the mock server's base URL — also what handleClmAccountDiscovery returns as the CLM API base URL.