From 6c55fcb71c9510f2ec6ceec628ba11f409c91597 Mon Sep 17 00:00:00 2001 From: Paul Bunkham Date: Fri, 14 Feb 2020 20:12:01 +0000 Subject: [PATCH] Add tests for invalid embed codes and URLs This also adds a check that the host of the URL includes OpenTable --- extensions/blocks/opentable/test/utils.js | 16 ++++++++++++++++ extensions/blocks/opentable/utils.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/blocks/opentable/test/utils.js b/extensions/blocks/opentable/test/utils.js index 7cc2951c5c54e..a11794a0387f6 100644 --- a/extensions/blocks/opentable/test/utils.js +++ b/extensions/blocks/opentable/test/utils.js @@ -9,6 +9,8 @@ import { getAttributesFromEmbedCode } from '../utils'; const widgetEmbedCode = ""; +const invalidEmbedCode = ""; + const marketingUrl = "https://www.opentable.com/vongs-thai-kitchen-reservations-chicago?restref=1&lang=en-US&ot_source=Restaurant%20website"; const customUrl1 = "https://www.opentable.com/restref/client/?restref=412810&lang=en-US&ot_source=Restaurant%20website&corrid=e413926b-0352-46d6-a8d8-d1d525932310"; @@ -17,6 +19,8 @@ const customUrl2 = "https://www.opentable.com/restref/client/?restref=1&lang=es- const customUrl3 = "https://www.opentable.com/restref/client/?rid=1&corrid=010a3136-569e-42a5-a381-e111887b4cf5"; +const invalidUrl = "https://www.widgets-r-us.com/widget/widgetygoddness?rid=1&type=standard&theme=standard&iframe=true&domain=com&lang=en-US&newtab=false&ot_source=Restaurant%20website"; + describe( 'getAttributesFromEmbedCode', () => { test( 'Widget embed code', () => { expect( @@ -75,4 +79,16 @@ describe( 'getAttributesFromEmbedCode', () => { } ); } ); + + test( 'Invaild Embed Code', () => { + expect( + getAttributesFromEmbedCode( invalidEmbedCode ) + ).toBeUndefined(); + } ); + + test( 'Invaild URL', () => { + expect( + getAttributesFromEmbedCode( invalidUrl ) + ).toBeUndefined(); + } ); } ); diff --git a/extensions/blocks/opentable/utils.js b/extensions/blocks/opentable/utils.js index 4d40a25afec83..4f1f0d344b9b5 100644 --- a/extensions/blocks/opentable/utils.js +++ b/extensions/blocks/opentable/utils.js @@ -10,7 +10,7 @@ const getAttributesFromUrl = url => { src = new URL( 'http:' + url ); } - if ( ! src.search ) { + if ( ! src.host || src.host.indexOf( 'opentable' ) === -1 || ! src.search ) { return; }