From 75db91b5b86ed7859f1b87cbe887a31635a76458 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 6 Mar 2023 19:47:07 -0300 Subject: [PATCH] ensureSecureProcotol --- ...ddProtocol.test.ts => ensureSecureProtocol.test.ts} | 10 +++++----- .../{addProtocol.ts => ensureSecureProtocol.ts} | 6 +++--- app/lib/methods/helpers/openLink.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) rename app/lib/methods/helpers/{addProtocol.test.ts => ensureSecureProtocol.test.ts} (65%) rename app/lib/methods/helpers/{addProtocol.ts => ensureSecureProtocol.ts} (60%) diff --git a/app/lib/methods/helpers/addProtocol.test.ts b/app/lib/methods/helpers/ensureSecureProtocol.test.ts similarity index 65% rename from app/lib/methods/helpers/addProtocol.test.ts rename to app/lib/methods/helpers/ensureSecureProtocol.test.ts index a4991792c..6650221eb 100644 --- a/app/lib/methods/helpers/addProtocol.test.ts +++ b/app/lib/methods/helpers/ensureSecureProtocol.test.ts @@ -1,20 +1,20 @@ -import addProtocol from './addProtocol'; +import ensureSecureProtocol from './ensureSecureProtocol'; describe('Add the protocol https at the begin of the URL', () => { it('return the link as original when sent with https at the begin', () => { const linkHttps = 'https://www.google.com'; - expect(addProtocol(linkHttps)).toBe(linkHttps); + expect(ensureSecureProtocol(linkHttps)).toBe(linkHttps); }); it('return the link as original when sent with http at the begin', () => { const linkHttp = 'http://www.google.com'; - expect(addProtocol(linkHttp)).toBe(linkHttp); + expect(ensureSecureProtocol(linkHttp)).toBe(linkHttp); }); it("return a new link with protocol at the begin when there isn't the protocol at the begin", () => { const linkWithoutProtocol = 'www.google.com'; - expect(addProtocol(linkWithoutProtocol)).toBe('https://www.google.com'); + expect(ensureSecureProtocol(linkWithoutProtocol)).toBe('https://www.google.com'); }); it('return the link correctly when the original starts with double slash, because the server is returning that', () => { const linkWithDoubleSlashAtBegin = '//www.google.com'; - expect(addProtocol(linkWithDoubleSlashAtBegin)).toBe('https://www.google.com'); + expect(ensureSecureProtocol(linkWithDoubleSlashAtBegin)).toBe('https://www.google.com'); }); }); diff --git a/app/lib/methods/helpers/addProtocol.ts b/app/lib/methods/helpers/ensureSecureProtocol.ts similarity index 60% rename from app/lib/methods/helpers/addProtocol.ts rename to app/lib/methods/helpers/ensureSecureProtocol.ts index 8688bbc64..1acfef6dd 100644 --- a/app/lib/methods/helpers/addProtocol.ts +++ b/app/lib/methods/helpers/ensureSecureProtocol.ts @@ -1,10 +1,10 @@ // If the link does not have the protocol at the beginning, we are inserting https as the default, -// since by conversion the most used is the secure protocol, with the same behavior as the web. -const addProtocol = (url: string): string => { +// since by convention the most used is the secure protocol, with the same behavior as the web. +const ensureSecureProtocol = (url: string): string => { if (!url.toLowerCase().startsWith('http')) { return `https://${url.replace('//', '')}`; } return url; }; -export default addProtocol; +export default ensureSecureProtocol; diff --git a/app/lib/methods/helpers/openLink.ts b/app/lib/methods/helpers/openLink.ts index 19bff6e37..45e3df5d6 100644 --- a/app/lib/methods/helpers/openLink.ts +++ b/app/lib/methods/helpers/openLink.ts @@ -5,7 +5,7 @@ import parse from 'url-parse'; import { themes } from '../../constants'; import { TSupportedThemes } from '../../../theme'; import UserPreferences from '../userPreferences'; -import addProtocol from './addProtocol'; +import ensureSecureProtocol from './ensureSecureProtocol'; export const DEFAULT_BROWSER_KEY = 'DEFAULT_BROWSER_KEY'; @@ -38,7 +38,7 @@ const appSchemeURL = (url: string, browser: string): string => { }; const openLink = async (url: string, theme: TSupportedThemes = 'light'): Promise => { - url = addProtocol(url); + url = ensureSecureProtocol(url); try { const browser = UserPreferences.getString(DEFAULT_BROWSER_KEY); if (browser === 'inApp') {