fix(core): Give each new Microsoft Teams sign-in credential a unique name (no-changelog) (#41256)

This commit is contained in:
Bernhard Wittmann 2026-10-16 13:04:21 +00:00 committed by GitHub
parent a906d2fdfc
commit 7001886432
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import type { CredentialsFinderService } from '@n8n/backend-services';
import type { CredentialsService } from '@/credentials/credentials.service';
import type { CredentialsOverwrites } from '@/credentials-overwrites';
import type { OauthService } from '@/oauth/oauth.service';
import type { NamingService } from '@/services/naming.service';
import { BadRequestError } from '@n8n/errors';
import {
@ -31,6 +32,7 @@ describe('TeamsManagedSetupService', () => {
let credentialsFinderService: ReturnType<typeof mock<CredentialsFinderService>>;
let credentialsOverwrites: ReturnType<typeof mock<CredentialsOverwrites>>;
let oauthService: ReturnType<typeof mock<OauthService>>;
let namingService: ReturnType<typeof mock<NamingService>>;
let service: TeamsManagedSetupService;
const withOverwrites = (overwrites: Record<string, unknown> | undefined) => {
@ -55,11 +57,13 @@ describe('TeamsManagedSetupService', () => {
credentialsOverwrites = mock<CredentialsOverwrites>();
oauthService = mock<OauthService>();
oauthService.getBaseUrl.mockReturnValue('https://n8n.example.com/rest/oauth2-credential');
namingService = mock<NamingService>();
service = new TeamsManagedSetupService(
credentialsService,
credentialsFinderService,
credentialsOverwrites,
oauthService,
namingService,
);
withOverwrites({ clientId: 'client-id', clientSecret: 'client-secret' });
});
@ -248,19 +252,22 @@ describe('TeamsManagedSetupService', () => {
});
describe('createManagerCredential', () => {
it('creates an empty credential of the manager type in the agent project', async () => {
it('creates an empty, uniquely named credential of the manager type in the agent project', async () => {
namingService.getUniqueCredentialName.mockResolvedValue('Microsoft organization 2');
credentialsService.createUnmanagedCredential.mockResolvedValue(
mock({ id: 'cred-new', name: 'Microsoft organization' }) as never,
mock({ id: 'cred-new', name: 'Microsoft organization 2' }) as never,
);
await expect(service.createManagerCredential(scope)).resolves.toEqual({
id: 'cred-new',
name: 'Microsoft organization',
name: 'Microsoft organization 2',
type: 'microsoftTeamsManagerOAuth2Api',
isResolvable: false,
});
expect(namingService.getUniqueCredentialName).toHaveBeenCalledWith('Microsoft organization');
expect(credentialsService.createUnmanagedCredential).toHaveBeenCalledWith(
expect.objectContaining({
name: 'Microsoft organization 2',
type: 'microsoftTeamsManagerOAuth2Api',
data: {},
projectId: PROJECT_ID,

View File

@ -12,6 +12,7 @@ import { CredentialsFinderService } from '@n8n/backend-services';
import { CredentialsService } from '@/credentials/credentials.service';
import { CredentialsOverwrites } from '@/credentials-overwrites';
import { OauthService, OauthVersion } from '@/oauth/oauth.service';
import { NamingService } from '@/services/naming.service';
import { BadRequestError } from '@n8n/errors';
import { stringProperty } from '../../integration-helpers';
@ -88,6 +89,7 @@ export class TeamsManagedSetupService {
private readonly credentialsFinderService: CredentialsFinderService,
private readonly credentialsOverwrites: CredentialsOverwrites,
private readonly oauthService: OauthService,
private readonly namingService: NamingService,
) {}
/**
@ -184,7 +186,7 @@ export class TeamsManagedSetupService {
this.assertSetupAvailable();
const credential = await this.credentialsService.createUnmanagedCredential(
{
name: DEFAULT_MANAGER_CREDENTIAL_NAME,
name: await this.namingService.getUniqueCredentialName(DEFAULT_MANAGER_CREDENTIAL_NAME),
type: TEAMS_MANAGER_CREDENTIAL_TYPE,
data: {},
projectId: options.projectId,