-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 TEST: Add test case for Private Network Access (#23)
see koajs/cors#83
- Loading branch information
Showing
15 changed files
with
182 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
schedule: | ||
- cron: '0 2 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [8, 10, 12, 14, 16] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- name: Checkout Git Source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Dependencies | ||
run: npm i -g npminstall && npminstall | ||
|
||
- name: Continuous Integration | ||
run: npm run ci | ||
|
||
- name: Code Coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('test/cors.private-network.test.js', () => { | ||
let app; | ||
before(() => { | ||
app = mm.app({ | ||
baseDir: 'apps/cors.private-network', | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
afterEach(mm.restore); | ||
|
||
it('should not set `Access-Control-Allow-Private-Network` when request Access-Control-Request-Private-Network header missing', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'https://eggjs.org') | ||
.set('Access-Control-Request-Method', 'GET') | ||
.expect('Access-Control-Allow-Origin', 'https://eggjs.org') | ||
.expect({ foo: 'bar' }) | ||
.expect(res => { | ||
assert(!res.headers['Access-Control-Allow-Private-Network']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Private-Network` to non-OPTIONS request', () => { | ||
return app.httpRequest() | ||
.post('/') | ||
.set('Origin', 'https://eggjs.org') | ||
.set('Access-Control-Request-Private-Network', 'true') | ||
.expect('Access-Control-Allow-Origin', 'https://eggjs.org') | ||
.expect(res => { | ||
assert(!res.headers['Access-Control-Allow-Private-Network']); | ||
}) | ||
.expect({ foo: 'bar' }) | ||
.expect(200); | ||
}); | ||
|
||
it('should set `Access-Control-Allow-Private-Network` on OPTIONS request', () => { | ||
app.mockCsrf(); | ||
return app.httpRequest() | ||
.options('/') | ||
.set('Origin', 'https://eggjs.org') | ||
.set('Access-Control-Request-Method', 'POST') | ||
.set('Access-Control-Request-Private-Network', 'true') | ||
.expect('Access-Control-Allow-Origin', 'https://eggjs.org') | ||
.expect('Access-Control-Allow-Private-Network', 'true') | ||
.expect(204); | ||
}); | ||
}); |
Oops, something went wrong.