Skip to content

Commit 934ca76

Browse files
committed
Remove unused testing code
Signed-off-by: Derek Ho <dxho@amazon.com>
1 parent 1202368 commit 934ca76

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed

server/auth/types/authentication_type.test.ts

+47-45
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
/* eslint-disable max-classes-per-file */
17-
// This file has extra classes used for testing
18-
1916
import { SecurityPluginConfigType } from '../..';
2017
import { AuthenticationType } from './authentication_type';
2118
import { httpServerMock } from '../../../../../src/core/server/mocks';
22-
import {
23-
SessionStorageFactory,
24-
SessionStorage,
25-
OpenSearchDashboardsRequest,
26-
} from '../../../../../src/core/server';
19+
import { OpenSearchDashboardsRequest } from '../../../../../src/core/server';
2720
import { SecuritySessionCookie } from '../../session/security_cookie';
2821

2922
class DummyAuthType extends AuthenticationType {
@@ -50,43 +43,6 @@ class DummyAuthType extends AuthenticationType {
5043
}
5144
}
5245

53-
// Implementation of SessionStorage using browser's sessionStorage
54-
class BrowserSessionStorage<T> implements SessionStorage<T> {
55-
private readonly storageKey: string;
56-
57-
constructor(storageKey: string) {
58-
this.storageKey = storageKey;
59-
}
60-
61-
async get(): Promise<T | null> {
62-
const storedValue = sessionStorage.getItem(this.storageKey);
63-
return storedValue ? JSON.parse(storedValue) : null;
64-
}
65-
66-
set(sessionValue: T): void {
67-
const serializedValue = JSON.stringify(sessionValue);
68-
sessionStorage.setItem(this.storageKey, serializedValue);
69-
}
70-
71-
clear(): void {
72-
sessionStorage.removeItem(this.storageKey);
73-
}
74-
}
75-
76-
// Implementation of SessionStorageFactory using the browser's sessionStorage
77-
export class BrowserSessionStorageFactory<T> implements SessionStorageFactory<T> {
78-
private readonly storageKey: string;
79-
80-
constructor(storageKey: string) {
81-
this.storageKey = storageKey;
82-
}
83-
84-
// This method returns a new instance of the browser's SessionStorage for each request
85-
asScoped(request: OpenSearchDashboardsRequest): SessionStorage<T> {
86-
return new BrowserSessionStorage<T>(this.storageKey);
87-
}
88-
}
89-
9046
describe('test tenant header', () => {
9147
const config = {
9248
multitenancy: {
@@ -158,4 +114,50 @@ describe('test tenant header', () => {
158114
const result = await dummyAuthType.authHandler(request, response, toolkit);
159115
expect(result.requestHeaders.securitytenant).toEqual('dummy_tenant');
160116
});
117+
118+
it(`keepalive should not shorten the cookie expiry`, async () => {
119+
const realDateNow = Date.now.bind(global.Date);
120+
const dateNowStub = jest.fn(() => 0);
121+
global.Date.now = dateNowStub;
122+
123+
const keepAliveConfig = {
124+
multitenancy: {
125+
enabled: true,
126+
},
127+
auth: {
128+
unauthenticated_routes: [] as string[],
129+
},
130+
session: {
131+
keepalive: true,
132+
ttl: 1000,
133+
},
134+
} as SecurityPluginConfigType;
135+
const keepAliveDummyAuth = new DummyAuthType(
136+
keepAliveConfig,
137+
new BrowserSessionStorageFactory('security_cookie'),
138+
router,
139+
esClient,
140+
coreSetup,
141+
logger
142+
);
143+
const testCookie: SecuritySessionCookie = {
144+
credentials: {
145+
authHeaderValueExtra: true,
146+
},
147+
expiryTime: 2000,
148+
};
149+
// Set cookie
150+
sessionStorage.setItem('security_cookie', JSON.stringify(testCookie));
151+
const request = httpServerMock.createOpenSearchDashboardsRequest({
152+
path: '/internal/v1',
153+
});
154+
const response = jest.fn();
155+
const toolkit = {
156+
authenticated: jest.fn((value) => value),
157+
};
158+
await keepAliveDummyAuth.authHandler(request, response, toolkit);
159+
const cookieAfterRequest = sessionStorage.getItem('security_cookie');
160+
expect(JSON.parse(cookieAfterRequest!).expiryTime).toBe(2000);
161+
global.Date.now = realDateNow;
162+
});
161163
});

0 commit comments

Comments
 (0)