saml reject token renewal (#17079)

This commit is contained in:
Karan Hotchandani 2024-07-18 23:23:50 +05:30 committed by GitHub
parent e4b31f9d65
commit c340fe94f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,63 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { render, screen } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { AuthenticatorRef } from '../AuthProviders/AuthProvider.interface';
import SamlAuthenticator from './SamlAuthenticator';
jest.mock('../../../hooks/useApplicationStore', () => {
return {
useApplicationStore: jest.fn(() => ({
authConfig: {},
getOidcToken: jest.fn().mockReturnValue({ isExpired: false }),
setOidcToken: jest.fn(),
})),
};
});
describe('Test SamlAuthenticator component', () => {
it('Checks if the SamlAuthenticator renders', async () => {
const onLogoutMock = jest.fn();
const authenticatorRef = null;
render(
<SamlAuthenticator ref={authenticatorRef} onLogoutSuccess={onLogoutMock}>
<p data-testid="children" />
</SamlAuthenticator>,
{
wrapper: MemoryRouter,
}
);
const children = screen.getByTestId('children');
expect(children).toBeInTheDocument();
});
it('Rejects promise when renew id token is called', async () => {
const onLogoutMock = jest.fn();
const authenticatorRef = React.createRef<AuthenticatorRef>();
render(
<SamlAuthenticator ref={authenticatorRef} onLogoutSuccess={onLogoutMock}>
<p data-testid="children" />
</SamlAuthenticator>,
{
wrapper: MemoryRouter,
}
);
await expect(authenticatorRef.current?.renewIdToken()).rejects.toEqual(
'SAML authenticator does not support token renewal'
);
});
});

View File

@ -84,7 +84,9 @@ const SamlAuthenticator = forwardRef<AuthenticatorRef, Props>(
logout();
},
async renewIdToken() {
return Promise.resolve('');
return Promise.reject(
'SAML authenticator does not support token renewal'
);
},
}));