forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Report missing SAML attributes early with an actionable er…
…ror message (n8n-io#9316)
- Loading branch information
1 parent
ff31749
commit 225fdbb
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { mock } from 'jest-mock-extended'; | ||
import type express from 'express'; | ||
import { SamlService } from '@/sso/saml/saml.service.ee'; | ||
import { mockInstance } from '../../../shared/mocking'; | ||
import { UrlService } from '@/services/url.service'; | ||
import { Logger } from '@/Logger'; | ||
import type { IdentityProviderInstance, ServiceProviderInstance } from 'samlify'; | ||
import * as samlHelpers from '@/sso/saml/samlHelpers'; | ||
|
||
describe('SamlService', () => { | ||
const logger = mockInstance(Logger); | ||
const urlService = mockInstance(UrlService); | ||
const samlService = new SamlService(logger, urlService); | ||
|
||
describe('getAttributesFromLoginResponse', () => { | ||
test('throws when any attribute is missing', async () => { | ||
// | ||
// ARRANGE | ||
// | ||
jest | ||
.spyOn(samlService, 'getIdentityProviderInstance') | ||
.mockReturnValue(mock<IdentityProviderInstance>()); | ||
|
||
const serviceProviderInstance = mock<ServiceProviderInstance>(); | ||
serviceProviderInstance.parseLoginResponse.mockResolvedValue({ | ||
samlContent: '', | ||
extract: {}, | ||
}); | ||
jest | ||
.spyOn(samlService, 'getServiceProviderInstance') | ||
.mockReturnValue(serviceProviderInstance); | ||
|
||
jest.spyOn(samlHelpers, 'getMappedSamlAttributesFromFlowResult').mockReturnValue({ | ||
attributes: {} as never, | ||
missingAttributes: [ | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress', | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstname', | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastname', | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn', | ||
], | ||
}); | ||
|
||
// | ||
// ACT & ASSERT | ||
// | ||
await expect( | ||
samlService.getAttributesFromLoginResponse(mock<express.Request>(), 'post'), | ||
).rejects.toThrowError( | ||
'SAML Authentication failed. Invalid SAML response (missing attributes: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress, http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstname, http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastname, http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn).', | ||
); | ||
}); | ||
}); | ||
}); |