Reject setting both OAuth token-URL closures

A Registration that sets both BuildTokenURLForDomain and
BuildTokenURLForSite would pass startup but silently use only the first
at the OAuth callback (CompleteWithState checks them in order). Reject
the combination in Register so the misconfiguration fails loud at
process start, matching the existing APIKeyBasicAuth/APIKeyHeader guard.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-06-04 18:51:57 +02:00
parent 09cfbce6e5
commit bb6a961b12
2 changed files with 22 additions and 0 deletions

View File

@@ -93,6 +93,14 @@ func (r *Registry) Register(reg *Registration) error {
return fmt.Errorf("cannot register connector provider %q: APIKeyBasicAuth, APIKeyHeader, and APIKeyAuthScheme are mutually exclusive", reg.Provider)
}
// BuildTokenURLForDomain and BuildTokenURLForSite both build the token
// endpoint host, but from different sources (a callback param vs. the
// signed state). CompleteWithState checks them in order, so setting both
// is a programmer error with a silent winner. Reject it at startup.
if reg.BuildTokenURLForDomain != nil && reg.BuildTokenURLForSite != nil {
return fmt.Errorf("cannot register connector provider %q: BuildTokenURLForDomain and BuildTokenURLForSite are mutually exclusive", reg.Provider)
}
r.mu.Lock()
defer r.mu.Unlock()

View File

@@ -109,6 +109,20 @@ func TestRegistry_Register(t *testing.T) {
assert.Contains(t, err.Error(), "mutually exclusive")
})
t.Run("BuildTokenURLForDomain and BuildTokenURLForSite mutually exclusive", func(t *testing.T) {
t.Parallel()
r := provider.NewRegistry()
err := r.Register(&provider.Registration{
Provider: coredata.ConnectorProviderSlack,
DisplayName: "Slack",
BuildTokenURLForDomain: func(string) (string, error) { return "", nil },
BuildTokenURLForSite: func(string) (string, error) { return "", nil },
})
require.Error(t, err)
assert.Contains(t, err.Error(), "mutually exclusive")
})
t.Run("duplicate registration", func(t *testing.T) {
t.Parallel()