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

#7618: increase managed storage delay and link extension immediately for CWS installs #7628

Merged
merged 17 commits into from
Feb 15, 2024

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Feb 15, 2024

What does this PR do?

  • Closes Managed extension policy not taking effect on some extension startups #7618
  • Bumps initialization delay to 4.5s, which is what Privacy Badger uses for Chrome
  • Adds an interval to watch for delayed managed policy initialization
  • Modifies handleInstall to call openInstallPage immediately if the installation appears to be an end-user installation
  • Fixes a bug where extension console + login page would be opened if managedOrganizationId was set in policy, but ssoUrl was not set in policy

Remaining Work

  • Fix strict null checks
  • Modify handleInstall to immediately look for app onboarding page, which indicates user is not an enterprise user
  • E2E users without policy (see demo)
  • E2E test users with policy (see demo)
  • Write storage and install jest tests - see future work

Discussion

  • This PR causes some tests that are using real timers with managed storage to time out. We need to shift those tests over to using fake timers in future DevEx work
  • It would be nice to re-write uses of managed storage (e.g., restricted URLs) to recover from delayed policy initialization. But it's much simpler to assume the policy at profile startup is the policy
  • I opened a w3c working group issue here: Proposal: document browser.storage.managed initialization semantics and provide initialization event w3c/webextensions#547
  • I want to get this PR merged for RainforestQA testing and can follow up with Jest tests (they're a bit complicated due to needing to mock timers)

Demo

Future Work

  • Modify functionality that uses managed policy (e.g., theme/restricted URLs) to handle late initialization/policy changes after the initial extension startup. It shouldn't be needed with 4.5 second startup delay, but we can revisit as necessary

Checklist

  • Add tests: see discussion
  • New files added to src/tsconfig.strictNullChecks.json (if possible)
  • Designate a primary reviewer: @mnholtz

@@ -52,3 +53,17 @@ describe("readManagedStorageByKey", () => {
);
});
});

describe("watchStorageInitialization", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: this test doesn't work

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use useFakeTimers and runOnlyPendingTimers?

Copy link
Contributor Author

@twschiller twschiller Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's what I will try to use now - was just trying to get a quick and dirty test originally without breaking the other tests in the module

* Returns true if this appears to be a Chrome Web Store install and/or the user has an app URL where they're
* authenticated so the extension can be linked.
*/
async function isEndUserInstall(): Promise<boolean> {
Copy link
Contributor Author

@twschiller twschiller Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no great way to test this method in Jest, b/c it would just involve mocking browser.tabs.query. So, we will rely on the Rainforest QA tests and manual testing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I might add "likely" to the name of this func, e.g. isLikelyEndUserInstall

@twschiller twschiller changed the title #7618: [WIP] managedStorage delay and API improvements #7618: [WIP] increate managed storage delay and link extension immediately for CWS installs Feb 15, 2024
@twschiller twschiller changed the title #7618: [WIP] increate managed storage delay and link extension immediately for CWS installs #7618: [WIP] increatse managed storage delay and link extension immediately for CWS installs Feb 15, 2024
@twschiller twschiller changed the title #7618: [WIP] increatse managed storage delay and link extension immediately for CWS installs #7618: [WIP] increase managed storage delay and link extension immediately for CWS installs Feb 15, 2024
@twschiller twschiller changed the title #7618: [WIP] increase managed storage delay and link extension immediately for CWS installs #7618: increase managed storage delay and link extension immediately for CWS installs Feb 15, 2024
@twschiller twschiller marked this pull request as ready for review February 15, 2024 22:25
@@ -421,7 +421,7 @@ export async function updateDeployments(): Promise<void> {
sso: false,
});

void browser.runtime.openOptionsPage();
await browser.runtime.openOptionsPage();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason for it to be void because that's the standard behavior

Copy link

When the PR is merged, the first loom link found on this PR will be posted to #sprint-demo on Slack. Do not edit this comment manually.


/**
* The managedStorageState, or undefined if it hasn't been initialized yet.
*/
let managedStorageState: ManagedStorageState | undefined;
let managedStorageSnapshot: Nullishable<ManagedStorageState>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: out of curiosity, why use the word snapshot here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshot is the terminology that React useExternalStore uses and is the method here:

export function getSnapshot(): Nullishable<ManagedStorageState> {

Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Attention: 26 lines in your changes are missing coverage. Please review.

Comparison is base (c918748) 72.80% compared to head (3d70082) 72.77%.
Report is 1 commits behind head on main.

❗ Current head 3d70082 differs from pull request most recent head 61857c9. Consider uploading reports for the commit 61857c9 to get more accurate results

Files Patch % Lines
src/store/enterprise/managedStorage.ts 62.96% 20 Missing ⚠️
src/background/installer.ts 58.33% 5 Missing ⚠️
src/background/background.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7628      +/-   ##
==========================================
- Coverage   72.80%   72.77%   -0.04%     
==========================================
  Files        1225     1225              
  Lines       38182    38212      +30     
  Branches     7180     7185       +5     
==========================================
+ Hits        27798    27807       +9     
- Misses      10384    10405      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@twschiller twschiller merged commit 963c1fd into main Feb 15, 2024
14 checks passed
@twschiller twschiller deleted the feature/7618-extension-policy branch February 15, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Managed extension policy not taking effect on some extension startups
4 participants