-
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.
- Loading branch information
Showing
14 changed files
with
167 additions
and
89 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,16 @@ | ||
# 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 | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
branches: [ master ] | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
schedule: | ||
- cron: '0 2 * * *' | ||
branches: [ master ] | ||
|
||
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 }} | ||
Job: | ||
name: Node.js | ||
uses: node-modules/github-actions/.github/workflows/node-test.yml@master | ||
with: | ||
os: 'ubuntu-latest' | ||
version: '14, 16, 18, 20' |
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,13 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
release: | ||
name: Node.js | ||
uses: eggjs/github-actions/.github/workflows/node-release.yml@master | ||
secrets: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} |
File renamed without changes.
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
// there is no global.URL in node 8 | ||
const URL = require('url').URL; | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
'use strict'; | ||
|
||
module.exports = require('@koa/cors'); |
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,110 @@ | ||
const assert = require('assert'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('test/cors.default-config.test.js', () => { | ||
let app; | ||
before(() => { | ||
app = mm.app({ | ||
baseDir: 'apps/cors-default-config', | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
afterEach(mm.restore); | ||
|
||
it('should not set `Access-Control-Allow-Origin` when request Origin header missing', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.expect({ foo: 'bar' }) | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` to request origin header', () => { | ||
app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'http://eggjs.org') | ||
.expect('Access-Control-Allow-Credentials', 'true') | ||
.expect({ foo: 'bar' }) | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` to request origin header with second-level domain', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'http://test.eggjs.org') | ||
.expect({ foo: 'bar' }) | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` to when white list domain is empty', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'https://a.com') | ||
.expect({ foo: 'bar' }) | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` on POST request', () => { | ||
app.mockCsrf(); | ||
return app.httpRequest() | ||
.post('/') | ||
.set('Origin', 'http://eggjs.org') | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` when origin not in white list', () => { | ||
app.mockCsrf(); | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'http://eggjs-black.org') | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` when origin = http://eggjs.org!.evil.com', () => { | ||
app.mockCsrf(); | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', 'http://eggjs.org!.evil.com') | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should not set `Access-Control-Allow-Origin` when origin = /foo', () => { | ||
app.mockCsrf(); | ||
return app.httpRequest() | ||
.get('/') | ||
.set('Origin', '/foo') | ||
.expect(res => { | ||
assert(!res.headers['access-control-allow-origin']); | ||
assert(!res.headers['access-control-allow-credentials']); | ||
}) | ||
.expect(200); | ||
}); | ||
}); |
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,15 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
app.get('/', async ctx => { | ||
ctx.body = { | ||
foo: 'bar', | ||
}; | ||
}); | ||
|
||
app.post('/', async ctx => { | ||
ctx.body = { | ||
foo: 'bar', | ||
}; | ||
}); | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/apps/cors-default-config/config/config.default.js
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,3 @@ | ||
exports.keys = 'foo'; | ||
|
||
exports.cors = {}; |
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,3 @@ | ||
{ | ||
"name": "cors" | ||
} |
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