Skip to content

Commit 273fec4

Browse files
do not refetch license if signature header absents from a response (elastic#79645) (elastic#80191)
Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent 0771cde commit 273fec4

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

x-pack/plugins/licensing/public/plugin.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,46 @@ describe('licensing plugin', () => {
240240
expect(coreSetup.http.get).toHaveBeenCalledTimes(1);
241241
});
242242

243+
it('http interceptor does not trigger re-fetch if signature header is not present', async () => {
244+
const sessionStorage = coreMock.createStorage();
245+
plugin = new LicensingPlugin(coreMock.createPluginInitializerContext(), sessionStorage);
246+
247+
const coreSetup = coreMock.createSetup();
248+
249+
coreSetup.http.get.mockResolvedValue(licenseMock.createLicense({ signature: 'signature-1' }));
250+
251+
let registeredInterceptor: HttpInterceptor;
252+
coreSetup.http.intercept.mockImplementation((interceptor: HttpInterceptor) => {
253+
registeredInterceptor = interceptor;
254+
return () => undefined;
255+
});
256+
257+
await plugin.setup(coreSetup);
258+
await plugin.start(coreStart);
259+
expect(registeredInterceptor!.response).toBeDefined();
260+
261+
const httpResponse = {
262+
response: {
263+
headers: {
264+
get(name: string) {
265+
if (name === 'kbn-license-sig') {
266+
return undefined;
267+
}
268+
throw new Error('unexpected header');
269+
},
270+
},
271+
},
272+
request: {
273+
url: 'http://10.10.10.10:5601/api/hello',
274+
},
275+
};
276+
expect(coreSetup.http.get).toHaveBeenCalledTimes(0);
277+
278+
await registeredInterceptor!.response!(httpResponse as any, null as any);
279+
280+
expect(coreSetup.http.get).toHaveBeenCalledTimes(0);
281+
});
282+
243283
it('http interceptor does not trigger license re-fetch for anonymous pages', async () => {
244284
const sessionStorage = coreMock.createStorage();
245285
plugin = new LicensingPlugin(coreMock.createPluginInitializerContext(), sessionStorage);

x-pack/plugins/licensing/public/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup, LicensingPl
101101
if (core.http.anonymousPaths.isAnonymous(window.location.pathname)) return httpResponse;
102102
if (httpResponse.response) {
103103
const signatureHeader = httpResponse.response.headers.get('kbn-license-sig');
104-
if (this.prevSignature !== signatureHeader) {
104+
if (typeof signatureHeader === 'string' && this.prevSignature !== signatureHeader) {
105105
if (!httpResponse.request!.url.includes(this.infoEndpoint)) {
106106
signatureUpdated$.next();
107107
}

0 commit comments

Comments
 (0)