Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

fix: Prevent infinitely recursing when injecting into iframes #66

Merged
merged 7 commits into from
Jun 22, 2018

Conversation

stephenmathieson
Copy link
Member

@stephenmathieson stephenmathieson commented Jun 21, 2018

This patch prevents axe-webdriverjs from infinitely recursing when injecting axe-core into <iframe>s. I've re-written the code we use for injecting which will only recurse as deep as the number of nested <iframe>s on the page.

In order to keep the code "easy to read/write", I've used async/await rather than chaining Promises together. Because we do not have a clear picture of what Node.js versions we need to support here, I've added Babel in order to ensure async/await works in older Nodes. It is currently setup use support Node v4.

A test case has been added ensuring this solves the problem described in #63.

Closes #63.

This patch prevents `axe-webdriverjs` to infinitely recurse when injecting `axe-core` into `<iframe>`s. I've re-written the code we use for injecting which will only recurse as deep as the number of nested `<iframe>`s on the page.

In order to keep the code "easy to read/write", I've used `async/await` rather than chaining `Promise`s together. Because we do not have a clear picture of what Node.js versions we need to support here, I've added Babel in order to ensure `async/await` works in older Nodes. It is currently setup use support Node v4.

A test case has been added ensuring this solves the problem described in #63.

Closes #63.
@@ -3,7 +3,7 @@
"description": "Provides a method to inject and analyze web pages using aXe",
"version": "2.0.0",
"license": "MPL-2.0",
"main": "lib/index.js",
"main": "dist/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to add the "engine" field


this.didLogError = true;
// eslint-disable-next-line no-console
console.log('Failed to inject axe-core into one of the iframes!');
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight scope creep here, but I'd like for us to have the option to turn this off: #41

Axe-core 3.0 has a rule which checks that iframes have been tested. That's a better way to expose this info than this console log.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can that be taken care of outside of this PR? I'd like to get this in to fix the issue for a client.

@@ -0,0 +1,82 @@
class AxeInjector {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you rewrite this to work as a class? As far as I can tell, all this is doing is binding some arguments to the inject function.

Copy link
Member Author

Choose a reason for hiding this comment

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

I rewrote this as a class to more easily maintain state. If it weren't a class, we'd have several nested closures, which can get hairy quickly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why, but lets roll with it.

.manage()
.timeouts()
.setScriptTimeout(5000);
return driver.get('https://buy.garmin.com/en-US/US/p/591046');
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems more than a little fragile. Can we do something to reproduce the problem somewhere we control ourselves instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have not successfully reproduced this outside of the Garmin page. I think we'd have to create a Facebook "like button" and serve some HTML containing it over HTTPS, which seems like a lot of work.

Instead, should I put this test behind a flag (so it's conditionally run)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Flag sounds good.

We shouldn't rely on the state of 3rd-party endpoints in our tests. Additionally, the client may not want us hitting their URLs this way.
@stephenmathieson stephenmathieson merged commit 591a701 into develop Jun 22, 2018
@stephenmathieson stephenmathieson deleted the fix-injection-loop branch June 22, 2018 15:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants