Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recovery): Recovery Rules should reset #1266

Merged
merged 88 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
7b4d93d
feat(mv3): :sparkles: Patching countly-sdk-web
whizzzkid Jul 12, 2023
f3305fe
feat(mv3): :sparkles: Implementing Custom Async Store.
whizzzkid Jul 12, 2023
83af58f
chore(mv3): :adhesive_bandage: Hooking everything up together.
whizzzkid Jul 12, 2023
d504c71
fix(mv3): Countly Patching + ignite-metrics@2.0.0
whizzzkid Jul 13, 2023
4fab16a
fix(mv3): :adhesive_bandage: Patching the Patch
whizzzkid Jul 13, 2023
f02d6a2
fix: tests
whizzzkid Jul 13, 2023
dbab08c
fix: lint
whizzzkid Jul 13, 2023
394b13b
fix(mv3): :recycle: Refactoring `supportsBlock` Checks.
whizzzkid Jul 18, 2023
cbb4ac6
fix(mv3): Regex Bug
whizzzkid Jul 18, 2023
5794aea
feat: Migrating blocking redirection test to observing redirection test
whizzzkid Jul 18, 2023
0b0af76
fix(mv3): :wrench: Fixing the mocha-setup.
whizzzkid Jul 18, 2023
0de2e89
fix(mv3): :recycle: Moving Setup Files.
whizzzkid Jul 19, 2023
1d46a57
fix(mv3): gateway-redirect tests now fixed.
whizzzkid Jul 19, 2023
44653de
fix: :adhesive_bandage: Patching error messages
whizzzkid Jul 19, 2023
64fcde7
fix(patch): countly-web-sdk
whizzzkid Jul 19, 2023
66b13dc
fix(patch): :pin: Pinning countly-web-sdk to 23.2.2
whizzzkid Jul 19, 2023
39af513
Merge branch 'fix/analytics' into feat/redirection-tests
whizzzkid Jul 19, 2023
bf98b8f
fix(mv3): :lipstick: Fixing Lint
whizzzkid Jul 19, 2023
0b8b308
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 19, 2023
3b80b2a
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 19, 2023
50797d0
feat: protocol-handler-redirection-tests
whizzzkid Jul 19, 2023
46fca05
feat: more tests fixed
whizzzkid Jul 19, 2023
8e3aee2
fix: More tests
whizzzkid Jul 19, 2023
83ff056
fix: lint fix
whizzzkid Jul 19, 2023
38d7b60
test: merge mocha-setup files (#1246)
SgtPooki Jul 25, 2023
4039f0f
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 25, 2023
dd86afa
test: fix after merge
SgtPooki Jul 25, 2023
0e316a2
test: fix after merge
SgtPooki Jul 25, 2023
7b94054
fix: typerrors for localstorage
whizzzkid Jul 25, 2023
8d95a1f
fix: Updating test:functional_MV3 command.
whizzzkid Jul 26, 2023
9bbf271
fix: setup
whizzzkid Jul 26, 2023
5ce5de8
fix(test): Fixing tests
whizzzkid Jul 26, 2023
e5d42e0
fix(lint): Becuase Ofcourse
whizzzkid Jul 26, 2023
a260eb9
feat(test): scaffolding mv3 + mv2 calls in a single check.
whizzzkid Jul 27, 2023
eb8fea0
feat(test): unskipping and upgrading dnslink tests to mv3
whizzzkid Jul 27, 2023
cc109b0
feat(test): Upgrading workaround tests to MV3
whizzzkid Jul 27, 2023
441191e
fix(test): removing all skips with better checks.
whizzzkid Jul 27, 2023
5ac8417
fix(test): :recycle: Refactoring tests and removing redundant calls.
whizzzkid Jul 27, 2023
02042cb
fix(test): More Dryer
whizzzkid Jul 27, 2023
f3d4605
fix(test): one more
whizzzkid Jul 27, 2023
47d72f8
fix(test): :pencil2: Renaming isMv3TestingEnabled -> isManifestV3
whizzzkid Jul 27, 2023
239984d
fix(test): refactor expectNoRedirect
whizzzkid Jul 27, 2023
94cb141
fix(test): :recycle: Refactoring more.
whizzzkid Jul 27, 2023
e3e73c9
fix: replacing checks to undefined
whizzzkid Jul 27, 2023
80e7d51
fix: renaming expectNoRedirect -> ensureNoRedirect
whizzzkid Jul 27, 2023
7d1e97c
fix(test): Adding missing JSDoc
whizzzkid Jul 27, 2023
33b8062
fix(test): :shrug: how did this get removed.
whizzzkid Jul 28, 2023
ae23f4c
fix(test): :wastebasket: removed.
whizzzkid Jul 28, 2023
b77ab7b
fix(test): Suggestion
whizzzkid Jul 28, 2023
bb85dbb
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 28, 2023
6fe39a3
fix(test): :adhesive_bandage: Bad Merge
whizzzkid Jul 28, 2023
e56bb6a
fix(test): sequential expectNoRedirect
lidel Aug 3, 2023
6bd8c3c
Update add-on/src/lib/redirect-handler/blockOrObserve.ts
whizzzkid Aug 4, 2023
7f68ab4
fix(mv3): :wrench: Modifying the default local redirect behaviour.
whizzzkid Aug 4, 2023
d94b9bb
Merge branch 'rc/3.0-mv3' into fix/default-rules
whizzzkid Aug 4, 2023
47ea944
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Aug 4, 2023
a817045
Merge branch 'rc/3.0-mv3' into fix/default-rules
whizzzkid Aug 4, 2023
045e660
fix(mv3): :wrench: Modifying the default local redirect behaviour.
whizzzkid Aug 4, 2023
f6561b9
Merge remote-tracking branch 'refs/remotes/origin/fix/default-rules' …
whizzzkid Aug 4, 2023
c020638
Merge branch 'feat/redirection-tests' into fix/default-rules
whizzzkid Aug 4, 2023
fc085b5
fix(mv3): :bug: Making rules less greedy
whizzzkid Aug 10, 2023
007f41f
fix(mv3): :sparkles: Dynamic Rules for subdomain gateways.
whizzzkid Aug 11, 2023
f18579b
fix(types): Adding ambient types for is-ipfs.
whizzzkid Aug 11, 2023
3e72d36
fix(test):
whizzzkid Aug 12, 2023
d36a282
fix(test): helper
whizzzkid Aug 12, 2023
6ee2d31
feat(mv3): less greedy rules
whizzzkid Aug 12, 2023
e592755
feat: Adding simpler regex for redirects from similar namespaces.
whizzzkid Aug 12, 2023
5c85d84
fix(lint): :rotating_light: Warnings
whizzzkid Aug 12, 2023
fca5fe2
feat(mv3): Better Default Rules (#1260)
whizzzkid Aug 15, 2023
832679d
Update add-on/src/lib/redirect-handler/blockOrObserve.ts
whizzzkid Aug 16, 2023
5e22cea
fix(docs): :pencil2: Adding comments
whizzzkid Aug 16, 2023
43478d6
refactor(regexFilters): :sparkles: Adding a base class for regexFilters.
whizzzkid Aug 16, 2023
fe40f59
refactor(regexFilters): :recycle: Moving subdomain filter to a subclass
whizzzkid Aug 16, 2023
7a631b6
refactor(regexFilters): :recycle: Moving namespace filter to a subclass
whizzzkid Aug 16, 2023
d5d47d7
refactor(regexFilters): :recycle: Moving common filter to a subclass
whizzzkid Aug 16, 2023
05c979f
feat(regexFilters): :sparkles: Hooking Up All together
whizzzkid Aug 16, 2023
7f78475
fix(lint): :pencil2: Lint
whizzzkid Aug 16, 2023
be5a7da
fix(regexFilters): :pencil2: Updating message.
whizzzkid Aug 16, 2023
df85418
fix(rename): :pencil2: CommonPatterRedirectRegexFilter -> CommonPatte…
whizzzkid Aug 24, 2023
524b9bf
fix(regexFilters): :recycle: Refactor to remove call to super
whizzzkid Aug 24, 2023
8261aec
fix: make _canHandle private
whizzzkid Aug 24, 2023
67bbd4a
fix: :zap: Fix math.min on every loop.
whizzzkid Aug 24, 2023
d9b16aa
fix(recovery): reset rules
whizzzkid Aug 25, 2023
de4e628
Merge branch 'rc/3.0-mv3' into fix/recovery-rule-reset
whizzzkid Aug 27, 2023
9439166
fix(recovery): :recycle: Refactor messaging logic
whizzzkid Sep 5, 2023
6d81928
fix(recovery): :bug: Cleanup Logic
whizzzkid Sep 5, 2023
11af401
fix(mv3): :bug: fix toggle site integration.
whizzzkid Sep 5, 2023
7b97530
fix(mv3): :adhesive_bandage: Hard coding wait as the browser is not c…
whizzzkid Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createRequestModifier } from './ipfs-request.js'
import createNotifier from './notifier.js'
import { runPendingOnInstallTasks } from './on-installed.js'
import { guiURLString, migrateOptions, optionDefaults, safeURL, storeMissingOptions } from './options.js'
import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'
import { cleanupRules, getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'
import createRuntimeChecks from './runtime-checks.js'
import { initState, offlinePeerCount } from './state.js'

Expand Down Expand Up @@ -521,6 +521,7 @@ export default async function init (inQuickImport = false) {
try {
const oldColor = colorArraytoHex(await browser.action.getBadgeBackgroundColor({}))
if (badgeColor !== oldColor) {
await cleanupRules(true)
await browser.action.setBadgeBackgroundColor({ color: badgeColor })
await setBrowserActionIcon(badgeIcon)
}
Expand Down Expand Up @@ -577,7 +578,7 @@ export default async function init (inQuickImport = false) {
}
}

async function onStorageChange (changes, area) {
async function onStorageChange (changes) {
let shouldReloadExtension = false
let shouldRestartIpfsClient = false
let shouldStopIpfsClient = false
Expand Down Expand Up @@ -696,6 +697,8 @@ export default async function init (inQuickImport = false) {
browser.tabs.reload() // async reload of options page to keep it alive
await browser.runtime.reload()
}
log('storage change processed')

// Post update to Browser Action (if exists) -- this gives UX a snappy feel
await sendStatusUpdateToBrowserAction()
}
Expand Down
76 changes: 38 additions & 38 deletions add-on/src/lib/redirect-handler/blockOrObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const log = debug('ipfs-companion:redirect-handler:blockOrObserve')
log.error = debug('ipfs-companion:redirect-handler:blockOrObserve:error')

export const DEFAULT_NAMESPACES = new Set(['ipfs', 'ipns'])

export const GLOBAL_STATE_CHANGE = 'GLOBAL_STATE_CHANGE'
export const GLOBAL_STATE_OPTION_CHANGE = 'GLOBAL_STATE_OPTION_CHANGE'
export const DELETE_RULE_REQUEST = 'DELETE_RULE_REQUEST'
export const DELETE_RULE_REQUEST_SUCCESS = 'DELETE_RULE_REQUEST_SUCCESS'
Expand All @@ -32,7 +30,7 @@ interface redirectHandlerInput {
getPort: (state: CompanionState) => string
}

type messageToSelfType = typeof GLOBAL_STATE_CHANGE | typeof GLOBAL_STATE_OPTION_CHANGE | typeof DELETE_RULE_REQUEST
type messageToSelfType = typeof GLOBAL_STATE_OPTION_CHANGE | typeof DELETE_RULE_REQUEST
interface messageToSelf {
type: messageToSelfType
value?: string | Record<string, unknown>
Expand All @@ -50,36 +48,38 @@ export const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})`
export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0)

/**
* Notify self about state change.
* @returns void
* Sends message to self to notify about change.
*
* @param msg
*/
export async function notifyStateChange (): Promise<void> {
return await sendMessageToSelf(GLOBAL_STATE_CHANGE)
async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise<void> {
// this check ensures we don't send messages to ourselves if blocking mode is enabled.
if (!supportsBlock()) {
const message: messageToSelf = { type: msg, value }
// on FF, this call waits for the response from the listener.
// on Chrome, this needs a callback.
await browser.runtime.sendMessage(message)
}
}

/**
* Notify self about option change.
*
* @returns void
*/
export async function notifyOptionChange (): Promise<void> {
log('notifyOptionChange')
return await sendMessageToSelf(GLOBAL_STATE_OPTION_CHANGE)
}

export async function notifyDeleteRule (id: number): Promise<void> {
return await sendMessageToSelf(DELETE_RULE_REQUEST, id)
}

/**
* Sends message to self to notify about change.
* Notify self about rule deletion.
*
* @param msg
* @param id number
* @returns void
*/
async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise<void> {
// this check ensures we don't send messages to ourselves if blocking mode is enabled.
if (!supportsBlock()) {
const message: messageToSelf = { type: msg }
await browser.runtime.sendMessage(message)
}
export async function notifyDeleteRule (id: number): Promise<void> {
return await sendMessageToSelf(DELETE_RULE_REQUEST, id)
}

const savedRegexFilters: Map<string, regexFilterMap> = new Map()
Expand Down Expand Up @@ -205,7 +205,8 @@ async function cleanupRuleById (id: number): Promise<void> {
* @param {function} handlerFn
*/
function setupListeners (handlers: Record<messageToSelfType, (value: any) => Promise<void>>): void {
browser.runtime.onMessage.addListener(async ({ message: { type, value } }: { message: messageToSelf }): Promise<void> => {
browser.runtime.onMessage.addListener(async (message: messageToSelf): Promise<void> => {
const { type, value } = message
if (type in handlers) {
await handlers[type](value)
}
Expand Down Expand Up @@ -340,6 +341,23 @@ export function generateAddRule (
*/
export function addRuleToDynamicRuleSetGenerator (
getState: () => CompanionState): (input: redirectHandlerInput) => Promise<void> {
// setup listeners for the extension.
setupListeners({
[GLOBAL_STATE_OPTION_CHANGE]: async (): Promise<void> => {
log('GLOBAL_STATE_OPTION_CHANGE')
await cleanupRules(true)
await reconcileRulesAndRemoveOld(getState())
},
[DELETE_RULE_REQUEST]: async (value: number): Promise<void> => {
if (value != null) {
await cleanupRuleById(value)
await browser.runtime.sendMessage({ type: DELETE_RULE_REQUEST_SUCCESS })
} else {
await cleanupRules(true)
}
}
})

// returning a closure to avoid passing `getState` as an argument to `addRuleToDynamicRuleSet`.
return async function ({ originUrl, redirectUrl }: redirectHandlerInput): Promise<void> {
// update the rules so that the next request is handled correctly.
Expand Down Expand Up @@ -378,24 +396,6 @@ export function addRuleToDynamicRuleSetGenerator (
}
)
}

setupListeners({
[GLOBAL_STATE_CHANGE]: async (): Promise<void> => {
await reconcileRulesAndRemoveOld(getState())
},
[GLOBAL_STATE_OPTION_CHANGE]: async (): Promise<void> => {
await cleanupRules(true)
await reconcileRulesAndRemoveOld(getState())
},
[DELETE_RULE_REQUEST]: async (value: number): Promise<void> => {
if (value != null) {
await cleanupRuleById(value)
await browser.runtime.sendMessage({ type: DELETE_RULE_REQUEST_SUCCESS })
} else {
await cleanupRules(true)
}
}
})
// call to reconcile rules and remove old ones.
await reconcileRulesAndRemoveOld(state)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class SubdomainRedirectRegexFilter extends RegexFilter {
const subdomainPart = urlParts.shift() as string
// this needs to be computed for every iteration as the staticUrlParts changes
const commonStaticUrlEnd = `\\.${escapeURLRegex(staticUrlParts.join('.'))}\\/${RULE_REGEX_ENDING}`

// this does not work for subdomains where namespace is not provided.
// e.g. https://helia-identify.on.fleek.co/
// e.g. https://bafybeib3bzis4mejzsnzsb65od3rnv5ffit7vsllratddjkgfgq4wiamqu.on.fleek.co/
Expand Down
8 changes: 4 additions & 4 deletions add-on/src/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export default function optionsPage (state, emit) {
// when global toggle is in "suspended" state
return html`
<div class="sans-serif">
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
${globalToggleForm({
active: state.options.active,
onOptionChange
})}
</div>
`
}
Expand Down
5 changes: 1 addition & 4 deletions add-on/src/options/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import browser from 'webextension-polyfill'
import { optionDefaults } from '../lib/options.js'
import { DELETE_RULE_REQUEST_SUCCESS, RULE_REGEX_ENDING, notifyDeleteRule, notifyOptionChange, notifyStateChange } from '../lib/redirect-handler/blockOrObserve.js'
import { DELETE_RULE_REQUEST_SUCCESS, RULE_REGEX_ENDING, notifyDeleteRule, notifyOptionChange } from '../lib/redirect-handler/blockOrObserve.js'
import createRuntimeChecks from '../lib/runtime-checks.js'

// The store contains and mutates the state for the app
Expand Down Expand Up @@ -49,9 +49,6 @@ export default function optionStore (state, emitter) {

emitter.on('optionChange', async ({ key, value }) => {
browser.storage.local.set({ [key]: value })
if (key === 'active') {
await notifyStateChange()
}
await notifyOptionChange()
})

Expand Down
10 changes: 7 additions & 3 deletions add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { optionsPage, welcomePage } from '../../lib/constants.js'
import { contextMenuCopyAddressAtPublicGw, contextMenuCopyCanonicalAddress, contextMenuCopyCidAddress, contextMenuCopyPermalink, contextMenuCopyRawCid, contextMenuViewOnGateway } from '../../lib/context-menus.js'
import { browserActionFilesCpImportCurrentTab } from '../../lib/ipfs-import.js'
import { ipfsContentPath } from '../../lib/ipfs-path.js'
import { notifyStateChange } from '../../lib/redirect-handler/blockOrObserve.js'
import { notifyOptionChange } from '../../lib/redirect-handler/blockOrObserve.js'
import { POSSIBLE_NODE_TYPES } from '../../lib/state.js'

// The store contains and mutates the state for the app
Expand Down Expand Up @@ -179,7 +179,11 @@ export default (state, emitter) => {
}
// console.dir('toggleSiteIntegrations', state)
await browser.storage.local.set({ disabledOn, enabledOn })
await notifyStateChange()
await notifyOptionChange()
// notifyOptionsChange call is async, sends a message to background and
// waits for it to resolve. However, that doesnt work the
// same way in Chrome and FF. So we need to wait a bit before reloading.
await new Promise(resolve => setTimeout(resolve, 200))

const path = ipfsContentPath(currentTab.url, { keepURIParams: true })
// Reload the current tab to apply updated redirect preference
Expand Down Expand Up @@ -216,7 +220,7 @@ export default (state, emitter) => {
state.swarmPeers = null
state.isIpfsOnline = false
}
await notifyStateChange()
await notifyOptionChange()
await browser.storage.local.set({ active: state.active })
} catch (error) {
console.error(`Unable to update global Active flag due to ${error}`)
Expand Down