Skip to content

Commit 2c57454

Browse files
committed
security updates
1 parent e29de52 commit 2c57454

16 files changed

Lines changed: 5842 additions & 4896 deletions

File tree

__mocks__/file-mock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'file-stub'

__mocks__/next/router.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default {
2+
push: jest.fn(),
3+
back: jest.fn(),
4+
forward: jest.fn(),
5+
prefetch: jest.fn(),
6+
replace: jest.fn(),
7+
reload: jest.fn(),
8+
pathname: '/',
9+
route: '/',
10+
query: {},
11+
asPath: '/',
12+
basePath: '',
13+
isLocaleDomain: false,
14+
isReady: true,
15+
isPreview: false,
16+
events: {
17+
on: jest.fn(),
18+
off: jest.fn(),
19+
emit: jest.fn()
20+
},
21+
beforePopState: jest.fn()
22+
}

__mocks__/react-markdown/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
3+
const ReactMarkdown = ({ children, ...props }) => {
4+
return React.createElement('div', {
5+
'data-testid': 'markdown-content',
6+
...props
7+
}, children)
8+
}
9+
10+
export default ReactMarkdown

babel.config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
module.exports = {
2-
presets: [
3-
"@babel/preset-react",
4-
[
5-
"@babel/preset-env",
6-
{
7-
targets: {
8-
browsers: "last 2 versions", // Specify the browsers you want to support
9-
},
10-
},
11-
],
12-
],
2+
presets: ['next/babel']
133
};

jest.config.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
module.exports = {
2-
testEnvironment: "jsdom",
3-
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx|js)$",
4-
setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
5-
transform: {
6-
"^.+\\.(js|jsx)$": "babel-jest"
7-
},
8-
moduleNameMapper: {
9-
'next/router': '<rootDir>/__mocks__/next/router.js',
10-
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
11-
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': '<rootDir>/__mocks__/file-mock.js',
12-
'react-markdown': '<rootDir>/node_modules/react-markdown/react-markdown.min.js',
13-
"\\.(css|sass|scss)$": "identity-obj-proxy",
14-
"\\.(jpg|jpeg|png|gif|eot|otf|svg|ttf|woff|woff2)$": "jest-transform-stub",
15-
},
16-
2+
testEnvironment: "jsdom",
3+
testMatch: [
4+
"<rootDir>/src/**/__tests__/**/*.{js,jsx}",
5+
"<rootDir>/src/**/*.{test,spec}.{js,jsx}"
6+
],
7+
setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
8+
transform: {
9+
"^.+\\.(js|jsx)$": ["babel-jest", { presets: ["next/babel"] }]
10+
},
11+
moduleNameMapper: {
12+
"^@/(.*)$": "<rootDir>/src/$1",
13+
"next/router": "<rootDir>/__mocks__/next/router.js",
14+
"react-markdown": "<rootDir>/__mocks__/react-markdown/index.js",
15+
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
16+
"^.+\\.(css|sass|scss)$": "identity-obj-proxy",
17+
"^.+\\.(jpg|jpeg|png|gif|webp|avif|svg|ico|bmp|tiff)$": "<rootDir>/__mocks__/file-mock.js"
18+
},
19+
collectCoverageFrom: [
20+
"src/**/*.{js,jsx}",
21+
"!src/**/*.test.{js,jsx}",
22+
"!src/**/__tests__/**",
23+
"!src/pages/_*.js"
24+
],
25+
coverageThreshold: {
26+
global: {
27+
branches: 70,
28+
functions: 70,
29+
lines: 70,
30+
statements: 70
31+
}
32+
},
33+
testEnvironmentOptions: {
34+
customExportConditions: [""]
35+
}
1736
};

next.config.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {}
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
// Security headers
5+
async headers() {
6+
return [
7+
{
8+
source: '/(.*)',
9+
headers: [
10+
{
11+
key: 'X-Frame-Options',
12+
value: 'DENY'
13+
},
14+
{
15+
key: 'X-Content-Type-Options',
16+
value: 'nosniff'
17+
},
18+
{
19+
key: 'Referrer-Policy',
20+
value: 'origin-when-cross-origin'
21+
},
22+
{
23+
key: 'Permissions-Policy',
24+
value: 'camera=(), microphone=(), geolocation=()'
25+
}
26+
]
27+
}
28+
]
29+
},
30+
// GitHub Pages specific settings
31+
trailingSlash: true,
32+
images: {
33+
unoptimized: true
34+
}
35+
}
336

437
module.exports = nextConfig

0 commit comments

Comments
 (0)