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

Raft Snapshot Download Bug #17769

Merged
merged 3 commits into from Nov 2, 2022
Merged

Conversation

zofskeez
Copy link
Contributor

@zofskeez zofskeez commented Nov 1, 2022

An uncaught error was causing the service worker to hang when attempting to download a raft snapshot which would eventually result in a permission denied response since the token was not provided to the fetch request.

In the service-worker-authenticated-download in-repo addon the service-worker-registration is attempting to import from @ember/application/namespace. In the generated sw-registration.js script this results in that module being accessed from the Ember global which has been removed and is undefined.

Screencast.from.2022-11-01.03.27.11.PM.webm

This seems to be an issue with ember-auto-import (or babel or webpack by extension) but I just couldn't figure out how to get that import working. I decided to move the event listener to the raft-storage-overview component in the parent application which is already doing a check for the service worker registration and where the download action lives.

@zofskeez zofskeez added ui bug Used to indicate a potential bug labels Nov 1, 2022
@zofskeez zofskeez modified the milestones: 1.13.0-rc1, 1.11.5 Nov 1, 2022

addSuccessHandler(function (registration) {
// attach the handler for the message event so we can send over the auth token
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think the only issue here is that the handler in init won't be called on the initial installation of the worker. This handler gets called when the worker is registered: https://github.com/DockYard/ember-service-worker/blob/4564e495666865b80fd29daf15784e2801b59d1b/service-worker-registration/index.js#L13 - so the check in the init function will only be truthy on subsequent tries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering about that too. I was thinking since the event listener for the message is added when the component initializes then it would be listening before the user has a chance to click the download action 🤔.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK I think you're right - I looked at the file I linked again (lol), and it runs when the JS package loads, so it should be installed by the time you get to the download page (or by the time it renders). Sorry it's been a little bit since I looked at this 😅 !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great thanks for talking through it with me! This is the first time I have looked at that part of the code and wanted to make sure I am understanding things.

@mladlow mladlow modified the milestones: 1.11.5, 1.11.6 Nov 2, 2022
@zofskeez zofskeez marked this pull request as ready for review November 2, 2022 16:02
Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

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

Nice work! Just a question

const [port] = event.ports;

if (action === 'getToken') {
port.postMessage({ token: this.auth.currentToken });
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still want to account for when/if the token isn't retrieved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't look like the original implementation was doing anything other than logging an error to the console. If there is no token the request would result in a 403. I'm not sure in practice if this would occur now since the user would be redirected to the auth route before the component is instantiated.

await render(hbs`<RaftStorageOverview @model={{this.model}} />`);
assert.dom('[data-raft-row]').exists({ count: 2 });
});

test('it should download snapshot via service worker', async function (assert) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't come up with a nice way to test this end to end with the service worker in an appreciable amount of time so I added a test for the component to ensure that it's doing its part.

@zofskeez zofskeez merged commit 7c1763e into main Nov 2, 2022
@zofskeez zofskeez deleted the ui/VAULT-7701/raft-snapshot-download-bug branch November 2, 2022 19:23
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
zofskeez added a commit that referenced this pull request Nov 2, 2022
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
@hashishaw hashishaw linked an issue Nov 21, 2022 that may be closed by this pull request
jayant07-yb pushed a commit to jayant07-yb/hashicorp-vault-integrations that referenced this pull request Mar 15, 2023
* moves service worker message event listener from addon to raft-storage-overview component

* adds changelog entry

* adds raft-storage-overview test for downloading snapshot via service worker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to indicate a potential bug ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot download raft storage snapshot from UI
4 participants