Repository: manusa/electronim
Pull request #258 (2023-01-07 06:36:05)

⬆ Bump @testing-library/dom to 8.19.1

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=manusa_electronim&pullRequest=258)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=258&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=258&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=258&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=258&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=258&metric=coverage&view=list) No Coverage information  
[![No Duplication information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=258&metric=duplicated_lines_density&view=list) No Duplication information



Patch:
diff --git a/package-lock.json b/package-lock.json
index 26f0fa4..8e18ed8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -39,7 +39,7 @@
         "electronim": "bin.js"
       },
       "devDependencies": {
-        "@testing-library/dom": "8.19.0",
+        "@testing-library/dom": "8.19.1",
         "@testing-library/user-event": "14.4.3",
         "chrome-tabs": "5.4.0",
         "css-loader": "6.7.3",
@@ -1427,14 +1427,14 @@
       }
     },
     "node_modules/@testing-library/dom": {
-      "version": "8.19.0",
-      "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.19.0.tgz",
-      "integrity": "sha512-6YWYPPpxG3e/xOo6HIWwB/58HukkwIVTOaZ0VwdMVjhRUX/01E4FtQbck9GazOOj7MXHc5RBzMrU86iBJHbI+A==",
+      "version": "8.19.1",
+      "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.19.1.tgz",
+      "integrity": "sha512-P6iIPyYQ+qH8CvGauAqanhVnjrnRe0IZFSYCeGkSRW9q3u8bdVn2NPI+lasFyVsEQn1J/IFmp5Aax41+dAP9wg==",
       "dev": true,
       "dependencies": {
         "@babel/code-frame": "^7.10.4",
         "@babel/runtime": "^7.12.5",
-        "@types/aria-query": "^4.2.0",
+        "@types/aria-query": "^5.0.1",
         "aria-query": "^5.0.0",
         "chalk": "^4.1.0",
         "dom-accessibility-api": "^0.5.9",
@@ -1468,9 +1468,9 @@
       }
     },
     "node_modules/@types/aria-query": {
-      "version": "4.2.2",
-      "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz",
-      "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==",
+      "version": "5.0.1",
+      "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
+      "integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==",
       "dev": true
     },
     "node_modules/@types/babel__core": {
@@ -9702,14 +9702,14 @@
       }
     },
     "@testing-library/dom": {
-      "version": "8.19.0",
-      "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.19.0.tgz",
-      "integrity": "sha512-6YWYPPpxG3e/xOo6HIWwB/58HukkwIVTOaZ0VwdMVjhRUX/01E4FtQbck9GazOOj7MXHc5RBzMrU86iBJHbI+A==",
+      "version": "8.19.1",
+      "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.19.1.tgz",
+      "integrity": "sha512-P6iIPyYQ+qH8CvGauAqanhVnjrnRe0IZFSYCeGkSRW9q3u8bdVn2NPI+lasFyVsEQn1J/IFmp5Aax41+dAP9wg==",
       "dev": true,
       "requires": {
         "@babel/code-frame": "^7.10.4",
         "@babel/runtime": "^7.12.5",
-        "@types/aria-query": "^4.2.0",
+        "@types/aria-query": "^5.0.1",
         "aria-query": "^5.0.0",
         "chalk": "^4.1.0",
         "dom-accessibility-api": "^0.5.9",
@@ -9731,9 +9731,9 @@
       "dev": true
     },
     "@types/aria-query": {
-      "version": "4.2.2",
-      "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz",
-      "integrity": "sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig==",
+      "version": "5.0.1",
+      "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
+      "integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==",
       "dev": true
     },
     "@types/babel__core": {
diff --git a/package.json b/package.json
index 6060693..65b96eb 100644
--- a/package.json
+++ b/package.json
@@ -172,7 +172,7 @@
     "verbose": true
   },
   "devDependencies": {
-    "@testing-library/dom": "8.19.0",
+    "@testing-library/dom": "8.19.1",
     "@testing-library/user-event": "14.4.3",
     "chrome-tabs": "5.4.0",
     "css-loader": "6.7.3",
diff --git a/src/tab-manager/redirect.js b/src/tab-manager/redirect.js
index a529840..0e778d5 100644
--- a/src/tab-manager/redirect.js
+++ b/src/tab-manager/redirect.js
@@ -40,12 +40,17 @@ const isOAuth = matchUrls([
   /^https:\/\/.+\.zoom\.us\/signin.*/ // NOSONAR
 ]);
 
+const isHandledInternally = matchUrls([
+  /^https:\/\/files\.slack\.com\/.*/ // NOSONAR
+]);
+
 const isSameOrigin = (browserViewUrl, url) => url.origin === browserViewUrl.origin;
 
 const shouldOpenInExternalBrowser = (browserView, url) => {
+  const browserViewUrl = new URL(browserView.webContents.getURL());
   let ret = true;
-  [isSameOrigin, isOAuth].forEach(f => {
-    if (ret && f(new URL(browserView.webContents.getURL()), url)) {
+  [isSameOrigin, isOAuth, isHandledInternally].forEach(f => {
+    if (ret && f(browserViewUrl, url)) {
       ret = false;
     }
   });
@@ -61,7 +66,7 @@ const handleRedirect = browserView => (e, urlString) => {
 };
 
 const windowOpenHandler = browserView => ({url}) => {
-  if (isSameOrigin(new URL(browserView.webContents.getURL()), new URL(url))) {
+  if (!shouldOpenInExternalBrowser(browserView, new URL(url))) {
     return {action: 'allow'};
   }
   shell.openExternal(url);


Test patch:
diff --git a/src/tab-manager/__tests__/redirect.test.js b/src/tab-manager/__tests__/redirect.test.js
index fe185d8..19d5262 100644
--- a/src/tab-manager/__tests__/redirect.test.js
+++ b/src/tab-manager/__tests__/redirect.test.js
@@ -35,6 +35,14 @@ describe('Tab Manager Redirect module test suite', () => {
         expect(result).toBe(true);
       });
     });
+    test.each([
+      'https://files.slack.com/files-pri/ID123/download/image.png?origin_team=ID456'
+    ])('URLs handled internally -isHandledInternally- (%s) , should return false', url => {
+      // When
+      const result = redirect.shouldOpenInExternalBrowser(mockBrowserView, new URL(url));
+      // Then
+      expect(result).toBe(false);
+    });
     describe('Google OAuth', () => {
       test('From OAuth to Slack, should return false', () => {
         // Given
@@ -223,14 +231,43 @@ describe('Tab Manager Redirect module test suite', () => {
       });
     });
   });
+  describe('handleRedirect', () => {
+    let event;
+    beforeEach(() => {
+      event = {preventDefault: jest.fn()};
+    });
+    describe('different origin and not handled', () => {
+      beforeEach(() => {
+        redirect.handleRedirect(mockBrowserView)(event, 'https://example.com/site-page');
+      });
+      test('should prevent default', () => {
+        expect(event.preventDefault).toHaveBeenCalled();
+      });
+      test('should open window in external browser', () => {
+        expect(require('electron').shell.openExternal).toHaveBeenCalledWith('https://example.com/site-page');
+      });
+    });
+  });
   describe('windowOpenHandler', () => {
-    test('same origin, opens window in Electron', () => {
+    test('same origin, opens window in Electron popup', () => {
       // When
       const result = redirect.windowOpenHandler(mockBrowserView)({url: 'http://localhost/terms-and-conditions'});
       // Then
       expect(result).toEqual({action: 'allow'});
     });
-    test('different origin, opens window in external browser', () => {
+    test('handled oauth, opens window in Electron popup', () => {
+      // When
+      const result = redirect.windowOpenHandler(mockBrowserView)({url: 'https://accounts.google.com/o/oauth2/auth'});
+      // Then
+      expect(result).toEqual({action: 'allow'});
+    });
+    test('handled internally, opens window in Electron popup', () => {
+      // When
+      const result = redirect.windowOpenHandler(mockBrowserView)({url: 'https://files.slack.com/files-pri/ID123/download/image.png?origin_team=ID456'});
+      // Then
+      expect(result).toEqual({action: 'allow'});
+    });
+    test('different origin and not handled, opens window in external browser', () => {
       // When
       const result = redirect.windowOpenHandler(mockBrowserView)({url: 'https://example.com/site-page'});
       // Then