mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 05:29:44 +02:00
fix(core): Give each new Microsoft Teams sign-in credential a unique name (no-changelog) (#41256)
This commit is contained in:
parent
a906d2fdfc
commit
7001886432
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user