Skip to content

Commit

Permalink
Remove dependency loop between dnr-utils and dnr-config-rulesets (duc…
Browse files Browse the repository at this point in the history
…kduckgo#2057)

* Remove dependency loop between dnr-utils and dnr-config-rulesets

* Update test imports
  • Loading branch information
sammacbeth authored Jun 22, 2023
1 parent d81bbc9 commit 7d99dea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
14 changes: 1 addition & 13 deletions shared/js/background/dnr-config-rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ensureServiceWorkerInitiatedRequestExceptions
} from './dnr-service-worker-initiated'
import { getDenylistedDomains } from './dnr-user-allowlist'
import { findExistingDynamicRule } from './dnr-utils'
import { findExistingDynamicRule, SETTING_PREFIX, ruleIdRangeByConfigName } from './dnr-utils'
import {
generateExtensionConfigurationRuleset
} from '@duckduckgo/ddg2dnr/lib/extensionConfiguration'
Expand All @@ -22,18 +22,6 @@ import {
generateCombinedConfigBlocklistRuleset
} from '@duckduckgo/ddg2dnr/lib/combined'

export const SETTING_PREFIX = 'declarative_net_request-'

// Allocate blocks of rule IDs for the different configurations. That way, the
// rules associated with a configuration can be safely cleared without the risk
// of removing rules associated with different configurations.
export const ruleIdRangeByConfigName = {
tds: [1, 10000],
config: [10001, 20000],
_RESERVED: [20001, 21000],
combined: [21001, 31000]
}

/**
* A dummy etag rule is saved with the declarativeNetRequest rules generated for
* each configuration. That way, a consistent extension state (between tds
Expand Down
16 changes: 12 additions & 4 deletions shared/js/background/dnr-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
ruleIdRangeByConfigName,
SETTING_PREFIX
} from './dnr-config-rulesets'
import settings from './settings'

// Rule IDs notes:
Expand Down Expand Up @@ -31,6 +27,18 @@ export const SERVICE_WORKER_INITIATED_ALLOWING_RULE_ID = 20002
export const HTTPS_SESSION_ALLOWLIST_RULE_ID = 20004
export const HTTPS_SESSION_UPGRADE_RULE_ID = 20005

export const SETTING_PREFIX = 'declarative_net_request-'

// Allocate blocks of rule IDs for the different configurations. That way, the
// rules associated with a configuration can be safely cleared without the risk
// of removing rules associated with different configurations.
export const ruleIdRangeByConfigName = {
tds: [1, 10000],
config: [10001, 20000],
_RESERVED: [20001, 21000],
combined: [21001, 31000]
}

// Valid dynamic rule IDs - others will be removed on extension start
const RESERVED_DYNAMIC_RULE_IDS = [
USER_ALLOWLIST_RULE_ID,
Expand Down
6 changes: 3 additions & 3 deletions unit-test/background/declarative-net-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
ensureServiceWorkerInitiatedRequestExceptions
} from '../../shared/js/background/dnr-service-worker-initiated'
import {
onConfigUpdate,
SETTING_PREFIX
onConfigUpdate
} from '../../shared/js/background/dnr-config-rulesets'
import {
refreshUserAllowlistRules,
Expand All @@ -23,7 +22,8 @@ import {
import {
getMatchDetails,
SERVICE_WORKER_INITIATED_ALLOWING_RULE_ID,
USER_ALLOWLIST_RULE_ID
USER_ALLOWLIST_RULE_ID,
SETTING_PREFIX
} from '../../shared/js/background/dnr-utils'
import {
SERVICE_WORKER_INITIATED_ALLOWING_PRIORITY,
Expand Down

0 comments on commit 7d99dea

Please sign in to comment.