diff --git a/ui/.env b/ui/.env index 64641bc9..e6464568 100644 --- a/ui/.env +++ b/ui/.env @@ -11,4 +11,5 @@ NEXT_PUBLIC_SAML_REQUEST_TEMPLATE=https://myserver.example.edu/myappiam_0108urn:oasis:names:tc:SAML:1.0:cm:artifacttestiwtaurn:oasis:names:tc:SAML:1.0:cm:artifacttestiwta@hawaii.edustaff99997010Testf-iwt-auhsystemTestf-iwt-a TestIAM-stafftestiwtatestiwta@hawaii.edutestiwta@hawaii.eduTestIAM-staffeduPersonOrgDN=uhsystem,eduPersonAffiliation=staff +XML_SOAP_RESPONSE_REQUEST_DENIED=Ticket 'test' not recognized IRON_SESSION_SECRET=IronSessionSecretForTestingAuthentication diff --git a/ui/src/access/Saml11Validator.ts b/ui/src/access/Saml11Validator.ts index 1448bca0..d046fc2b 100644 --- a/ui/src/access/Saml11Validator.ts +++ b/ui/src/access/Saml11Validator.ts @@ -35,6 +35,15 @@ export const validateTicket = async (ticket: string): Promise => { body: samlRequestBody }); const data = await response.text(); + + const { statusCode }: { statusCode: string } = await transform(data, { + statusCode: '//*[local-name() = "Status"]/*[local-name() ="StatusCode"]/@Value' + }); + + if (statusCode.endsWith('RequestDenied')) { + throw new Error('Invalid ticket'); + } + const casUser = await transform(data, samlResponseTemplate); return { diff --git a/ui/tests/access/Saml11Validator.test.ts b/ui/tests/access/Saml11Validator.test.ts index 730787af..f8e525aa 100644 --- a/ui/tests/access/Saml11Validator.test.ts +++ b/ui/tests/access/Saml11Validator.test.ts @@ -3,6 +3,7 @@ import User, { AnonymousUser } from '@/access/User'; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); const xmlSoapResponse = process.env.XML_SOAP_RESPONSE as string; +const xmlSoapResponseRequestDenied = process.env.XML_SOAP_RESPONSE_REQUEST_DENIED as string; describe('Saml11Validator', () => { @@ -18,6 +19,11 @@ describe('Saml11Validator', () => { expect(await validateTicket('ticket')).toEqual(AnonymousUser); }); + it('should return an AnonymousUser on invalid ticket', async () => { + fetchMock.mockResponse(xmlSoapResponseRequestDenied); + expect(await validateTicket('ticket')).toEqual(AnonymousUser); + }); + }); });