[kbn-test] improve saml auth failure logging (#208216)

## Summary

sometimes we face failure during saml authentication and error message
is not very helpful:

```
Error: Failed to parse 'set-cookie' header
    at getCookieFromResponseHeaders (packages/kbn-test/src/auth/saml_auth.ts:61:11)
    at finishSAMLHandshake (packages/kbn-test/src/auth/saml_auth.ts:280:10)
    at createLocalSAMLSession (packages/kbn-test/src/auth/saml_auth.ts:333:18)
```

With this change we should know when it happened:

- we create SAML request by calling `/internal/security/login
- we finish SAML handshake by calling  `/api/security/saml/callback`

I also hope `response.data` to be useful for investigation
This commit is contained in:
Dzmitry Lemechko 2025-01-27 21:13:50 +01:00 committed by GitHub
parent 3e5505fad7
commit 10505bd488
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -230,7 +230,7 @@ describe('saml_auth', () => {
});
expect(createSAMLRequest('https://kbn.test.co', '8.12.0', log)).rejects.toThrow(
`Failed to parse 'set-cookie' header`
/Failed to parse cookie from SAML response headers: no 'set-cookie' header, response.data:/
);
});
@ -332,7 +332,9 @@ https://kbn.test.co in the same window.`);
sid: 'Fe26.2**1234567890',
log,
})
).rejects.toThrow(`Failed to parse 'set-cookie' header`);
).rejects.toThrow(
/Failed to get cookie from SAML callback response: no 'set-cookie' header, response.data:/
);
});
});
});

View file

@ -58,7 +58,9 @@ const cleanException = (url: string, ex: any) => {
const getCookieFromResponseHeaders = (response: AxiosResponse, errorMessage: string) => {
const setCookieHeader = response?.headers['set-cookie'];
if (!setCookieHeader) {
throw new Error(`Failed to parse 'set-cookie' header`);
throw new Error(
`${errorMessage}: no 'set-cookie' header, response.data: ${JSON.stringify(response?.data)}`
);
}
const cookie = parseCookie(setCookieHeader![0]);
@ -289,7 +291,7 @@ export const finishSAMLHandshake = async ({
return getCookieFromResponseHeaders(
authResponse,
'Failed to get cookie from SAML callback response headers'
'Failed to get cookie from SAML callback response'
);
};