New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dhis2/app-service-offline

Package Overview
Dependencies
Maintainers
15
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhis2/app-service-offline - npm Package Compare versions

Comparing version 2.12.0 to 2.12.1

29

build/cjs/lib/__tests__/clear-sensitive-caches.test.js

@@ -14,4 +14,9 @@ "use strict";

// Mocks for CacheStorage API
// Returns true if an existing cache is deleted
const makeCachesDeleteMock = keys => {
return jest.fn().mockImplementation(key => Promise.resolve(keys.includes(key)));
};
const keysMockDefault = jest.fn().mockImplementation(async () => []);
const deleteMockDefault = jest.fn().mockImplementation(async () => null);
const deleteMockDefault = makeCachesDeleteMock([]);
const cachesDefault = {

@@ -44,14 +49,18 @@ keys: keysMockDefault,

it('does not fail if there are no caches or no sections-db', () => {
return expect((0, _clearSensitiveCaches.clearSensitiveCaches)()).resolves.toBeDefined();
return expect((0, _clearSensitiveCaches.clearSensitiveCaches)()).resolves.toBe(false);
});
it('clears potentially sensitive caches', async () => {
const keysMock = jest.fn().mockImplementation(async () => ['cache1', 'cache2', 'app-shell']);
window.caches = { ...cachesDefault,
keys: keysMock
const testKeys = ['cache1', 'cache2', 'app-shell'];
const keysMock = jest.fn().mockImplementation(() => Promise.resolve(testKeys));
const deleteMock = makeCachesDeleteMock(testKeys);
window.caches = {
keys: keysMock,
delete: deleteMock
};
await (0, _clearSensitiveCaches.clearSensitiveCaches)();
expect(deleteMockDefault).toHaveBeenCalledTimes(3);
expect(deleteMockDefault.mock.calls[0][0]).toBe('cache1');
expect(deleteMockDefault.mock.calls[1][0]).toBe('cache2');
expect(deleteMockDefault.mock.calls[2][0]).toBe('app-shell');
const cachesDeleted = await (0, _clearSensitiveCaches.clearSensitiveCaches)();
expect(cachesDeleted).toBe(true);
expect(deleteMock).toHaveBeenCalledTimes(3);
expect(deleteMock.mock.calls[0][0]).toBe('cache1');
expect(deleteMock.mock.calls[1][0]).toBe('cache2');
expect(deleteMock.mock.calls[2][0]).toBe('app-shell');
});

@@ -58,0 +67,0 @@ it('preserves keepable caches', async () => {

@@ -75,8 +75,10 @@ "use strict";

const cacheKeys = await caches.keys();
return Promise.all([clearDB(dbName), // remove caches if not in keepable list
return Promise.all([// (Resolves to 'false' because this can't detect if anything was deleted):
clearDB(dbName).then(() => false), // Remove caches if not in keepable list
...cacheKeys.map(key => {
if (!KEEPABLE_CACHES.some(pattern => pattern.test(key))) {
// .then() satisfies typescript
return caches.delete(key).then(() => undefined);
return caches.delete(key);
}
return false;
})]).then(responses => {

@@ -83,0 +85,0 @@ // Return true if any caches have been cleared

@@ -5,5 +5,10 @@ import FDBFactory from 'fake-indexeddb/lib/FDBFactory';

import { clearSensitiveCaches, SECTIONS_DB, SECTIONS_STORE } from '../clear-sensitive-caches'; // Mocks for CacheStorage API
// Returns true if an existing cache is deleted
const makeCachesDeleteMock = keys => {
return jest.fn().mockImplementation(key => Promise.resolve(keys.includes(key)));
};
const keysMockDefault = jest.fn().mockImplementation(async () => []);
const deleteMockDefault = jest.fn().mockImplementation(async () => null);
const deleteMockDefault = makeCachesDeleteMock([]);
const cachesDefault = {

@@ -36,14 +41,18 @@ keys: keysMockDefault,

it('does not fail if there are no caches or no sections-db', () => {
return expect(clearSensitiveCaches()).resolves.toBeDefined();
return expect(clearSensitiveCaches()).resolves.toBe(false);
});
it('clears potentially sensitive caches', async () => {
const keysMock = jest.fn().mockImplementation(async () => ['cache1', 'cache2', 'app-shell']);
window.caches = { ...cachesDefault,
keys: keysMock
const testKeys = ['cache1', 'cache2', 'app-shell'];
const keysMock = jest.fn().mockImplementation(() => Promise.resolve(testKeys));
const deleteMock = makeCachesDeleteMock(testKeys);
window.caches = {
keys: keysMock,
delete: deleteMock
};
await clearSensitiveCaches();
expect(deleteMockDefault).toHaveBeenCalledTimes(3);
expect(deleteMockDefault.mock.calls[0][0]).toBe('cache1');
expect(deleteMockDefault.mock.calls[1][0]).toBe('cache2');
expect(deleteMockDefault.mock.calls[2][0]).toBe('app-shell');
const cachesDeleted = await clearSensitiveCaches();
expect(cachesDeleted).toBe(true);
expect(deleteMock).toHaveBeenCalledTimes(3);
expect(deleteMock.mock.calls[0][0]).toBe('cache1');
expect(deleteMock.mock.calls[1][0]).toBe('cache2');
expect(deleteMock.mock.calls[2][0]).toBe('app-shell');
});

@@ -50,0 +59,0 @@ it('preserves keepable caches', async () => {

@@ -66,8 +66,10 @@ // IndexedDB names; should be the same as in @dhis2/pwa

const cacheKeys = await caches.keys();
return Promise.all([clearDB(dbName), // remove caches if not in keepable list
return Promise.all([// (Resolves to 'false' because this can't detect if anything was deleted):
clearDB(dbName).then(() => false), // Remove caches if not in keepable list
...cacheKeys.map(key => {
if (!KEEPABLE_CACHES.some(pattern => pattern.test(key))) {
// .then() satisfies typescript
return caches.delete(key).then(() => undefined);
return caches.delete(key);
}
return false;
})]).then(responses => {

@@ -74,0 +76,0 @@ // Return true if any caches have been cleared

{
"name": "@dhis2/app-service-offline",
"description": "A runtime service for online/offline detection and offline caching",
"version": "2.12.0",
"version": "2.12.1",
"main": "./build/cjs/index.js",

@@ -36,3 +36,3 @@ "module": "./build/es/index.js",

"peerDependencies": {
"@dhis2/app-service-alerts": "2.12.0",
"@dhis2/app-service-alerts": "2.12.1",
"prop-types": "^15.7.2",

@@ -39,0 +39,0 @@ "react": "^16.8.6",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc