From 9b1a6141dfded938757aaf8d60c0ab6f562a9f08 Mon Sep 17 00:00:00 2001 From: AlexVangelov Date: Fri, 15 Sep 2017 15:57:41 -0400 Subject: [PATCH 1/3] OAuth2 authorizationUrl with extra query parameters (should include double '?') --- src/core/oauth2-authorize.js | 3 ++- test/core/oauth2-authorize.js | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/core/oauth2-authorize.js diff --git a/src/core/oauth2-authorize.js b/src/core/oauth2-authorize.js index 2e36010e..3c0b15cc 100644 --- a/src/core/oauth2-authorize.js +++ b/src/core/oauth2-authorize.js @@ -64,7 +64,8 @@ export default function authorize ( { auth, authActions, errActions, configs, au } } - let url = [schema.get("authorizationUrl"), query.join("&")].join("?") + let authorizationUrl = schema.get("authorizationUrl"); + let url = [authorizationUrl, query.join("&")].join(authorizationUrl.indexOf('?') === -1 ? "?" : "&") // pass action authorizeOauth2 and authentication data through window // to authorize with oauth2 diff --git a/test/core/oauth2-authorize.js b/test/core/oauth2-authorize.js new file mode 100644 index 00000000..e6c76a6d --- /dev/null +++ b/test/core/oauth2-authorize.js @@ -0,0 +1,39 @@ +/* eslint-env mocha */ +import expect, { createSpy } from "expect" +import { fromJS } from "immutable" +import win from "core/window" +import oauth2Authorize from "core/oauth2-authorize" + +describe("OAuth2", function () { + + let mockSchema = { + flow: 'accessCode', + authorizationUrl: 'https://testAuthorizationUrl' + }; + + let authConfig = { + auth: { schema: { get: (key)=> mockSchema[key] } }, + authActions: {}, + errActions: {}, + configs: { oauth2RedirectUrl: "" }, + authConfigs: {} + }; + + describe("authorize redirect", function () { + + it("should build redirectUrl", function() { + win.open = createSpy(); + oauth2Authorize(authConfig); + expect(win.open.calls.length).toEqual(1); + expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&state="); + }); + + it("should build correct redirectUrl from authorizeUrl with query parameters", function() { + win.open = createSpy(); + mockSchema.authorizationUrl = 'https://testAuthorizationUrl?param=1'; + oauth2Authorize(authConfig); + expect(win.open.calls.length).toEqual(1); + expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&state="); + }); + }); +}); From 4172e33e0495bbcb35d0297adb8a5a19b1252412 Mon Sep 17 00:00:00 2001 From: AlexVangelov Date: Fri, 15 Sep 2017 20:52:55 -0400 Subject: [PATCH 2/3] satisfy project lint rules --- src/core/oauth2-authorize.js | 4 ++-- test/core/oauth2-authorize.js | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/oauth2-authorize.js b/src/core/oauth2-authorize.js index 3c0b15cc..fd3a4afc 100644 --- a/src/core/oauth2-authorize.js +++ b/src/core/oauth2-authorize.js @@ -64,8 +64,8 @@ export default function authorize ( { auth, authActions, errActions, configs, au } } - let authorizationUrl = schema.get("authorizationUrl"); - let url = [authorizationUrl, query.join("&")].join(authorizationUrl.indexOf('?') === -1 ? "?" : "&") + let authorizationUrl = schema.get("authorizationUrl") + let url = [authorizationUrl, query.join("&")].join(authorizationUrl.indexOf("?") === -1 ? "?" : "&") // pass action authorizeOauth2 and authentication data through window // to authorize with oauth2 diff --git a/test/core/oauth2-authorize.js b/test/core/oauth2-authorize.js index e6c76a6d..1d99cdce 100644 --- a/test/core/oauth2-authorize.js +++ b/test/core/oauth2-authorize.js @@ -7,9 +7,9 @@ import oauth2Authorize from "core/oauth2-authorize" describe("OAuth2", function () { let mockSchema = { - flow: 'accessCode', - authorizationUrl: 'https://testAuthorizationUrl' - }; + flow: "accessCode", + authorizationUrl: "https://testAuthorizationUrl" + } let authConfig = { auth: { schema: { get: (key)=> mockSchema[key] } }, @@ -17,23 +17,23 @@ describe("OAuth2", function () { errActions: {}, configs: { oauth2RedirectUrl: "" }, authConfigs: {} - }; + } describe("authorize redirect", function () { it("should build redirectUrl", function() { - win.open = createSpy(); - oauth2Authorize(authConfig); - expect(win.open.calls.length).toEqual(1); - expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&state="); - }); + win.open = createSpy() + oauth2Authorize(authConfig) + expect(win.open.calls.length).toEqual(1) + expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&state=") + }) it("should build correct redirectUrl from authorizeUrl with query parameters", function() { - win.open = createSpy(); - mockSchema.authorizationUrl = 'https://testAuthorizationUrl?param=1'; - oauth2Authorize(authConfig); - expect(win.open.calls.length).toEqual(1); - expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&state="); - }); - }); -}); + win.open = createSpy() + mockSchema.authorizationUrl = "https://testAuthorizationUrl?param=1" + oauth2Authorize(authConfig) + expect(win.open.calls.length).toEqual(1) + expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&state=") + }) + }) +}) From c1abdfb1c47cfdc8b246dacd95d8af7110c70959 Mon Sep 17 00:00:00 2001 From: AlexVangelov Date: Fri, 15 Sep 2017 21:04:38 -0400 Subject: [PATCH 3/3] follow lowercase naming convention in tests --- test/core/oauth2-authorize.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/oauth2-authorize.js b/test/core/oauth2-authorize.js index 1d99cdce..c4fed4ba 100644 --- a/test/core/oauth2-authorize.js +++ b/test/core/oauth2-authorize.js @@ -4,7 +4,7 @@ import { fromJS } from "immutable" import win from "core/window" import oauth2Authorize from "core/oauth2-authorize" -describe("OAuth2", function () { +describe("oauth2", function () { let mockSchema = { flow: "accessCode", @@ -21,14 +21,14 @@ describe("OAuth2", function () { describe("authorize redirect", function () { - it("should build redirectUrl", function() { + it("should build authorize url", function() { win.open = createSpy() oauth2Authorize(authConfig) expect(win.open.calls.length).toEqual(1) expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&state=") }) - it("should build correct redirectUrl from authorizeUrl with query parameters", function() { + it("should append query paramters to authorizeUrl with query parameters", function() { win.open = createSpy() mockSchema.authorizationUrl = "https://testAuthorizationUrl?param=1" oauth2Authorize(authConfig)