Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {}
}
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [filiphric]
custom: ['https://filiphric.com/workshops']
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.11.1](https://github.com/filiphric/cypress-plugin-api/compare/v2.11.0...v2.11.1) (2023-05-15)


### Bug Fixes

* types for env object being wrongly set as required ([8a1a995](https://github.com/filiphric/cypress-plugin-api/commits/8a1a9954eebaa16ed505cd2715d4ba77d07c1d9b))

## [2.11.0](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.5...v2.11.0) (2023-03-17)


### Features

* add support for hiding query parameters ([9122abc](https://github.com/filiphric/cypress-plugin-api/commits/9122abcb68e683b5e2d8da6d35e703de593b8e73))

### [2.10.5](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.4...v2.10.5) (2023-03-17)


### Bug Fixes

* snapshot handling that causes unexpected errors ([f60021d](https://github.com/filiphric/cypress-plugin-api/commits/f60021d0f3c52cc7e6fc60955279362a848f8e90))

### [2.10.4](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.3...v2.10.4) (2023-03-17)


### Bug Fixes

* make size attribute optional ([7950f38](https://github.com/filiphric/cypress-plugin-api/commits/7950f38d04a1197d2b6600e5fb7a6f1be058cf9f))

### [2.10.3](https://github.com/filiphric/cypress-plugin-api/compare/v2.10.2...v2.10.3) (2023-02-03)


Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ it('my secret test', {
hideCredentialsOptions: {
headers: ['authorization'],
auth: ['pass'],
body: ['username']
body: ['username'],
query: ['password']
}
}
}, () => {
Expand All @@ -115,6 +116,9 @@ it('my secret test', {
},
body: {
username: Cypress.env('myUser') // hidden
},
qs: {
password: Cypress.env('password') // hidden
}
})

Expand Down
23 changes: 23 additions & 0 deletions cypress/e2e/authorization.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ describe('Hiding credentials by defining them', () => {

});

it('hides credentials in query', {
env: {
hideCredentials: true,
hideCredentialsOptions: {
qs: ['password']
}
}
}, () => {

cy.api({
method: 'POST',
url: '/',
qs: {
password: 'secret'
}
})

cy.get('[data-cy="query"]')
.should('contain', '******')
.should('contain', 'password')

});

});

describe('Showing credentials', () => {
Expand Down
18 changes: 11 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Filip Hric (https://filiphric.com/)",
"license": "ISC",
"name": "cypress-plugin-api",
"version": "2.10.3",
"version": "2.11.1",
"keywords": [
"cypress",
"api",
Expand Down Expand Up @@ -69,7 +69,7 @@
"vite": "^3.1.4"
},
"peerDependencies": {
"cypress": ">=3"
"cypress": ">=10"
},
"dependencies": {
"highlight.js": "11.4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/StatusPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class="mx-2 font-mono text-cy-green"
>{{ time }}&nbsp;ms</span>
</p>
<p>
<p v-if="size">
Size:<span
data-cy="size"
class="mx-2 font-mono text-cy-green"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cloneProps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isValidUrlOrIp } from "@utils/isValidUrlOrIp"
import { ApiRequestOptions, RequestProps } from "src/types"
import { ApiRequestOptions, RequestProps } from "../types"
const { _ } = Cypress

export const cloneProps = (props: RequestProps[], index: number, options: ApiRequestOptions) => {
Expand Down
56 changes: 31 additions & 25 deletions src/modules/handleResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { removeStyles } from '@modules/removeStyles'
import setCookie from 'set-cookie-parser';
import { convertSize } from '@utils/convertSize';
import { calculateSize } from '@utils/calculateSize';
import { ApiRequestOptions, ApiResponseBody, RequestProps } from 'src/types';
import { ApiRequestOptions, ApiResponseBody, RequestProps } from '../types';
import { transform } from "@modules/transform";
import { getState } from '@utils/getState';
import { App } from 'vue';
Expand All @@ -17,7 +17,7 @@ export const handleResponse = (res: ApiResponseBody, options: ApiRequestOptions,
name: options.method || 'GET',
autoEnd: false,
message: `${options.url}`
})
}).snapshot('request')

const { body, status, headers, statusText, duration } = res

Expand Down Expand Up @@ -69,40 +69,46 @@ export const handleResponse = (res: ApiResponseBody, options: ApiRequestOptions,
props[index].responseHeaders.formatted = transform(headers)

// count content size from header if available, or calculate manually
const size = contentLengthHeader ? parseInt(contentLengthHeader) : calculateSize(props[index].responseBody.body.value)
const size = contentLengthHeader ? parseInt(contentLengthHeader) : calculateSize(props[index].responseBody.body?.value)
props[index].size = convertSize(size) // convert to readable format (kB, MB...)
res.size = size

const yielded = res

// we need to make sure we do the snapshot at a right moment
cy.get(`#${props[index].id}`, { log: false }).then(($el) => {
const findSnapshotElement = () => {
return Cypress.$(`#${props[index].id}`, { log: false })
}

// add response to console output
log.set({
consoleProps() {
return {
yielded
// we need to make sure we do the snapshot at a right moment
cy.window({ log: false })
.then(findSnapshotElement)
.then(($el) => {

// add response to console output
log.set({
consoleProps() {
return {
yielded
}
}
}
})
})

// save all props to current window to be loaded
window.props[testId] = props
// save all props to current window to be loaded
window.props[testId] = props

log.set({ $el });
log.snapshot('snapshot').end()
log.set({ $el });
log.snapshot('response').end()

// scroll to the bottom
doc.getElementById('api-view-bottom')?.scrollIntoView()
// scroll to the bottom
doc.getElementById('api-view-bottom')?.scrollIntoView()

// if in snapshot mode, unmount plugin from view
if (Cypress.env('snapshotOnly')) {
app.unmount()
removeStyles()
}
// if in snapshot mode, unmount plugin from view
if (Cypress.env('snapshotOnly')) {
app.unmount()
removeStyles()
}

return res
return res

})
})
}
2 changes: 1 addition & 1 deletion src/modules/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getState } from '@utils/getState'
import { RequestProps } from "src/types"
import { RequestProps } from "../types"
import { reactive, createApp } from "vue"
import App from "../components/App.vue";
import { mountPlugin } from "./mountPlugin";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/transformData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestProps } from "src/types"
import { RequestProps } from "../types"
import { transform } from "./transform"

export const transformData = (props: RequestProps[], index: number) => {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare global {
env(object: PluginEnvOptions): void;
}
interface TestConfigOverrides {
env?: PluginEnvOptions
env?: Partial<PluginEnvOptions>
}
}
interface Window {
Expand All @@ -109,6 +109,7 @@ export interface HideCredentialsOptions {
auth?: string[]
headers?: string[]
body?: string[]
qs?: string[]
}

export interface ApiRequestOptions extends Cypress.RequestOptions {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/anonymize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const anonymize = (options: RequestProps) => {
auth: [],
body: [],
headers: [],
qs: [],
...Cypress.env('hideCredentialsOptions')
}

Expand Down Expand Up @@ -37,5 +38,12 @@ export const anonymize = (options: RequestProps) => {
}
})

anonymizeOptions.qs?.forEach(k => {
if (options.query.body && options.query.body[k as keyof Cypress.RequestBody]) {
// @ts-ignore until I figure out how to fix this
options.query.body[k] = options?.query.body[k].replace(/./g, '*')
}
})

return options
}