feat: apply cumulative update to address various issues (#10324)

This commit is contained in:
Vladimír Gorej
2025-02-27 11:12:42 +01:00
committed by GitHub
parent 621a7f0f76
commit 80d56c9518
298 changed files with 11066 additions and 11680 deletions

View File

@@ -15,6 +15,11 @@ import makeGetSampleSchema from "core/plugins/json-schema-5-samples/fn/get-sampl
import makeGetJsonSampleSchema from "core/plugins/json-schema-5-samples/fn/get-json-sample-schema"
import makeGetYamlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-yaml-sample-schema"
import makeGetXmlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-xml-sample-schema"
import { foldType } from "core/plugins/json-schema-2020-12-samples/fn/index"
import {
makeGetType,
isBooleanJSONSchema,
} from "core/plugins/json-schema-2020-12/fn.js"
describe("bug #4557: default parameter values", function () {
it("should apply a Swagger 2.0 default value", function () {
@@ -47,6 +52,10 @@ describe("bug #4557: default parameter values", function () {
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
})
const props = {
@@ -105,6 +114,10 @@ describe("bug #4557: default parameter values", function () {
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
mergeJsonSchema,
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
})
const props = {

View File

@@ -48,6 +48,6 @@ describe("<OperationTag/>", function(){
const renderedLink = wrapper.find("Link")
expect(renderedLink.length).toEqual(1)
expect(renderedLink.props().href).toEqual("http://swagger.io")
expect(renderedLink.props().href).toEqual("http://swagger.io/")
})
})

View File

@@ -8,6 +8,7 @@ import {Collapse} from "core/components/layout-utils"
const components = {
Collapse,
DeepLink,
// eslint-disable-next-line react/prop-types
OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />,
OperationTag: "div",
}

View File

@@ -15,6 +15,11 @@ import makeGetSampleSchema from "core/plugins/json-schema-5-samples/fn/get-sampl
import makeGetJsonSampleSchema from "core/plugins/json-schema-5-samples/fn/get-json-sample-schema"
import makeGetYamlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-yaml-sample-schema"
import makeGetXmlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-xml-sample-schema"
import { foldType } from "core/plugins/json-schema-2020-12-samples/fn/index"
import {
makeGetType,
isBooleanJSONSchema,
} from "core/plugins/json-schema-2020-12/fn.js"
describe("<ParameterRow/>", () => {
const createProps = ({ param, isOAS3 }) => {
@@ -33,6 +38,10 @@ describe("<ParameterRow/>", () => {
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
mergeJsonSchema,
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
oas3Selectors: { activeExamplesMember: () => {} },
getConfigs: () => ({}),
@@ -173,6 +182,10 @@ describe("bug #5573: zero default and example values", function () {
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
getConfigs: () => {
return {}
@@ -225,6 +238,10 @@ describe("bug #5573: zero default and example values", function () {
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
})
const props = {
@@ -279,6 +296,10 @@ describe("bug #5573: zero default and example values", function () {
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
mergeJsonSchema,
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
})
const props = {
@@ -333,6 +354,10 @@ describe("bug #5573: zero default and example values", function () {
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
mergeJsonSchema,
jsonSchema202012: {
foldType,
getType: makeGetType(() => ({ isBooleanJSONSchema })),
},
},
})
const props = {

View File

@@ -228,6 +228,7 @@ describe("curlify", function () {
}
let file = new win.File(["data"], "file.txt", { type: "text/plain" })
// eslint-disable-next-line camelcase
let optionsJSON = JSON.stringify({ some_array: ["string"], max_bar: 300 })
let options = new FileWithData(optionsJSON, "", { type: "application/json;charset=utf-8" })

View File

@@ -44,7 +44,7 @@ describe("oauth2", () => {
it("should build authorize url", () => {
oauth2Authorize(authConfig)
expect(authConfig.authActions.authPopup.mock.calls.length).toEqual(1)
expect(authConfig.authActions.authPopup.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&scope=scope1%20scope2&state=")
expect(authConfig.authActions.authPopup.mock.calls[0][0]).toMatch("https://testauthorizationurl/?response_type=code&redirect_uri=&scope=scope1%20scope2&state=")
authConfig.authActions.authPopup.mockReset()
})
@@ -76,7 +76,7 @@ describe("oauth2", () => {
oauth2Authorize(authConfig)
expect(authConfig.authActions.authPopup.mock.calls.length).toEqual(1)
expect(authConfig.authActions.authPopup.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&scope=scope1%20scope2&state=")
expect(authConfig.authActions.authPopup.mock.calls[0][0]).toMatch("https://testauthorizationurl/?param=1&response_type=code&redirect_uri=&scope=scope1%20scope2&state=")
authConfig.authActions.authPopup.mockReset()
})
@@ -182,7 +182,7 @@ describe("oauth2", () => {
oauth2Authorize(authConfig2)
expect(authConfig2.authActions.authPopup.mock.calls.length).toEqual(1)
expect(authConfig2.authActions.authPopup.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&scope=scope2%20scope3&state=")
expect(authConfig2.authActions.authPopup.mock.calls[0][0]).toMatch("https://testauthorizationurl/?param=1&response_type=code&redirect_uri=&scope=scope2%20scope3&state=")
authConfig2.authActions.authPopup.mockReset()
})
@@ -193,7 +193,7 @@ describe("oauth2", () => {
oauth2Authorize(authConfig3)
expect(authConfig3.authActions.authPopup.mock.calls.length).toEqual(1)
expect(authConfig3.authActions.authPopup.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&scope=scope4%20scope5&state=")
expect(authConfig3.authActions.authPopup.mock.calls[0][0]).toMatch("https://testauthorizationurl/?response_type=code&redirect_uri=&scope=scope4%20scope5&state=")
authConfig3.authActions.authPopup.mockReset()
})

View File

@@ -35,7 +35,7 @@ const OAI3_SYSTEM = {
isOAS3: () => true,
specJson: () => {
return fromJS({
openapi: "3.0.0",
openapi: "3.0.4",
components: {
securitySchemes: {
basicAuth: {

View File

@@ -112,8 +112,6 @@ describe("auth plugin - selectors", () => {
})
it("should fail gracefully with bad data", () => {
const securityDefinitions = null
const system = {
authSelectors: {
definitionsToAuthorize() {

View File

@@ -26,6 +26,7 @@ describe("getSampleSchema", () => {
const getSampleSchema = makeGetSampleSchema(getSystem)
beforeEach(() => {
// eslint-disable-next-line no-global-assign
Date = function () {
this.toISOString = function () {
return "2018-07-07T07:07:05.189Z"
@@ -34,6 +35,7 @@ describe("getSampleSchema", () => {
})
afterEach(() => {
// eslint-disable-next-line no-global-assign
Date = oriDate
})

View File

@@ -24,6 +24,7 @@ describe("getSampleSchema", () => {
const getSampleSchema = makeGetSampleSchema(getSystem)
beforeEach(() => {
// eslint-disable-next-line no-global-assign
Date = function () {
this.toISOString = function () {
return "2018-07-07T07:07:05.189Z"
@@ -32,6 +33,7 @@ describe("getSampleSchema", () => {
})
afterEach(() => {
// eslint-disable-next-line no-global-assign
Date = oriDate
})

View File

@@ -3,6 +3,7 @@ import Immutable, { List } from "immutable"
import { Select, Input, TextArea } from "core/components/layout-utils"
import { mount, render } from "enzyme"
import * as JsonSchemaComponents from "core/plugins/json-schema-5/components/json-schema-components"
import { foldType } from "core/plugins/json-schema-2020-12-samples/fn/index"
const components = {...JsonSchemaComponents, Select, Input, TextArea}
@@ -21,7 +22,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "string",
enum: ["one", "two"]
@@ -44,7 +49,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "string",
enum: ["one", "two"]
@@ -65,7 +74,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
required: true,
schema: Immutable.fromJS({
type: "string",
@@ -89,7 +102,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "boolean"
})
@@ -112,7 +129,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "boolean",
enum: ["true"]
@@ -135,7 +156,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "boolean",
required: true
@@ -159,7 +184,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
required: true,
schema: Immutable.fromJS({
type: "boolean",
@@ -186,7 +215,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
updateQueue.push({ value })
},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
errors: List(),
schema: Immutable.fromJS({
type: "object",
@@ -215,7 +248,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "yo",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "NotARealType"
})
@@ -237,7 +274,11 @@ describe("<JsonSchemaComponents.JsonSchemaForm/>", function(){
value: "yo",
onChange: () => {},
keyName: "",
fn: {},
fn: {
jsonSchema202012: {
foldType,
},
},
schema: Immutable.fromJS({
type: "NotARealType",
format: "NotARealFormat"

View File

@@ -23,22 +23,6 @@ describe("<SchemesContainer/>", function(){
},
getComponent: c => components[c]
}
const twoSecurityDefinitions = {
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"flow": "implicit",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
},
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
}
it("renders Schemes inside SchemesContainer if schemes are provided", function(){

View File

@@ -1,7 +1,7 @@
import { fromJS } from "immutable"
import { isOAS30, isSwagger2 } from "core/plugins/oas3/helpers"
const isOAS3Shorthand = (version) => isOAS30(fromJS({
const isOAS30Shorthand = (version) => isOAS30(fromJS({
openapi: version
}))
@@ -9,45 +9,46 @@ const isSwagger2Shorthand = (version) => isSwagger2(fromJS({
swagger: version
}))
describe("isOAS3", function () {
describe("isOAS30", function () {
it("should recognize valid OAS3 version values", function () {
expect(isOAS3Shorthand("3.0.0")).toEqual(true)
expect(isOAS3Shorthand("3.0.1")).toEqual(true)
expect(isOAS3Shorthand("3.0.4")).toEqual(true)
expect(isOAS3Shorthand("3.0.11111")).toEqual(true)
expect(isOAS3Shorthand("3.0.0-rc0")).toEqual(false)
expect(isOAS30Shorthand("3.0.0")).toEqual(true)
expect(isOAS30Shorthand("3.0.1")).toEqual(true)
expect(isOAS30Shorthand("3.0.2")).toEqual(true)
expect(isOAS30Shorthand("3.0.3")).toEqual(true)
expect(isOAS30Shorthand("3.0.4")).toEqual(true)
expect(isOAS30Shorthand("3.0.25")).toEqual(true)
})
it("should fail for invalid OAS3 version values", function () {
expect(isOAS3Shorthand("3.0")).toEqual(false)
expect(isOAS3Shorthand("3.0.")).toEqual(false)
expect(isOAS3Shorthand("2.0")).toEqual(false)
expect(isOAS30Shorthand("3.0")).toEqual(false)
expect(isOAS30Shorthand("3.0.")).toEqual(false)
expect(isOAS30Shorthand("3.0.01")).toEqual(false)
expect(isOAS30Shorthand("2.0")).toEqual(false)
expect(isOAS30Shorthand("3.0.0-rc0")).toEqual(false)
})
it("should gracefully fail for non-string values", function () {
expect(isOAS3Shorthand(3.0)).toEqual(false)
expect(isOAS3Shorthand(3)).toEqual(false)
expect(isOAS3Shorthand({})).toEqual(false)
expect(isOAS3Shorthand(null)).toEqual(false)
expect(isOAS30Shorthand(3.0)).toEqual(false)
expect(isOAS30Shorthand(3)).toEqual(false)
expect(isOAS30Shorthand({})).toEqual(false)
expect(isOAS30Shorthand(null)).toEqual(false)
})
it("should gracefully fail when `openapi` field is missing", function () {
expect(isOAS30(fromJS({
openApi: "3.0.0"
openApi: "3.0.4"
}))).toEqual(false)
expect(isOAS3Shorthand(null)).toEqual(false)
expect(isOAS30Shorthand(null)).toEqual(false)
})
})
describe("isSwagger2", function () {
it("should recognize valid Swagger 2.0 version values", function () {
expect(isSwagger2Shorthand("2.0")).toEqual(true)
expect(isSwagger2Shorthand("2.0-rc0")).toEqual(false)
})
it("should fail for invalid Swagger 2.0 version values", function () {
expect(isSwagger2Shorthand("2.0-rc0")).toEqual(false)
expect(isSwagger2Shorthand("3.0")).toEqual(false)
expect(isSwagger2Shorthand("3.0.")).toEqual(false)
expect(isSwagger2Shorthand("2.1")).toEqual(false)

View File

@@ -25,7 +25,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -55,7 +55,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -89,7 +89,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -126,7 +126,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -170,7 +170,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -211,7 +211,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -266,7 +266,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -320,7 +320,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}
@@ -349,7 +349,7 @@ describe("OAS3 plugin - state", function() {
return {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
return fromJS({ openapi: "3.0.4" })
},
isOAS3: () => true,
}

View File

@@ -15,7 +15,7 @@ describe("oas3 plugin - auth extensions - wrapSelectors", function(){
getState: () => new Map(),
specSelectors: {
specJson: () => fromJS({
openapi: "3.0.0"
openapi: "3.0.4"
}),
isOAS3: () => true,
securityDefinitions: () => {

View File

@@ -8,7 +8,7 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
// Given
const spec = fromJS({
openapi: "3.0.0",
openapi: "3.0.4",
components: {
schemas: {
a: {
@@ -48,7 +48,7 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
// Given
const spec = fromJS({
openapi: "3.0.0"
openapi: "3.0.4"
})
const system = {
@@ -71,7 +71,7 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
// Given
const spec = fromJS({
openapi: "3.0.0",
openapi: "3.0.4",
components: {
schemas: "..."
}

View File

@@ -5,12 +5,33 @@ const isOAS31Shorthand = (version) => isOAS31(fromJS({
openapi: version
}))
describe("isOAS31", function () {
it("should recognize valid OAS31 version values", function () {
describe("isOAS30", function () {
it("should recognize valid OAS3 version values", function () {
expect(isOAS31Shorthand("3.1.0")).toEqual(true)
expect(isOAS31Shorthand("3.1.1")).toEqual(true)
expect(isOAS31Shorthand("3.1.12")).toEqual(true)
expect(isOAS31Shorthand("3.2.0")).toEqual(false)
expect(isOAS31Shorthand("3.0.0-rc0")).toEqual(false)
expect(isOAS31Shorthand("3.1.25")).toEqual(true)
})
it("should fail for invalid OAS3 version values", function () {
expect(isOAS31Shorthand("3.1")).toEqual(false)
expect(isOAS31Shorthand("3.1.")).toEqual(false)
expect(isOAS31Shorthand("3.1.01")).toEqual(false)
expect(isOAS31Shorthand("2.0")).toEqual(false)
})
it("should gracefully fail for non-string values", function () {
expect(isOAS31Shorthand(3.0)).toEqual(false)
expect(isOAS31Shorthand(3)).toEqual(false)
expect(isOAS31Shorthand({})).toEqual(false)
expect(isOAS31Shorthand(null)).toEqual(false)
})
it("should gracefully fail when `openapi` field is missing", function () {
expect(isOAS31(fromJS({
openApi: "3.1.0"
}))).toEqual(false)
expect(isOAS31Shorthand(null)).toEqual(false)
})
})

View File

@@ -1,4 +1,3 @@
import { fromJS } from "immutable"
import { fromJSOrdered } from "core/utils"
import {
@@ -7,6 +6,7 @@ import {
contentTypeValues,
operationScheme,
specJsonWithResolvedSubtrees,
operations,
producesOptionsFor,
operationWithMeta,
parameterWithMeta,
@@ -460,6 +460,7 @@ describe("specJsonWithResolvedSubtrees", function(){
},
security: [
{
// eslint-disable-next-line camelcase
petstore_auth: [
"write:pets",
"read:pets"
@@ -1216,6 +1217,23 @@ describe("taggedOperations", function () {
}
})
})
it("should gracefully handle a malformed paths defined as array", function () {
const state = fromJS({
json: {
tags: [null],
paths:[
{
"/users": null,
"get": null
}
]
}
})
const result = operations(state)
expect(result.toJS()).toEqual([])
})
})
describe("isMediaTypeSchemaPropertiesEqual", () => {
const stateSingleMediaType = fromJS({
@@ -1400,11 +1418,11 @@ describe("validationErrors", function() {
"query.with.dot.hash": {
errors: [
{
error: "Value must be an integer",
error: "Value must be an integer",
propKey: "id"
},
{
error: "Value must be a string",
{
error: "Value must be a string",
propKey: "name"
}
]
@@ -1418,12 +1436,12 @@ describe("validationErrors", function() {
"query.arrayWithObjects.hash": {
errors: [
{
error: "Parameter string value must be valid JSON",
error: "Parameter string value must be valid JSON",
index: 0
},
{
{
error: {
error: "Value must be a string",
error: "Value must be a string",
propKey: "name"
},
index: 1

View File

@@ -1,6 +1,6 @@
import React, { PureComponent } from "react"
import { fromJS } from "immutable"
import { render, mount } from "enzyme"
import { render } from "enzyme"
import { Provider } from "react-redux"
import System from "core/system"
@@ -356,7 +356,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "original"
}
}
@@ -367,7 +367,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
wrapSelectors: {
wow: (ori) => (system) => {
wow: (ori) => () => {
// Then
return ori() + " wrapper"
}
@@ -393,7 +393,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "original"
}
}
@@ -434,7 +434,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "original"
}
}
@@ -445,7 +445,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
wrapSelectors: {
wow: (ori, system) => (dogeState) => {
wow: (ori) => (dogeState) => {
// Then
expect(dogeState.toJS().abc).toEqual("123")
done()
@@ -486,7 +486,7 @@ describe("bound system", function(){
it("allows container components to provide their own `mapStateToProps` function", function() {
// Given
class ContainerComponent extends PureComponent {
mapStateToProps(nextState, props) {
mapStateToProps() {
return {
"fromMapState": "This came from mapStateToProps"
}
@@ -497,8 +497,10 @@ describe("bound system", function(){
}
render() {
// eslint-disable-next-line react/prop-types
const { exampleSelectors, fromMapState, fromOwnProps } = this.props
return (
// eslint-disable-next-line react/prop-types
<div>{ fromMapState } {exampleSelectors.foo()} {fromOwnProps}</div>
)
}
@@ -539,7 +541,7 @@ describe("bound system", function(){
// Given
class ContainerComponent extends PureComponent {
mapStateToProps(nextState, props) {
const { exampleSelectors, fromMapState, fromOwnProps } = props
const { exampleSelectors, fromOwnProps } = props
return {
"fromMapState": `This came from mapStateToProps ${exampleSelectors.foo()} ${fromOwnProps}`
}
@@ -550,6 +552,7 @@ describe("bound system", function(){
}
render() {
// eslint-disable-next-line react/prop-types
const { fromMapState } = this.props
return (
<div>{ fromMapState }</div>
@@ -601,7 +604,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -624,7 +627,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -651,7 +654,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -680,7 +683,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -714,7 +717,7 @@ describe("bound system", function(){
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -734,13 +737,13 @@ describe("bound system", function(){
it("should encapsulate thrown errors in an afterLoad method", function() {
// Given
const ThrowyPlugin = {
afterLoad(system) {
afterLoad() {
throw new Error("afterLoad BREAKS STUFF!")
},
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
wow: () => () => {
return "so selective"
}
}
@@ -800,7 +803,7 @@ describe("bound system", function(){
}
},
reducers: {
"THROW_FUNC": (state, action) => {
"THROW_FUNC": () => {
throw new Error("this reducer EXPLODES!")
}
}
@@ -823,7 +826,7 @@ describe("bound system", function(){
statePlugins: {
throw: {
selectors: {
func: (state, arg1) => {
func: () => {
throw new Error("this selector THROWS!")
}
}
@@ -844,7 +847,7 @@ describe("bound system", function(){
statePlugins: {
throw: {
selectors: {
func: (state, arg1) => system => {
func: () => () => {
throw new Error("this selector THROWS!")
}
}
@@ -873,7 +876,7 @@ describe("bound system", function(){
}
},
wrapActions: {
func: (ori) => (...args) => {
func: () => () => {
throw new Error("this wrapAction UNRAVELS EVERYTHING!")
}
}
@@ -894,7 +897,7 @@ describe("bound system", function(){
statePlugins: {
throw: {
selectors: {
func: (state, arg1) => {
func: () => {
return 123
}
},

View File

@@ -2,6 +2,7 @@ import React from "react"
import { render } from "enzyme"
import System from "core/system"
import PropTypes from "prop-types"
describe("wrapComponents", () => {
describe("should wrap a component and provide a reference to the original", () => {
@@ -46,7 +47,11 @@ describe("wrapComponents", () => {
}
}
// Given
MyComponent.propTypes = {
name: PropTypes.string,
}
// Given
const system = new System({
plugins: [
{
@@ -207,7 +212,7 @@ describe("wrapComponents", () => {
() => {
return {
wrapComponents: {
wow: (OriginalComponent, system) => (props) => {
wow: (OriginalComponent) => (props) => {
return <container1>
<OriginalComponent {...props}></OriginalComponent>
<div>Injected after</div>
@@ -219,7 +224,7 @@ describe("wrapComponents", () => {
() => {
return {
wrapComponents: {
wow: (OriginalComponent, system) => (props) => {
wow: (OriginalComponent) => (props) => {
return <container2>
<div>Injected before</div>
<OriginalComponent {...props}></OriginalComponent>

View File

@@ -20,7 +20,6 @@ import {
escapeDeepLinkPath,
getExtensions,
getCommonExtensions,
sanitizeUrl,
requiresValidationURL,
extractFileNameFromContentDispositionHeader,
deeplyStripKey,
@@ -35,10 +34,11 @@ import {
buildBaseUrl,
buildUrl,
safeBuildUrl,
sanitizeUrl,
} from "core/utils/url"
import win from "core/window"
import { afterAll, beforeAll, expect, jest } from "@jest/globals"
import { afterAll, beforeAll, expect } from "@jest/globals"
describe("utils", () => {
@@ -1301,10 +1301,11 @@ describe("utils", () => {
}
let count = 0
const result = deeplyStripKey(input, "$$ref", () => {
deeplyStripKey(input, "$$ref", () => {
count++
return true
})
expect(count).toEqual(2)
})
})
@@ -1361,27 +1362,91 @@ describe("utils", () => {
describe("sanitizeUrl", () => {
it("should sanitize a `javascript:` url", () => {
const res = sanitizeUrl("javascript:alert('bam!')")
const url = "javascript:alert('bam!')"
expect(res).toEqual("about:blank")
expect(sanitizeUrl(url)).toEqual("about:blank")
})
it("should sanitize a `vbscript:` url", () => {
const url = "vbscript:alert('bam!')"
expect(sanitizeUrl(url)).toEqual("about:blank")
})
it("should sanitize a `data:` url", () => {
const res = sanitizeUrl(`data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4=`)
const url = "data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4="
expect(res).toEqual("about:blank")
expect(sanitizeUrl(url)).toEqual("about:blank")
})
it("should not sanitize", () => {
const url1 = "http://swagger.io/path/to:something"
const url2 = "http://swagger.io:4567/path/to:something"
const url3 = "https://example.com:4567/path/to:something"
const url4 = "./path/to/my.json"
const url5 = "path/to/my.json"
const url6 = "swagger.io"
const url7 = "com.braintreepayments.demo://example"
const url8 = "mailto:test@example.com?subject=hello+world"
const url9 = "javascrip%25%32%35%25%33%35%25%34%33rt:alert()"
const url10 = "notjavascript:alert()"
const url11 = "%20javascript:alert()"
expect(sanitizeUrl(url1)).toEqual(url1)
expect(sanitizeUrl(url2)).toEqual(url2)
expect(sanitizeUrl(url3)).toEqual(url3)
expect(sanitizeUrl(url4)).toEqual(url4)
expect(sanitizeUrl(url5)).toEqual(url5)
expect(sanitizeUrl(url6)).toEqual(url6)
expect(sanitizeUrl(url7)).toEqual(url7)
expect(sanitizeUrl(url8)).toEqual(url8)
expect(sanitizeUrl(url9)).toEqual(url9)
expect(sanitizeUrl(url10)).toEqual(url10)
expect(sanitizeUrl(url11)).toEqual(url11)
})
it("should normalize", () => {
const url1 = "//google.com/robots.txt"
const url2 = "www.example.com/with-áccêntš"
const url3 = "www.example.com/лот.рфшишкиü–"
const url4 = " http://example.com/path/to:something "
const url5 = "https://example.com&NewLine;&NewLine;/something"
const url6 = "http://example.com#javascript:foo"
expect(sanitizeUrl(url1)).toEqual("https://google.com/robots.txt")
expect(sanitizeUrl(url2)).toEqual("www.example.com/with-%C3%A1cc%C3%AAnt%C5%A1")
expect(sanitizeUrl(url3)).toEqual("www.example.com/%D0%BB%D0%BE%D1%82.%D1%80%D1%84%D1%88%D0%B8%D1%88%D0%BA%D0%B8%C3%BC%E2%80%93")
expect(sanitizeUrl(url4)).toEqual("http://example.com/path/to:something")
expect(sanitizeUrl(url5)).toEqual("https://example.com&newline;&newline;/something")
expect(sanitizeUrl(url6)).toEqual("http://example.com/#javascript:foo")
})
it("should sanitize", () => {
const url1 = "www.example.com/\u200D\u0000\u001F\x00\x1F\uFEFFfoo"
const url2 = "javascri\npt:alert('xss')"
const url3 = "\u0000javascript:alert()"
const url4 = "\\j\\av\\a\\s\\cript:alert()"
const url5 = " javascript:alert('xss')"
expect(sanitizeUrl(url1)).toEqual("www.example.com/%E2%80%8D%00%1F%00%1F%EF%BB%BFfoo")
expect(sanitizeUrl(url2)).toEqual("about:blank")
expect(sanitizeUrl(url3)).toEqual("about:blank")
expect(sanitizeUrl(url4)).toEqual("j/av/a/s/cript:alert()")
expect(sanitizeUrl(url5)).toEqual("about:blank")
})
it("should not modify a `http:` url", () => {
const res = sanitizeUrl(`http://swagger.io/`)
const url = "http://swagger.io/"
expect(res).toEqual("http://swagger.io/")
expect(sanitizeUrl(url)).toEqual(url)
})
it("should not modify a `https:` url", () => {
const res = sanitizeUrl(`https://swagger.io/`)
const url = "https://swagger.io/"
expect(res).toEqual("https://swagger.io/")
expect(sanitizeUrl(url)).toEqual("https://swagger.io/")
})
it("should gracefully handle empty strings", () => {
@@ -1712,7 +1777,7 @@ describe("utils", () => {
let res = null
try {
const res = paramToIdentifier(param)
paramToIdentifier(param)
} catch(e) {
error = e
}

View File

@@ -54,11 +54,3 @@ describe("Markdown Link Anchor Safety", function () {
})
})
})
function withMarkdownWrapper(str, { isOAS3 = false } = {}) {
if(isOAS3) {
return `<div class="renderedMarkdown"><p>${str}</p></div>`
}
return `<div class="markdown"><p>${str}</p>\n</div>`
}