Skip to content

Commit 994480f

Browse files
committed
reset trusted domains on extension settings reset
1 parent fca6cd7 commit 994480f

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Extension/src/background/api/document-block.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,11 @@ export class DocumentBlockApi {
8989

9090
DocumentBlockApi.storeTrustedDomain(hostname);
9191
}
92+
93+
/**
94+
* Resets trusted domains to empty array.
95+
*/
96+
public static async reset(): Promise<void> {
97+
await trustedDomainsStorage.setData([]);
98+
}
9299
}

Extension/src/background/api/settings/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
GPC_SCRIPT_OUTPUT,
7474
HIDE_DOCUMENT_REFERRER_OUTPUT,
7575
} from '../../../../../constants';
76+
import { DocumentBlockApi } from '../document-block';
7677
import { filteringLogApi } from '../filtering-log';
7778
import { network } from '../network';
7879
import { CommonFilterUtils } from '../../../common/common-filter-utils';
@@ -216,6 +217,9 @@ export class SettingsApi {
216217
// On import should enable only groups from imported file.
217218
await CommonFilterApi.initDefaultFilters(enableUntouchedGroups);
218219

220+
// reset trusted domains list
221+
await DocumentBlockApi.reset();
222+
219223
// reset list of consented filter ids on reset settings
220224
await annoyancesConsent.reset();
221225
}

tests/src/background/api/document-block.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,31 @@ describe('document block api', () => {
8080
}),
8181
).toBe(true);
8282
});
83+
84+
it('Resets trusted domains', async () => {
85+
const url = 'https://example.org/test';
86+
87+
await DocumentBlockApi.init();
88+
89+
vi.spyOn(Date, 'now').mockImplementation(() => 0);
90+
91+
await DocumentBlockApi.setTrustedDomain(url);
92+
93+
expect(
94+
browser.storage.local.set.calledWith({
95+
[TRUSTED_DOCUMENTS_CACHE_KEY]: JSON.stringify([{
96+
domain: 'example.org',
97+
expires: DocumentBlockApi.TRUSTED_TTL_MS,
98+
}]),
99+
}),
100+
).toBe(true);
101+
102+
await DocumentBlockApi.reset();
103+
104+
expect(
105+
browser.storage.local.set.calledWith({
106+
[TRUSTED_DOCUMENTS_CACHE_KEY]: JSON.stringify([]),
107+
}),
108+
).toBe(true);
109+
});
83110
});

tests/src/background/api/settings.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
HIDE_DOCUMENT_REFERRER_OUTPUT,
1717
} from '../../../../constants';
1818
import {
19+
DocumentBlockApi,
1920
Network,
2021
SettingsApi,
2122
type SettingsData,
@@ -222,10 +223,16 @@ describe('Settings Api', () => {
222223

223224
it('Reset default settings', async () => {
224225
await SettingsApi.setSetting(SettingOption.AllowlistEnabled, false);
226+
expect(SettingsApi.getSetting(SettingOption.AllowlistEnabled)).toBe(false);
227+
228+
// test trusted domains list as well since it is temporary and not stores as a part of settings
229+
await DocumentBlockApi.setTrustedDomain('https://example.com/test');
230+
expect(await DocumentBlockApi.getTrustedDomains()).toStrictEqual(['example.com']);
225231

226232
await SettingsApi.reset(true);
227233

228234
expect(SettingsApi.getSetting(SettingOption.AllowlistEnabled)).toBe(true);
235+
expect(await DocumentBlockApi.getTrustedDomains()).toStrictEqual([]);
229236
}, EXTENDED_TIMEOUT_MS);
230237
});
231238
});

0 commit comments

Comments
 (0)