Enforce ManagedAPIKey for resource ID flag
RequiresManagedResourceID only has meaning for a ManagedAPIKey provider: ManagedConnectorReady consults it exclusively on that path. A non-managed provider that set it would advertise normally with the requirement silently doing nothing. Reject the combination at registration, matching the ManagedAPIKey/SupportsAPIKey mutual-exclusion guard already in Register, and cover it with a TestRegistry_Register subtest. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -120,6 +120,14 @@ func (r *Registry) Register(reg *Registration) error {
|
||||
return fmt.Errorf("cannot register connector provider %q: ManagedAPIKey is mutually exclusive with SupportsAPIKey and SupportsClientCredentials", reg.Provider)
|
||||
}
|
||||
|
||||
// RequiresManagedResourceID only has meaning for a ManagedAPIKey provider:
|
||||
// ManagedConnectorReady consults it exclusively on that path, so setting it
|
||||
// on a non-managed provider is a silently ineffective flag. Reject it at
|
||||
// startup rather than let the requirement quietly do nothing.
|
||||
if reg.RequiresManagedResourceID && !reg.ManagedAPIKey {
|
||||
return fmt.Errorf("cannot register connector provider %q: RequiresManagedResourceID requires ManagedAPIKey", 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
|
||||
|
||||
@@ -138,6 +138,19 @@ func TestRegistry_Register(t *testing.T) {
|
||||
assert.Contains(t, err.Error(), "mutually exclusive")
|
||||
})
|
||||
|
||||
t.Run("RequiresManagedResourceID requires ManagedAPIKey", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := provider.NewRegistry()
|
||||
err := r.Register(&provider.Registration{
|
||||
Provider: coredata.ConnectorProviderSlack,
|
||||
DisplayName: "Slack",
|
||||
RequiresManagedResourceID: true,
|
||||
})
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "RequiresManagedResourceID requires ManagedAPIKey")
|
||||
})
|
||||
|
||||
t.Run("duplicate registration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user