diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e662fb3..492a03fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,195 +1,195 @@ name: ci on: -- pull_request -- push + - pull_request + - push jobs: test: - runs-on: ubuntu-latest + runs-on: ["self-hosted", "general-ubuntu-amd"] strategy: matrix: name: - - Node.js 0.8 - - Node.js 0.10 - - Node.js 0.12 - - io.js 1.x - - io.js 2.x - - io.js 3.x - - Node.js 4.x - - Node.js 5.x - - Node.js 6.x - - Node.js 7.x - - Node.js 8.x - - Node.js 9.x - - Node.js 10.x - - Node.js 11.x - - Node.js 12.x - - Node.js 13.x - - Node.js 14.x - - Node.js 15.x - - Node.js 16.x - - Node.js 17.x - - Node.js 18.x + - Node.js 0.8 + - Node.js 0.10 + - Node.js 0.12 + - io.js 1.x + - io.js 2.x + - io.js 3.x + - Node.js 4.x + - Node.js 5.x + - Node.js 6.x + - Node.js 7.x + - Node.js 8.x + - Node.js 9.x + - Node.js 10.x + - Node.js 11.x + - Node.js 12.x + - Node.js 13.x + - Node.js 14.x + - Node.js 15.x + - Node.js 16.x + - Node.js 17.x + - Node.js 18.x include: - - name: Node.js 0.8 - node-version: "0.8" - npm-i: mocha@2.5.3 supertest@1.1.0 - npm-rm: nyc + - name: Node.js 0.8 + node-version: "0.8" + npm-i: mocha@2.5.3 supertest@1.1.0 + npm-rm: nyc - - name: Node.js 0.10 - node-version: "0.10" - npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 + - name: Node.js 0.10 + node-version: "0.10" + npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 - - name: Node.js 0.12 - node-version: "0.12" - npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 + - name: Node.js 0.12 + node-version: "0.12" + npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 - - name: io.js 1.x - node-version: "1.8" - npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 + - name: io.js 1.x + node-version: "1.8" + npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 - - name: io.js 2.x - node-version: "2.5" - npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 + - name: io.js 2.x + node-version: "2.5" + npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 - - name: io.js 3.x - node-version: "3.3" - npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 + - name: io.js 3.x + node-version: "3.3" + npm-i: mocha@2.5.3 nyc@10.3.2 supertest@2.0.0 - - name: Node.js 4.x - node-version: "4.9" - npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 + - name: Node.js 4.x + node-version: "4.9" + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - - name: Node.js 5.x - node-version: "5.12" - npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 + - name: Node.js 5.x + node-version: "5.12" + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - - name: Node.js 6.x - node-version: "6.17" - npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 + - name: Node.js 6.x + node-version: "6.17" + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - - name: Node.js 7.x - node-version: "7.10" - npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 + - name: Node.js 7.x + node-version: "7.10" + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - - name: Node.js 8.x - node-version: "8.17" - npm-i: mocha@7.2.0 + - name: Node.js 8.x + node-version: "8.17" + npm-i: mocha@7.2.0 - - name: Node.js 9.x - node-version: "9.11" - npm-i: mocha@7.2.0 + - name: Node.js 9.x + node-version: "9.11" + npm-i: mocha@7.2.0 - - name: Node.js 10.x - node-version: "10.24" - npm-i: mocha@8.4.0 + - name: Node.js 10.x + node-version: "10.24" + npm-i: mocha@8.4.0 - - name: Node.js 11.x - node-version: "11.15" - npm-i: mocha@8.4.0 + - name: Node.js 11.x + node-version: "11.15" + npm-i: mocha@8.4.0 - - name: Node.js 12.x - node-version: "12.22" - npm-i: mocha@9.2.2 + - name: Node.js 12.x + node-version: "12.22" + npm-i: mocha@9.2.2 - - name: Node.js 13.x - node-version: "13.14" - npm-i: mocha@9.2.2 + - name: Node.js 13.x + node-version: "13.14" + npm-i: mocha@9.2.2 - - name: Node.js 14.x - node-version: "14.19" + - name: Node.js 14.x + node-version: "14.19" - - name: Node.js 15.x - node-version: "15.14" + - name: Node.js 15.x + node-version: "15.14" - - name: Node.js 16.x - node-version: "16.15" + - name: Node.js 16.x + node-version: "16.15" - - name: Node.js 17.x - node-version: "17.9" + - name: Node.js 17.x + node-version: "17.9" - - name: Node.js 18.x - node-version: "18.0" + - name: Node.js 18.x + node-version: "18.0" steps: - - uses: actions/checkout@v2 - - - name: Install Node.js ${{ matrix.node-version }} - shell: bash -eo pipefail -l {0} - run: | - nvm install --default ${{ matrix.node-version }} - if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then - nvm install --alias=npm 0.10 - nvm use ${{ matrix.node-version }} - sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" - npm config set strict-ssl false - fi - dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" - - - name: Configure npm - run: npm config set shrinkwrap false - - - name: Remove npm module(s) ${{ matrix.npm-rm }} - run: npm rm --silent --save-dev ${{ matrix.npm-rm }} - if: matrix.npm-rm != '' - - - name: Install npm module(s) ${{ matrix.npm-i }} - run: npm install --save-dev ${{ matrix.npm-i }} - if: matrix.npm-i != '' - - - name: Setup Node.js version-specific dependencies - shell: bash - run: | - # eslint for linting - # - remove on Node.js < 10 - if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then - node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ - grep -E '^eslint(-|$)' | \ - sort -r | \ - xargs -n1 npm rm --silent --save-dev - fi - - - name: Install Node.js dependencies - run: npm install - - - name: List environment - id: list_env - shell: bash - run: | - echo "node@$(node -v)" - echo "npm@$(npm -v)" - npm -s ls ||: - (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' - - - name: Run tests - shell: bash - run: | - if npm -ps ls nyc | grep -q nyc; then - npm run test-ci - else - npm test - fi - - - name: Lint code - if: steps.list_env.outputs.eslint != '' - run: npm run lint - - - name: Collect code coverage - uses: coverallsapp/github-action@master - if: steps.list_env.outputs.nyc != '' - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - flag-name: run-${{ matrix.test_number }} - parallel: true + - uses: actions/checkout@v2 + + - name: Install Node.js ${{ matrix.node-version }} + shell: bash -eo pipefail -l {0} + run: | + nvm install --default ${{ matrix.node-version }} + if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then + nvm install --alias=npm 0.10 + nvm use ${{ matrix.node-version }} + sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" + npm config set strict-ssl false + fi + dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" + + - name: Configure npm + run: npm config set shrinkwrap false + + - name: Remove npm module(s) ${{ matrix.npm-rm }} + run: npm rm --silent --save-dev ${{ matrix.npm-rm }} + if: matrix.npm-rm != '' + + - name: Install npm module(s) ${{ matrix.npm-i }} + run: npm install --save-dev ${{ matrix.npm-i }} + if: matrix.npm-i != '' + + - name: Setup Node.js version-specific dependencies + shell: bash + run: | + # eslint for linting + # - remove on Node.js < 10 + if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then + node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ + grep -E '^eslint(-|$)' | \ + sort -r | \ + xargs -n1 npm rm --silent --save-dev + fi + + - name: Install Node.js dependencies + run: npm install + + - name: List environment + id: list_env + shell: bash + run: | + echo "node@$(node -v)" + echo "npm@$(npm -v)" + npm -s ls ||: + (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' + + - name: Run tests + shell: bash + run: | + if npm -ps ls nyc | grep -q nyc; then + npm run test-ci + else + npm test + fi + + - name: Lint code + if: steps.list_env.outputs.eslint != '' + run: npm run lint + + - name: Collect code coverage + uses: coverallsapp/github-action@master + if: steps.list_env.outputs.nyc != '' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: run-${{ matrix.test_number }} + parallel: true coverage: needs: test - runs-on: ubuntu-latest + runs-on: ["self-hosted", "general-ubuntu-amd"] steps: - - name: Upload code coverage - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + - name: Upload code coverage + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..f0bf8d57 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@classdojo:registry=https://npm.pkg.github.com diff --git a/.yarnrc b/.yarnrc new file mode 100644 index 00000000..8faf0a10 --- /dev/null +++ b/.yarnrc @@ -0,0 +1,2 @@ +registry "https://registry.npmjs.org/" +"@classdojo:registry" "https://npm.pkg.github.com" diff --git a/README.md b/README.md index 45e68a98..55bcfbb1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# NOTE +We've forked this because it doesn't play nicely with our cookie system - one global one and one for each of teach/home/student. +The only change is the block of commented out code in the `getcookie` method. + + # express-session [![NPM Version][npm-version-image]][npm-url] diff --git a/index.js b/index.js index 40a442ba..e7af0b67 100644 --- a/index.js +++ b/index.js @@ -531,6 +531,16 @@ function getcookie(req, name, secrets) { var raw; var val; + // DOJO CHANGE - Use a parsed object for the cookies, instead of parsing them here. + // Since we're already parsing the cookies in previous middleware, this is safe, and it + // allows us to copy the `dojo_teach_login.sid` or other site-specific cookie to overwrite + // the `dojo_login.sid` value. This in turn allows a user to be signed in as both a + // parent and a teacher and a student at the same time. + if (req.signedCookies) { + return req.signedCookies[name]; + } + + // read from cookie header if (header) { var cookies = cookie.parse(header); @@ -551,15 +561,6 @@ function getcookie(req, name, secrets) { } } - // back-compat read from cookieParser() signedCookies data - if (!val && req.signedCookies) { - val = req.signedCookies[name]; - - if (val) { - deprecate('cookie should be available in req.headers.cookie'); - } - } - // back-compat read from cookieParser() cookies data if (!val && req.cookies) { raw = req.cookies[name]; diff --git a/package.json b/package.json index 711e9866..80df9c2e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "express-session", + "name": "@classdojo/express-session", "version": "1.17.3", "description": "Simple session middleware for Express", "author": "TJ Holowaychuk (http://tjholowaychuk.com)", @@ -7,7 +7,10 @@ "Douglas Christopher Wilson ", "Joe Wagner " ], - "repository": "expressjs/session", + "repository": { + "type": "git", + "url": "ssh://git@github.com/classdojo/session.git" + }, "license": "MIT", "dependencies": { "cookie": "0.4.2", diff --git a/test/session.js b/test/session.js index 7416b261..c5aa8b39 100644 --- a/test/session.js +++ b/test/session.js @@ -2205,7 +2205,8 @@ describe('session()', function(){ }) describe('cookieParser()', function () { - it('should read from req.cookies', function(done){ + // only test that fails with dojo changes, because it's about the order of cookie parsing. + xit('should read from req.cookies', function(done){ var app = express() .use(cookieParser()) .use(function(req, res, next){ req.headers.cookie = 'foo=bar'; next() })