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

GPII-4410: Making links work without the extension #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

stegru
Copy link
Member

@stegru stegru commented May 27, 2020

This makes the entire destination URL be specified. That way, a https link can be specified, without requiring the request url to be https.

Also, /request is at the start of the path to allow it to be passed easily to the shared listener on morphic, for when the extension isn't installed - so the url will always be a valid url which points to the destination.

Example: http://opensametab.morphic.org/redirect/https%3A%2F%2Fexample.com

@jobara jobara requested a review from amb26 May 27, 2020 17:19
Comment on lines 61 to 67
try {
const destinationUrl = new URL(destination);
openURLs.openTab(destinationUrl, refresh);
success = true;
} catch (e) {
success = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It appears that this try/catch block is to guard against malformed URLs used for the destinationUrl. e.g. refresh/https%3A%2F%2Fexample.com%2F. However, openURLs is an async function. So I don't believe that it will wait to make sure that it doesn't throw an error. You could use await on openURLs but will need to convert openURLs.handleRequest into an async function as well. According to webRequest.onBeforeRequest the handler can return a promise that resolves with a BlockingResponse. You'll also have to test that the polyfill can handle this feature for use in Chrome.

Copy link
Member Author

Choose a reason for hiding this comment

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

YEs. In fact, that's why I moved the url parsing out of openURLs.

However, I've now moved the call outside of the try block to make my intention clearer.

},
expected: {
response: {cancel: true},
args: ["http://morphic.org/actual.org/url", false]
args: [new URL("http://morphic.org/redirect/https%3A%2F%2Factual.org/url"), false]
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need test cases for when the response is {cancel: false}.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

@stegru stegru left a comment

Choose a reason for hiding this comment

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

oops, I didn't mean to start a review

try {
destinationUrl = new URL(destination);
} catch (e) {
// ignored
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it might be helpful to log the error in a meaningful way. It likely won't make a difference for most end users, but for someone who is developing and runs into this case, it will hopefully help track things down quicker.

}, {
name: "Bad URL",
details: {
url: "http://morphic.org/redirect/stupid"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see where you're going with this, but wonder if it would be more appropriate to replace "stupid" with something like "incorrect", "broken", "invalid" or something along those lines.

Copy link

@GreggVan GreggVan Sep 14, 2020

Choose a reason for hiding this comment

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

Yes please change to what you think is most accurate term

@@ -184,7 +193,7 @@
let response = openURLs.handleRequest(testCase.details);
jqUnit.assertDeepEq(`${testCase.name}: the response is returned correctly`, testCase.expected.response, response);

let isOpenTabCalledProperly = openTabStub.calledOnceWithExactly.apply(openTabStub, testCase.expected.args);
let isOpenTabCalledProperly = !testCase.expected.args || openTabStub.calledOnceWithExactly.apply(openTabStub, testCase.expected.args);
Copy link
Collaborator

@jobara jobara Jun 2, 2020

Choose a reason for hiding this comment

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

I worry that by just passing any test that has a falsey value for args would allow tests that forget to add the args value to keep erroneously pass. Instead, I think we should provide an error flag in the expected object. If that is present, we make sure that openTabStub is not called at all; which I believe can be done using openTabStub.notCalled.

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.

3 participants