Files
swagger-ui/test/core/plugins/auth/actions.js
Luka Žitnik e2d8a4e396 Fix(auth): improper resolution of relative token urls (#4180)
* fix(auth): improper resolution of relative token urls

* revert cc58ba7 for OAS2

In OAS2, relative token URLs are resolved against the host that serves the specs.
2018-04-05 19:20:20 -07:00

76 lines
1.8 KiB
JavaScript

/* eslint-env mocha */
import expect, { createSpy } from "expect"
import { authorizeRequest } from "corePlugins/auth/actions"
describe("auth plugin - actions", () => {
describe("authorizeRequest", () => {
[
[
{
oas3: true,
server: "https://host/resource",
scheme: "http",
host: null,
url: "http://specs/file",
},
"https://host/authorize"
],
[
{
oas3: false,
server: null,
scheme: "https",
host: undefined,
url: "https://specs/file",
},
"https://specs/authorize"
],
[
{
oas3: false,
server: null,
scheme: "https",
host: "host",
url: "http://specs/file",
},
"http://specs/authorize"
],
].forEach(([{oas3, server, scheme, host, url}, expectedFetchUrl]) => {
it("should resolve authorization endpoint against the server URL", () => {
// Given
const data = {
url: "/authorize"
}
const system = {
fn: {
fetch: createSpy().andReturn(Promise.resolve())
},
getConfigs: () => ({}),
authSelectors: {
getConfigs: () => ({})
},
oas3Selectors: {
selectedServer: () => server
},
specSelectors: {
isOAS3: () => oas3,
operationScheme: () => scheme,
host: () => host,
url: () => url
}
}
// When
authorizeRequest(data)(system)
// Then
expect(system.fn.fetch.calls.length).toEqual(1)
expect(system.fn.fetch.calls[0].arguments[0]).toInclude({url: expectedFetchUrl})
})
})
})
})