From 5e2806662cba9e5fa532e9d837a0ee9b4564d125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 11 Jan 2021 13:20:10 +0100 Subject: [PATCH] allow indexing for public chats and browser links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disables indexing for users and groups chats using robot meta tag. Signed-off-by: Jakub Sokołowski --- routes/index.js | 3 +++ tests/main.js | 8 ++++++++ views/index.ejs | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/routes/index.js b/routes/index.js index 69d2fb7..8a8ec4d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -101,6 +101,7 @@ const handleChatKey = (req, res) => { mainTarget: chatKey, headerName: chatName, path: req.originalUrl, + noindex: true, }) } @@ -120,6 +121,7 @@ const handleEnsName = (req, res) => { mainTarget: username, headerName: `@${utils.showSpecialChars(username)}`, path: req.originalUrl, + noindex: true, }) } @@ -166,6 +168,7 @@ const handleGroupChat = (req, res) => { mainTarget: groupName, headerName: groupName, path: req.originalUrl, + noindex: true, }) } diff --git a/tests/main.js b/tests/main.js index 3e95d14..02ae471 100644 --- a/tests/main.js +++ b/tests/main.js @@ -17,11 +17,13 @@ const get = (path) => srv.get(path).set('Host', host).set('X-Forwarded-Proto', p const q = (res, query) => cheerio.load(res.text)(query) const html = (res, query) => (cheerio.load(res.text)(query).html() || "").trim() const meta = (res, name) => q(res, `meta[property="${name}"]`).attr('content') +const robo = (res) => q(res, 'meta[name="robots"]').attr('content') test('test browser routes', t => { t.test('/b/ens.domains - VALID', async t => { const res = await get('/b/ens.domains') t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), undefined, 'indexing is enabled') t.eq(meta(res, 'status-im:target'), 'ens.domains', 'contains target') t.eq(meta(res, 'al:ios:url'), 'status-im://b/ens.domains', 'contains ios url') t.eq(meta(res, 'al:android:url'), 'status-im://b/ens.domains', 'contains android url') @@ -47,6 +49,7 @@ test('test user ens routes', t => { t.test('/u/jakubgs.eth - VALID', async t => { const res = await get('/u/jakubgs.eth') t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), 'noindex', 'indexing is disabled') t.eq(meta(res, 'al:ios:url'), 'status-im://u/jakubgs.eth', 'contains ios url') t.eq(meta(res, 'al:android:url'), 'status-im://u/jakubgs.eth', 'contains android url') t.eq(html(res, 'div#info'), 'Chat and transact with @jakubgs.eth in Status.', 'contains prompt') @@ -75,6 +78,7 @@ test('test chat key routes', t => { t.test(`/u/0x04${chatKey.substr(0,8)}... - VALID`, async t => { const res = await get(`/u/0x04${chatKey}`) t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), 'noindex', 'indexing is disabled') t.eq(meta(res, 'al:ios:url'), `status-im://u/0x04${chatKey}`, 'contains ios url') t.eq(meta(res, 'al:android:url'), `status-im://u/0x04${chatKey}`, 'contains android url') t.eq(html(res, 'div#info'), `Chat and transact with 0x04${chatKey} in Status.`, 'contains prompt') @@ -107,6 +111,7 @@ test('test multibase chat key routes', t => { t.test(`/u/${multibaseKey.substr(0,12)}... - VALID`, async t => { const res = await get(`/u/${multibaseKey}`) t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), 'noindex', 'indexing is disabled') t.eq(meta(res, 'al:ios:url'), `status-im://u/${multibaseKey}`, 'contains ios url') t.eq(meta(res, 'al:android:url'), `status-im://u/${multibaseKey}`, 'contains android url') t.eq(html(res, 'div#info'), `Chat and transact with ${multibaseKey} in Status.`, 'contains prompt') @@ -126,6 +131,7 @@ test('test compressed chat key routes', t => { t.test(`/u/${compressedKey.substr(0,12)}... - VALID`, async t => { const res = await get(`/u/${compressedKey}`) t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), 'noindex', 'indexing is disabled') t.eq(meta(res, 'al:ios:url'), `status-im://u/${compressedKey}`, 'contains ios url') t.eq(meta(res, 'al:android:url'), `status-im://u/${compressedKey}`, 'contains android url') t.eq(html(res, 'div#info'), `Chat and transact with ${compressedKey} in Status.`, 'contains prompt') @@ -143,6 +149,7 @@ test('test public channel routes', t => { t.test('/status-test - VALID', async t => { const res = await get('/status-test') t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), undefined, 'indexing is enabled') t.eq(meta(res, 'al:ios:url'), 'status-im://status-test', 'contains ios url') t.eq(meta(res, 'al:android:url'), 'status-im://status-test', 'contains android url') t.eq(html(res, 'div#info'), 'Join public channel #status-test in Status.', 'contains prompt') @@ -166,6 +173,7 @@ test('group chat routes', t => { t.test('/g/args?a1=Secret%20Club&... - VALID', async t => { const res = await get(`/g/args?a=${adminKey}&a1=${groupName}&a2=${groupKey}`) t.eq(res.status, 200, 'returns 200') + t.eq(robo(res), 'noindex', 'indexing is disabled') t.eq(meta(res, 'al:ios:url'), `status-im://g/args?a=${adminKey}&a1=${groupName}&a2=${groupKey}`, 'contains ios url') t.eq(meta(res, 'al:android:url'), `status-im://g/args?a=${adminKey}&a1=${groupName}&a2=${groupKey}`, 'contains android url') t.eq(html(res, 'div#info'), 'Join group chat Secret Club in Status.', 'contains prompt') diff --git a/views/index.ejs b/views/index.ejs index 23faacd..85e6a24 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -43,6 +43,11 @@ <% } -%> +<% if (locals.noindex) { -%> + + +<% } -%> +