未验证 提交 3efdf122 编写于 作者: K kyle 提交者: GitHub

fix: add additionalQueryStringParams to auth requests (#4419)

* tests: add failing unit tests

* fix: add additionalQueryStringParams to auth requests
上级 911a140e
......@@ -140,17 +140,25 @@ export const authorizeAccessCodeWithBasicAuthentication = ( { auth, redirectUrl
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth, headers})
}
export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, errActions, oas3Selectors, specSelectors } ) => {
export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, errActions, oas3Selectors, specSelectors, authSelectors } ) => {
let { body, query={}, headers={}, name, url, auth } = data
let fetchUrl
let { additionalQueryStringParams } = authSelectors.getConfigs() || {}
let parsedUrl
if (specSelectors.isOAS3()) {
fetchUrl = parseUrl(url, oas3Selectors.selectedServer()).toString()
parsedUrl = parseUrl(url, oas3Selectors.selectedServer(), true)
} else {
fetchUrl = parseUrl(url, specSelectors.url()).toString()
parsedUrl = parseUrl(url, specSelectors.url(), true)
}
if(typeof additionalQueryStringParams === "object") {
parsedUrl.query = Object.assign({}, parsedUrl.query, additionalQueryStringParams)
}
const fetchUrl = parsedUrl.toString()
let _headers = Object.assign({
"Accept":"application/json, text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded"
......
......@@ -71,5 +71,77 @@ describe("auth plugin - actions", () => {
expect(system.fn.fetch.calls[0].arguments[0]).toInclude({url: expectedFetchUrl})
})
})
it("should add additionalQueryStringParams to Swagger 2.0 authorization and token URLs", () => {
// Given
const data = {
url: "/authorize?q=1"
}
const system = {
fn: {
fetch: createSpy().andReturn(Promise.resolve())
},
getConfigs: () => ({}),
authSelectors: {
getConfigs: () => ({
additionalQueryStringParams: {
myCustomParam: "abc123"
}
})
},
specSelectors: {
isOAS3: () => false,
operationScheme: () => "https",
host: () => "http://google.com",
url: () => "http://google.com/swagger.json"
}
}
// When
authorizeRequest(data)(system)
// Then
expect(system.fn.fetch.calls.length).toEqual(1)
expect(system.fn.fetch.calls[0].arguments[0].url)
.toEqual("http://google.com/authorize?q=1&myCustomParam=abc123")
})
it("should add additionalQueryStringParams to OpenAPI 3.0 authorization and token URLs", () => {
// Given
const data = {
url: "/authorize?q=1"
}
const system = {
fn: {
fetch: createSpy().andReturn(Promise.resolve())
},
getConfigs: () => ({}),
authSelectors: {
getConfigs: () => ({
additionalQueryStringParams: {
myCustomParam: "abc123"
}
})
},
oas3Selectors: {
selectedServer: () => "http://google.com"
},
specSelectors: {
isOAS3: () => true,
}
}
// When
authorizeRequest(data)(system)
// Then
expect(system.fn.fetch.calls.length).toEqual(1)
expect(system.fn.fetch.calls[0].arguments[0].url)
.toEqual("http://google.com/authorize?q=1&myCustomParam=abc123")
})
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册