From 7a4e65cef9468a20fb32dc112aa7113345bc76c5 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Fri, 8 Apr 2022 13:05:39 -0700 Subject: [PATCH] Fix websocketonly flag (#6126) * Fixed issue where webSocketOnly was incorrectly set to nodeAdmin Co-authored-by: Maneesh Tewani --- .changeset/twenty-shoes-cheer.md | 5 +++ CONTRIBUTING.md | 2 +- README.md | 14 ++++++++ .../database/src/core/util/libs/parser.ts | 2 +- packages/database/test/parser.test.ts | 34 +++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .changeset/twenty-shoes-cheer.md create mode 100644 packages/database/test/parser.test.ts diff --git a/.changeset/twenty-shoes-cheer.md b/.changeset/twenty-shoes-cheer.md new file mode 100644 index 00000000000..5b2f43d20f4 --- /dev/null +++ b/.changeset/twenty-shoes-cheer.md @@ -0,0 +1,5 @@ +--- +"@firebase/database": patch +--- + +Fix issue where if a websocket protocol was used in the databaseURL, `webSocketOnly` field was incorrectly set to undefined. (When using `wss` or `ws` protocols in the databaseURL, webSocketOnly will be true and longPolling will be disabled) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2b4e6fb104e..8684de9a07e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,7 +77,7 @@ Before you start working on a larger contribution, you should get in touch with * Create your patch, **including appropriate test cases**. Patches with tests are more likely to be merged. * Avoid checking in files that shouldn't be tracked (e.g `node_modules`, `gulp-cache`, `.tmp`, `.idea`). If your development setup automatically creates some of these files, please add them to the `.gitignore` at the root of the package (click [here][gitignore] to read more on how to add entries to the `.gitignore`). -* Commit your changes using a commit message that follows our [commit message guidelines](#commit-message-guidelines). +* Commit your changes ```shell git commit -a diff --git a/README.md b/README.md index 3e04371b1d4..f9810c99638 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,20 @@ implementation. The SDK is built via a combination of all of these packages which are published under the [`firebase` scope](https://www.npmjs.com/search?q=scope%3Afirebase) on NPM. +### Testing the SDK Locally + +Please be sure to build your repo before proceeding any further. +In order to manually test your SDK changes locally, you must use [yarn link](https://classic.yarnpkg.com/en/docs/cli/link): + +```shell +$ cd packages/firebase +$ yarn link # initialize the linking to the other folder +$ cd ../ # cd into your personal project directory +$ yarn link firebase # tell yarn to use the locally built firebase SDK instead +``` + +This will create a symlink and point your `` to the locally built version of the firebase SDK. + ### Helper Scripts Each package in the `packages` directory exposes a `dev` script. This script diff --git a/packages/database/src/core/util/libs/parser.ts b/packages/database/src/core/util/libs/parser.ts index 92be50daa2f..61fcef35979 100644 --- a/packages/database/src/core/util/libs/parser.ts +++ b/packages/database/src/core/util/libs/parser.ts @@ -92,8 +92,8 @@ export const parseRepoInfo = function ( parsedUrl.host, parsedUrl.secure, namespace, - nodeAdmin, webSocketOnly, + nodeAdmin, /*persistenceKey=*/ '', /*includeNamespaceInQueryParams=*/ namespace !== parsedUrl.subdomain ), diff --git a/packages/database/test/parser.test.ts b/packages/database/test/parser.test.ts new file mode 100644 index 00000000000..9776d0a1fa6 --- /dev/null +++ b/packages/database/test/parser.test.ts @@ -0,0 +1,34 @@ +/** + * @license + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; + +import { parseRepoInfo } from '../src/core/util/libs/parser'; + +describe('parser', () => { + it('should set websocketUrl correctly based on the protocol', () => { + const httpsRepoInfo = parseRepoInfo( + 'https://test-ns.firebaseio.com', + false + ); + expect(httpsRepoInfo.repoInfo.webSocketOnly).to.equal(false); + const wssRepoInfo = parseRepoInfo('wss://test-ns.firebaseio.com', false); + expect(wssRepoInfo.repoInfo.webSocketOnly).to.equal(true); + const wsRepoInfo = parseRepoInfo('ws://test-ns.firebaseio.com', false); + expect(wsRepoInfo.repoInfo.webSocketOnly).to.equal(true); + }); +});