|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { httpServerMock } from '../../../../../../src/core/server/http/http_server.mocks'; |
| 17 | + |
| 18 | +import { SecurityPluginConfigType } from '../../../index'; |
| 19 | +import { SecuritySessionCookie } from '../../../session/security_cookie'; |
| 20 | +import { |
| 21 | + IRouter, |
| 22 | + CoreSetup, |
| 23 | + ILegacyClusterClient, |
| 24 | + Logger, |
| 25 | + SessionStorageFactory, |
| 26 | +} from '../../../../../../src/core/server'; |
| 27 | +import { BasicAuthentication } from './basic_auth'; |
| 28 | + |
| 29 | +describe('Basic auth tests', () => { |
| 30 | + let router: IRouter; |
| 31 | + let core: CoreSetup; |
| 32 | + let esClient: ILegacyClusterClient; |
| 33 | + let sessionStorageFactory: SessionStorageFactory<SecuritySessionCookie>; |
| 34 | + let logger: Logger; |
| 35 | + |
| 36 | + const config = { |
| 37 | + session: { |
| 38 | + ttl: 1000, |
| 39 | + }, |
| 40 | + } as SecurityPluginConfigType; |
| 41 | + |
| 42 | + test('getKeepAliveExpiry', () => { |
| 43 | + const realDateNow = Date.now.bind(global.Date); |
| 44 | + const dateNowStub = jest.fn(() => 0); |
| 45 | + global.Date.now = dateNowStub; |
| 46 | + const basicAuthentication = new BasicAuthentication( |
| 47 | + config, |
| 48 | + sessionStorageFactory, |
| 49 | + router, |
| 50 | + esClient, |
| 51 | + core, |
| 52 | + logger |
| 53 | + ); |
| 54 | + |
| 55 | + const cookie: SecuritySessionCookie = { |
| 56 | + credentials: { |
| 57 | + authHeaderValueExtra: true, |
| 58 | + }, |
| 59 | + expiryTime: 0, |
| 60 | + }; |
| 61 | + |
| 62 | + const request = httpServerMock.createOpenSearchDashboardsRequest({ |
| 63 | + path: '/internal/v1', |
| 64 | + }); |
| 65 | + |
| 66 | + expect(basicAuthentication.getKeepAliveExpiry(cookie, request)).toBe(1000); |
| 67 | + global.Date.now = realDateNow; |
| 68 | + }); |
| 69 | +}); |
0 commit comments