Skip to content
Snippets Groups Projects
Commit 0c0016da authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Migrating commit

parent eacba818
No related branches found
No related tags found
No related merge requests found
Showing with 6717 additions and 58 deletions
node_modules/
coverage/
stryker.log
*.DS_Store
# stryker temp files
.stryker-tmp
\ No newline at end of file
image: node:latest
include:
- project: 'general/templates'
file: '/cicd/SAST-nodejs.gitlab-ci.yml'
- project: 'general/templates'
file: '/cicd/npm-audit.gitlab-ci.yml'
- project: 'general/templates'
file: '/cicd/sonarqube.gitlab-ci.yml'
variables:
SONAR_PROJECT_KEY: security
SONAR_TOKEN: 11922a8e774494f51e1d2f0e695949e4073e7df8
NPM_REGISTRY: https://npm.br-edv.brnet.int
NPM_TOKEN: 5w2Gy80rdH+2Tch0afNI6Q==
cache:
paths:
- node_modules/
- docs/
stages:
- build
- test
- quality
- publish
build:
stage: build
script:
- npm install --production
test:
stage: test
before_script:
- npm install -g jest
script:
- jest
artifacts:
paths:
- docs/test-report.html
- docs/coverage/lcov.info
publish:
stage: publish
script:
- npm config set strict-ssl false
- npm publish --verbose --registry $NPM_REGISTRY
.gitlab-ci.yml
\ No newline at end of file
{
"[markdown]": {
"editor.cursorSurroundingLines": 0
}
}
\ No newline at end of file
# security
Sets Headers to a very save style. may be overriden by config.
## Installation
## Getting started
- `npm install --save @libs/security`
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
## Usage
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
`const security = require('@libs/security')`
`app.use(security(options))`
## Add your files
## Options
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
### Headers
```
cd existing_repo
git remote add origin https://gitlab.ard.de/libs/security.git
git branch -M main
git push -uf origin main
```
This is the List of Header with default values and Option name
## Integrate with your tools
| Header | Option | Default Value |
| ------- | ------ | ------------- |
| [Cache-Control](https://developer.mozilla.org/en/docs/Web/HTTP/Headers/Cache-Control) | CacheControl | no-cache, no-store, must-revalidate |
| [Pragma](https://developer.mozilla.org/en/docs/Web/HTTP/Headers/Pragma) | Pragma | no-cache |
| [Expires](https://developer.mozilla.org/en/docs/Web/HTTP/Headers/Expires) | Expires | 0 |
| [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) | ContentSecurityPolicy | default-src \'self\'; frame-ancestors \'none\' |
| [X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection) | XXSSProtection | 1; mode=block |
| [X-DNS-Prefetch-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control) | XDNSPrefetchControl | off |
| [Expect-CT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT) | ExpectCT | report-uri="/_report", enforce, max-age=30 |
| [X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) | XFrameOptions | deny |
| [X-Powered-By](https://blog.rapid7.com/2019/12/06/hidden-helpers-security-focused-http-headers-to-protect-against-vulnerabilities/) | XPoweredBy | true |
| [Strict-Transport-Security](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) | StrictTransportSecurity | max-age=30 |
| [X-Download-Options](https://www.nwebsec.com/HttpHeaders/SecurityHeaders/XDownloadOptions) | XDownloadOptions | noopen |
| [X-Content-Type-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options) | XContentTypeOptions | nosniff |
| [X-Permitted-Cross-Domain-Policies](https://helmetjs.github.io/docs/crossdomain/) | XPermittedCrossDomainPolicies | none |
| [Referrer-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy) | ReferrerPolicy | no-referrer |
- [ ] [Set up project integrations](https://gitlab.ard.de/libs/security/-/settings/integrations)
### Allowed Methods
## Collaborate with your team
The option _allowedMethods_ is an array of allowed HTTP-Methods.
By Default it is set to `['GET', 'POST', 'PUT', 'DELETE']`, dissallowing e.g. _HEAD_
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
You may set this Array to whatever you like, we recommend to make it even more restrict if possible.
## Test and Deploy
A read-only API may set `allowedMethods: ['GET']`
Use the built-in continuous integration in GitLab.
### Only Defined Routes
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
The Option _onlyDefinedRoutes_ may be set to _true_ (Default: _false_)
***
Then only explicitely defined Routes are allowed by the express-Router,
all other attempts will receive a status _405_
# Editing this README
To define Routes, use the Option _definedRoutes_, which expects an Array of Routes.
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
You may also define regex-Definitions for Routes by prefixing them with __REGEX:__.
Beware of Escaping!
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
Example: `REGEX:\\/id\\/\\d{1,}`
Allows: _/id/NUMBER_ where NUMBER is a digit between 0 and Infinity
## Name
Choose a self-explaining name for your project.
We discourage the use of rules like _/.*_ (which allows all routes)
And it is better to define all known routes.
So if you have a route like _/items/:id_ defined, you should add all ids to your array of defined routes ...
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Examples
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
Run these and check with your favorite testing tool, eg nikto, zap
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
### Default
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
You Should create SSL-Keys first to enable https-example:
`openssl req -x509 -newkey rsa:4096 -keyout examples/default/private.key -out examples/default/certificate.crt -days 365 -nodes`
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
`node examples/default/index.js`
### unsave
`node examples/unsave/index.js`
## Author
Dominik Sigmund <dominik.sigmund@br.de>
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Contribution
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
### Header
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
To add header, create a fork, then branch and add the header to:
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
- index.js
- index.test.js
- README.md
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
then run tests and mutation tests.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
after that, create a pull request and state the function of the header.
## License
For open source projects, say how it is licensed.
### Other Functions
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Similar as above, just make sure the functions secures the app even more.
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="mutation-test-elements.js"></script>
</head>
<body>
<img class="stryker-image" alt="Stryker" src="stryker-80x80.png"
style="position: fixed; right: 0; top: 0; z-index: 10">
<mutation-test-report-app titlePostfix="Stryker">
Your browser doesn't support <a href="https://caniuse.com/#search=custom%20elements">custom elements</a>.
Please use a latest version of an evergreen browser (Firefox, Chrome, Safari, Opera, etc).
</mutation-test-report-app>
<script src="bind-mutation-test-report.js"></script>
</body>
</html>
This diff is collapsed.
docs/mutation/stryker-80x80.png

6.05 KiB

This diff is collapsed.
const express = require('express')
const security = require('../../index')
const app = express()
app.use(security())
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function () {
console.log('Secure Example app listening on port 3000!')
})
\ No newline at end of file
const express = require('express')
const security = require('../../index')
const app = express()
app.use(security({
CacheControl: 'public, max-age=9999999999',
Pragma: false,
Expires: 'Wed, 21 Oct 2090 07:28:00 GMT',
ContentSecurityPolicy: false,
XXSSProtection: false,
XDNSPrefetchControl: 'on',
ExpectCT: false,
XFrameOptions: false,
StrictTransportSecurity: false,
XDownloadOptions: false,
XContentTypeOptions: false,
XPermittedCrossDomainPolicies: false,
ReferrerPolicy: 'unsafe-url',
allowedMethods: ['HEAD', 'GET', 'OPTIONS'],
onlyDefinedRoutes: false
}))
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function () {
console.log('Unsave Example app listening on port 3000!')
})
\ No newline at end of file
declare module 'security' {
const noTypesYet: any;
export default noTypesYet;
}
\ No newline at end of file
index.js 0 → 100644
module.exports = function(options) {
return function(req, res, next) {
if(!options) options = {}
if (typeof options.CacheControl === 'undefined') {
options.CacheControl = 'no-cache, no-store, must-revalidate'
}
if (options.CacheControl !== false) {
res.set('Cache-Control', options.CacheControl)
}
if (typeof options.Pragma === 'undefined') {
options.Pragma = 'no-cache'
}
if (options.Pragma !== false) {
res.set('Pragma', options.Pragma)
}
if (typeof options.Expires === 'undefined') {
options.Expires = '0'
}
if (options.Expires !== false) {
res.set('Expires', options.Expires)
}
if (typeof options.ContentSecurityPolicy === 'undefined') {
options.ContentSecurityPolicy = 'default-src \'self\'; frame-ancestors \'none\''
}
if (options.ContentSecurityPolicy !== false) {
res.set('Content-Security-Policy', options.ContentSecurityPolicy )
}
if (typeof options.XXSSProtection === 'undefined') {
options.XXSSProtection = '1; mode=block'
}
if (options.XXSSProtection !== false) {
res.set('X-XSS-Protection', options.XXSSProtection)
}
if (typeof options.XDNSPrefetchControl === 'undefined') {
options.XDNSPrefetchControl = 'off'
}
if (options.XDNSPrefetchControl !== false) {
res.set('X-DNS-Prefetch-Control', options.XDNSPrefetchControl)
}
if (typeof options.ExpectCT === 'undefined') {
options.ExpectCT = 'report-uri="/_report", enforce, max-age=30'
}
if (options.ExpectCT !== false) {
res.set('Expect-CT', options.ExpectCT)
}
if (typeof options.XFrameOptions === 'undefined') {
options.XFrameOptions = 'deny'
}
if (options.XFrameOptions !== false) {
res.set('X-Frame-Options', options.XFrameOptions)
}
if (typeof options.XPoweredBy === 'undefined') {
options.XPoweredBy = true
}
if (options.XPoweredBy !== false) {
res.removeHeader('X-Powered-By')
}
if (typeof options.StrictTransportSecurity === 'undefined') {
options.StrictTransportSecurity = 'max-age=30'
}
if (options.StrictTransportSecurity !== false) {
res.set('Strict-Transport-Security', options.StrictTransportSecurity)
}
if (typeof options.XDownloadOptions === 'undefined') {
options.XDownloadOptions = 'noopen'
}
if (options.XDownloadOptions !== false) {
res.set('X-Download-Options', options.XDownloadOptions)
}
if (typeof options.XContentTypeOptions === 'undefined') {
options.XContentTypeOptions = 'nosniff'
}
if (options.XContentTypeOptions !== false) {
res.set('X-Content-Type-Options', options.XContentTypeOptions )
}
if (typeof options.XPermittedCrossDomainPolicies === 'undefined') {
options.XPermittedCrossDomainPolicies = 'none'
}
if (options.XPermittedCrossDomainPolicies !== false) {
res.set('X-Permitted-Cross-Domain-Policies', options.XPermittedCrossDomainPolicies)
}
if (typeof options.ReferrerPolicy === 'undefined') {
options.ReferrerPolicy = 'no-referrer'
}
if (options.ReferrerPolicy !== false) {
res.set('Referrer-Policy', options.ReferrerPolicy)
}
if (typeof options.allowedMethods === 'undefined') {
options.allowedMethods = ['GET', 'POST', 'PUT', 'DELETE']
}
if (!options.allowedMethods.includes(req.method)) {
res.status(405).end()
}
if (typeof options.onlyDefinedRoutes === 'undefined') {
options.onlyDefinedRoutes = true
}
if (options.onlyDefinedRoutes) {
if (!req.app._router.stack.filter(r => r.route).map(r => r.route.path).includes(req.originalUrl)) {
res.status(405).end()
}
}
next()
}
}
\ No newline at end of file
const security = require('./index')
const express = require('express')
const superagent = require("superagent")
let app
let server
const mockReq = {
originalUrl: '/',
_setUrl: function (url) {
this.originalUrl = url
},
method: 'GET',
_setMethod: function(method) {
this.method = method
},
app: {
_router: {
stack: [{
route: {
path: '/'
}
}]
}
}
}
const mockRes = {
_headers: {
'X-Powered-By': 'my-server'
},
set: function(header, value) {
this._headers[header] = value
},
removeHeader: function(header) {
delete this._headers[header]
},
_status: 200,
status: function(status) {
this._status = status
return this
},
end: function() {
return undefined
}
}
describe('Unit Tests', () => {
beforeEach(() => {
mockRes._headers = { 'X-Powered-By': 'my-server'}
mockRes._status = 200
mockReq.originalUrl = '/'
mockReq.method = 'GET'
})
headerUnitTest('Cache-Control', 'CacheControl', 'no-cache, no-store, must-revalidate')
headerUnitTest('Pragma', 'Pragma', 'no-cache')
headerUnitTest('Expires', 'Expires', '0')
headerUnitTest('Content-Security-Policy', 'ContentSecurityPolicy', 'default-src \'self\'; frame-ancestors \'none\'')
headerUnitTest('X-XSS-Protection', 'XXSSProtection', '1; mode=block')
headerUnitTest('X-DNS-Prefetch-Control', 'XDNSPrefetchControl', 'off')
headerUnitTest('Expect-CT', 'ExpectCT', 'report-uri="/_report", enforce, max-age=30')
headerUnitTest('X-Frame-Options', 'XFrameOptions', 'deny')
describe('Header: X-Powered-By', () => {
it('should remove Header if not defined', (done) => {
let sec = security()
sec(mockReq, mockRes, () => {
expect(mockRes._headers['X-Powered-By']).toBeUndefined()
done()
})
})
it('should not remove Header if set to false', (done) => {
let options = {}
options.XPoweredBy = false
let sec = security(options)
sec(mockReq, mockRes, () => {
expect(mockRes._headers['X-Powered-By']).toBeDefined()
done()
})
})
})
headerUnitTest('Strict-Transport-Security', 'StrictTransportSecurity', 'max-age=30')
headerUnitTest('X-Download-Options', 'XDownloadOptions', 'noopen')
headerUnitTest('X-Content-Type-Options', 'XContentTypeOptions', 'nosniff')
headerUnitTest('X-Permitted-Cross-Domain-Policies', 'XPermittedCrossDomainPolicies', 'none')
headerUnitTest('Referrer-Policy', 'ReferrerPolicy', 'no-referrer')
describe('Allowed Methods', () => {
it('should only allow GET, POST, PUT, DELETE on default', (done) => {
let sec = security()
mockReq._setMethod('GET')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(200)
mockReq._setMethod('HEAD')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(405)
done()
})
})
})
it('should allow given Methods', (done) => {
let sec = security({
allowedMethods: ['POST']
})
mockReq._setMethod('POST')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(200)
mockReq._setMethod('GET')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(405)
done()
})
})
done()
})
})
describe('Defined Routes', () => {
it('should only allow defined routes by default', (done) => {
let sec = security()
mockReq._setUrl('/')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(200)
mockReq._setUrl('/test')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(405)
done()
})
})
})
it('should allow all routes if set to false', (done) => {
let sec = security({
onlyDefinedRoutes: false
})
mockReq._setUrl('/')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(200)
mockReq._setUrl('/test')
sec(mockReq, mockRes, () => {
expect(mockRes._status).toBe(200)
done()
})
})
})
})
})
describe('Integration Tests', () => {
afterEach(() => {
server.close()
})
headerIntegrationTest('Cache-Control', 'CacheControl', 'no-cache, no-store, must-revalidate')
headerIntegrationTest('Pragma', 'Pragma', 'no-cache')
headerIntegrationTest('Expires', 'Expires', '0')
headerIntegrationTest('Content-Security-Policy', 'ContentSecurityPolicy', 'default-src \'self\'; frame-ancestors \'none\'')
headerIntegrationTest('X-XSS-Protection', 'XXSSProtection', '1; mode=block')
headerIntegrationTest('X-DNS-Prefetch-Control', 'XDNSPrefetchControl', 'off')
headerIntegrationTest('Expect-CT', 'ExpectCT', 'report-uri="/_report", enforce, max-age=30')
headerIntegrationTest('X-Frame-Options', 'XFrameOptions', 'deny')
describe('Header: X-Powered-By', () => {
it('should remove Header if not defined', (done) => {
startUpServer({})
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
expect(res.headers['x-powered-by']).toBeUndefined()
done()
})
})
it('should not remove Header if set to false', (done) => {
startUpServer({
XPoweredBy: false
})
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
expect(res.headers['x-powered-by']).toBeDefined()
done()
})
})
})
headerIntegrationTest('Strict-Transport-Security', 'StrictTransportSecurity', 'max-age=30')
headerIntegrationTest('X-Download-Options', 'XDownloadOptions', 'noopen')
headerIntegrationTest('X-Content-Type-Options', 'XContentTypeOptions', 'nosniff')
headerIntegrationTest('X-Permitted-Cross-Domain-Policies', 'XPermittedCrossDomainPolicies', 'none')
headerIntegrationTest('Referrer-Policy', 'ReferrerPolicy', 'no-referrer')
describe('Allowed Methods', () => {
it('should only allow GET, POST, PUT, DELETE on default', (done) => {
startUpServer({})
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
superagent
.head('http://127.0.0.1:7777')
.then(res => {})
.catch((error) => {
expect(error.status).toBe(405)
done()
})
})
})
it('should allow given Methods', (done) => {
startUpServer({
allowedMethods: ['HEAD']
})
superagent
.head('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
superagent
.get('http://127.0.0.1:7777')
.then(res => {})
.catch((error) => {
expect(error.status).toBe(405)
done()
})
})
})
})
describe('Defined Routes', () => {
it('should only allow defined routes by default', (done) => {
startUpServer({})
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
superagent
.get('http://127.0.0.1:7777/test')
.then(res => {})
.catch((error) => {
expect(error.status).toBe(405)
done()
})
})
})
})
})
function headerUnitTest (header, headerOption, defaultValue) {
describe('Header: ' + header, () => {
it('should set "' + defaultValue + '" if not defined', (done) => {
let sec = security()
sec(mockReq, mockRes, () => {
expect(mockRes._headers[header]).toBe(defaultValue)
done()
})
})
it('should not set Header if set to false', (done) => {
let options = {}
options[headerOption] = false
let sec = security(options)
sec(mockReq, mockRes, () => {
expect(mockRes._headers[header]).toBeUndefined()
done()
})
})
it('should set given values', (done) => {
let options = {}
options[headerOption] = 'somevalue'
let sec = security(options)
sec(mockReq, mockRes, () => {
expect(mockRes._headers[header]).toBe('somevalue')
done()
})
})
})
}
function headerIntegrationTest (header, headerOption, defaultValue) {
describe('Header: ' + header, () => {
it('should set "' + defaultValue + '" if not defined', (done) => {
startUpServer({})
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
expect(res.headers[header.toLowerCase()]).toBe(defaultValue)
done()
})
})
it('should not set Header if set to false', (done) => {
let options = {}
options[headerOption] = false
startUpServer(options)
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
expect(res.headers[header.toLowerCase()]).toBeUndefined()
done()
})
})
it('should set given values', (done) => {
let options = {}
options[headerOption] = 'somevalue'
startUpServer(options)
superagent
.get('http://127.0.0.1:7777')
.then(res => {
expect(res.status).toBe(200)
expect(res.headers[header.toLowerCase()]).toBe('somevalue')
done()
})
})
})
}
function startUpServer(options) {
app = express()
app.use(security(options))
app.get('/', function (req, res) {
res.send('Hello World!')
})
server = app.listen(7777)
}
\ No newline at end of file
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
module.exports = {
collectCoverage: true,
coverageDirectory: './docs/coverage',
coverageReporters: ['json', 'lcov', 'text', 'clover', 'html'],
reporters: [
'default',
['jest-html-reporters', {
publicPath: './docs',
filename: 'test-report.html',
pageTitle: 'Module :: Security :: Test Results'
}]
],
testEnvironment: 'node',
moduleFileExtensions: ['js']
}
This diff is collapsed.
{
"name": "@plastdev/security",
"version": "1.0.0",
"description": "Sets Headers to a very save style in express-apps. may be overriden by config",
"main": "index.js",
"scripts": {
"test": "jest",
"test:mutation": "stryker run"
},
"keywords": [
"security",
"header",
"express",
"middleware"
],
"author": "Dominik Sigmund <dominik.sigmund@br.de>",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"@stryker-mutator/core": "^3.1.0",
"@stryker-mutator/javascript-mutator": "^3.1.0",
"@stryker-mutator/jest-runner": "^3.1.0",
"@stryker-mutator/typescript": "^3.1.0",
"express": "^4.17.1",
"jest": "^25.3.0",
"jest-html-reporters": "^1.2.1",
"superagent": "^5.2.2"
},
"jest": {
"collectCoverage": true,
"coverageReporters": [
"json",
"lcov",
"text",
"clover",
"html"
],
"coverageDirectory": "docs/coverage"
}
}
{
"$schema": "https://raw.githubusercontent.com/stryker-mutator/stryker/master/packages/api/schema/stryker-core.json",
"mutator": "javascript",
"packageManager": "npm",
"reporters": [
"html",
"clear-text",
"progress",
"dashboard"
],
"htmlReporter": {
"baseDir": "docs/mutation"
},
"testRunner": "jest",
"transpilers": [],
"coverageAnalysis": "off",
"mutate": [
"index.js"
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment