-
Notifications
You must be signed in to change notification settings - Fork 0
amp runtime should respect the whitelist of actions specified in meta #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import {StandardActions} from '../../src/service/standard-actions-impl'; | |
| import {Services} from '../../src/services'; | ||
| import {installHistoryServiceForDoc} from '../../src/service/history-impl'; | ||
| import {setParentWindow} from '../../src/service'; | ||
| import {createElementWithAttributes} from '../../src/dom'; | ||
|
|
||
|
|
||
| describes.sandboxed('StandardActions', {}, () => { | ||
|
|
@@ -352,6 +353,64 @@ describes.sandboxed('StandardActions', {}, () => { | |
| standardActions.handleAmpTarget(invocation); | ||
| expect(printStub).to.be.calledOnce; | ||
| }); | ||
|
|
||
| it('should not implement print when not whitelisted', () => { | ||
| window.document.head.appendChild( | ||
| createElementWithAttributes(window.document, 'meta', { | ||
| name: 'amp-action-whitelist', | ||
| content: 'pushState,setState', | ||
| })); | ||
|
|
||
| standardActions = new StandardActions(ampdoc); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also done in beforeEach, no? It's the same
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is done in beforeEach as well, but the problem is back in beforeEach there is no meta tag present in the document
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To your comment below: The whitelist is created in the constructor of the StandardAction. By the time the constructor is called we have appended the meta tag child. I did what you are suggesting and the test fails for the reason I explained. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhh sorry, I forgot the constructor is caching the meta tag content. |
||
|
|
||
| const windowApi = { | ||
| print: () => {}, | ||
| }; | ||
| const printStub = sandbox.stub(windowApi, 'print'); | ||
| const invocation = { | ||
| method: 'print', | ||
| satisfiesTrust: () => true, | ||
| target: { | ||
| ownerDocument: { | ||
| defaultView: windowApi, | ||
| }, | ||
| }, | ||
| }; | ||
| expect(() => standardActions.handleAmpTarget(invocation)).to.throw(); | ||
| expect(printStub).to.not.be.called; | ||
| }); | ||
|
|
||
| it('should implement pushState when whitelisted', () => { | ||
| window.document.head.appendChild( | ||
| createElementWithAttributes(window.document, 'meta', { | ||
| name: 'amp-action-whitelist', | ||
| content: 'setState, pushState', | ||
| })); | ||
|
|
||
| standardActions = new StandardActions(ampdoc); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
|
||
| const pushStateWithExpression = sandbox.stub(); | ||
| // Bind.pushStateWithExpression() doesn't resolve with a value, | ||
| // but add one here to check that the promise is chained. | ||
| pushStateWithExpression.returns(Promise.resolve('push-state-complete')); | ||
|
|
||
| window.services.bind = { | ||
| obj: {pushStateWithExpression}, | ||
| }; | ||
|
|
||
| const args = { | ||
| [OBJECT_STRING_ARGS_KEY]: '{foo: 123}', | ||
| }; | ||
| const target = ampdoc; | ||
| const satisfiesTrust = () => true; | ||
| const pushState = {method: 'pushState', args, target, satisfiesTrust}; | ||
|
|
||
| return standardActions.handleAmpTarget(pushState, 0, []).then(result => { | ||
| expect(result).to.equal('push-state-complete'); | ||
| expect(pushStateWithExpression).to.be.calledOnce; | ||
| expect(pushStateWithExpression).to.be.calledWith('{foo: 123}'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describes.fakeWin('adoptEmbedWindow', {}, env => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80 column limit.
gulp presubmitshould catch this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done this for the actual pull request ampproject#13192