From 3d11ba28271b14c24166361c276264e9403a67ad Mon Sep 17 00:00:00 2001 From: Michael Oberwasserlechner Date: Tue, 11 Apr 2023 19:57:08 +0200 Subject: [PATCH] chore(): Prepare release 4.0.2 --- CHANGELOG.md | 11 +++++++++-- package-lock.json | 4 ++-- package.json | 2 +- src/web-utils.test.ts | 42 +++++++++++++++++++++++++++++++++++------- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de3938a..5dacc830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ # Changelog +## [4.0.2] - 2023-04-11 + +### Fixed + +* Web: Parse url parameters for search and hash properly [#183](https://github.com/moberwasserlechner/capacitor-oauth2/pull/183), [#182](https://github.com/moberwasserlechner/capacitor-oauth2/issues/182). Thank you, [@jvartanian](https://github.com/jvartanian) + ## [4.0.1] - 2023-04-11 ### Fixed -* Android: Additional `id_token` argument for logout method [#192](https://github.com/moberwasserlechner/capacitor-oauth2/issues/233). Thank you [@svzi](https://github.com/svzi) +* Android: Additional `id_token` argument for logout method [#233](https://github.com/moberwasserlechner/capacitor-oauth2/pull/233). Thank you, [@svzi](https://github.com/svzi) ### Chore @@ -133,7 +139,8 @@ This is controlled by Android specific parameters `handleResultOnNewIntent` for - Android: Fix Java compiler error #36 (thx @Anthbs) - Fix github security error by updating Jest lib -[Unreleased]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/4.0.1...main +[Unreleased]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/4.0.2...main +[4.0.2]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/4.0.1...4.0.2 [4.0.1]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/4.0.0...4.0.1 [4.0.0]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/3.0.1...4.0.0 [3.0.1]: https://github.com/moberwasserlechner/capacitor-oauth2/compare/3.0.0...3.0.1 diff --git a/package-lock.json b/package-lock.json index eb5a281c..b3ece37e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@byteowls/capacitor-oauth2", - "version": "4.0.1", + "version": "4.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@byteowls/capacitor-oauth2", - "version": "4.0.1", + "version": "4.0.2", "license": "MIT", "devDependencies": { "@capacitor/android": "4.2.0", diff --git a/package.json b/package.json index e60fae32..a1c7ef41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@byteowls/capacitor-oauth2", - "version": "4.0.1", + "version": "4.0.2", "description": "Capacitor OAuth 2 client plugin", "author": "Michael Oberwasserlechner", "homepage": "https://github.com/moberwasserlechner/capacitor-oauth2", diff --git a/src/web-utils.test.ts b/src/web-utils.test.ts index d391a8a9..18475531 100644 --- a/src/web-utils.test.ts +++ b/src/web-utils.test.ts @@ -140,31 +140,36 @@ describe('web options', () => { describe("Url param extraction", () => { - it('should return null on null url', () => { + it('should return undefined on null url', () => { const paramObj = WebUtils.getUrlParams(null!); expect(paramObj).toBeUndefined(); }); - it('should return null on empty url', () => { + it('should return undefined on empty url', () => { const paramObj = WebUtils.getUrlParams(""); expect(paramObj).toBeUndefined(); }); - it('should return null on url with spaces', () => { + it('should return undefined on url with spaces', () => { const paramObj = WebUtils.getUrlParams(" "); expect(paramObj).toBeUndefined(); }); - it('should return null if no params in url', () => { + it('should return undefined if no params in url', () => { const paramObj = WebUtils.getUrlParams("https://app.example.com/"); expect(paramObj).toBeUndefined(); }); - it('should return null if no params in url', () => { + it('should return undefined if no params in url search', () => { const paramObj = WebUtils.getUrlParams("https://app.example.com?"); expect(paramObj).toBeUndefined(); }); + it('should return undefined if no params in url hash', () => { + const paramObj = WebUtils.getUrlParams("https://app.example.com#"); + expect(paramObj).toBeUndefined(); + }); + it('should remove invalid combinations one param', () => { const paramObj = WebUtils.getUrlParams("https://app.example.com?=test"); expect(paramObj).toBeUndefined(); @@ -182,7 +187,7 @@ describe("Url param extraction", () => { it('should extract a uuid state param', () => { const state = WebUtils.randomString(); - const paramObj = WebUtils.getUrlParams("https://app.example.com?state=" + state + "&access_token=testtoken"); + const paramObj = WebUtils.getUrlParams(`https://app.example.com?state=${state}&access_token=testtoken`); expect(paramObj!["state"]).toStrictEqual(state); }); @@ -191,7 +196,15 @@ describe("Url param extraction", () => { const foo = WebUtils.randomString(); const paramObj = WebUtils.getUrlParams(`https://app.example.com?random=${random}&foo=${foo}#ignored`); expect(paramObj!["random"]).toStrictEqual(random); - expect(paramObj!["foo"]).toStrictEqual(`${foo}`); + expect(paramObj!["foo"]).toStrictEqual(foo); + }); + + it('should use query flag with another question mark in a param', () => { + const random = WebUtils.randomString(); + const foo = WebUtils.randomString(); + const paramObj = WebUtils.getUrlParams(`https://app.example.com?random=${random}&foo=${foo}?questionmark`); + expect(paramObj!["random"]).toStrictEqual(random); + expect(paramObj!["foo"]).toStrictEqual(`${foo}?questionmark`); }); it('should use hash flag and ignore query flag', () => { @@ -202,6 +215,14 @@ describe("Url param extraction", () => { expect(paramObj!["foo"]).toStrictEqual(`${foo}?ignored`); }); + it('should use hash flag with another hash in a param', () => { + const random = WebUtils.randomString(); + const foo = WebUtils.randomString(); + const paramObj = WebUtils.getUrlParams(`https://app.example.com#random=${random}&foo=${foo}#hash`); + expect(paramObj!["random"]).toStrictEqual(random); + expect(paramObj!["foo"]).toStrictEqual(`${foo}#hash`); + }); + it('should extract hash params correctly', () => { const random = WebUtils.randomString(20); const url = `http://localhost:4200/#state=${random}&access_token=ya29.a0ARrdaM-sdfsfsdfsdfsdfs-YGFHwg_lM6dePPaT_TunbpsdfsdfsdfsEG6vTVLsLJDDW @@ -213,6 +234,13 @@ describe("Url param extraction", () => { expect(paramObj!["prompt"]).toBeDefined(); expect(paramObj!["state"]).toStrictEqual(random); }); + + it('should extract hash params if search param indicator present', () => { + const token = "sldfskdjflsdf12302"; + const url = `http://localhost:3000/login?#access_token=${token}`; + const paramObj = WebUtils.getUrlParams(url); + expect(paramObj!["access_token"]).toStrictEqual(token); + }) }); describe("Random string gen", () => {