diff --git a/.github/workflows/fns.sh b/.github/workflows/fns.sh new file mode 100644 index 0000000..4eeffb7 --- /dev/null +++ b/.github/workflows/fns.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +vercomp () { + if [[ $1 == $2 ]]; then + export vercomp_last_result=0 + return $vercomp_last_result + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]]; then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})); then + export vercomp_last_result=1 + return $vercomp_last_result + fi + if ((10#${ver1[i]} < 10#${ver2[i]})); then + export vercomp_last_result=2 + return $vercomp_last_result + fi + done + export vercomp_last_result=0 + return $vercomp_last_result +} + +install_fibjs() { + local version=$1 + if [[ -z "$version" ]]; then + echo "[install_fibjs] version is required" + exit 1 + fi + local os=$2 + if [[ -z "$os" ]]; then + echo "[install_fibjs] os is required" + exit 1 + fi + local arch=$3 + if [[ -z "$arch" ]]; then + echo "[install_fibjs] arch is required" + exit 1 + fi + + local url_base="https://github.com/fibjs/fibjs/releases/download/v${version}/fibjs-v${version}-${os}-${arch}" + + # in fact, there's also non-archived linux fibjs + if [[ "$RUNNER_OS" == "Linux" ]]; then + if [ "$lower_than_0_37_0" == "true" ]; then + local remote_url="${url_base}.xz" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs.xz; + xz -d ./node_modules/.bin/fibjs.xz; + else + local remote_url="${url_base}.tar.gz" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs.tar.gz; + tar -xzf ./node_modules/.bin/fibjs.tar.gz -C ./node_modules/.bin; + fi + chmod a+x ./node_modules/.bin/fibjs; + elif [[ "$RUNNER_OS" == "macOS" ]]; then + local remote_url="${url_base}" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs; + chmod a+x ./node_modules/.bin/fibjs; + else + local remote_url="${url_base}.exe" + curl -SL "$remote_url" -o ./node_modules/.bin/fibjs.exe; + fi + echo "[install_fibjs] Downloading fibjs from ${remote_url}" +} diff --git a/.github/workflows/run-ci.yml b/.github/workflows/run-ci.yml index f38836e..c75b6af 100644 --- a/.github/workflows/run-ci.yml +++ b/.github/workflows/run-ci.yml @@ -24,14 +24,68 @@ jobs: continue-on-error: true strategy: matrix: - os: [ubuntu-18.04, windows-2019, macos-10.15] - version: [0.33.0, 0.34.0, 0.35.0] - arch: [amd64, i386] - exclude: - - os: windows-2019 - arch: i386 - - os: macos-10.15 - arch: i386 + include: + - os: windows-2019 + arch: x64 + fibjs: 0.34.0 + - os: windows-2019 + arch: x64 + fibjs: 0.35.0 + - os: windows-2019 + arch: x64 + fibjs: 0.36.0 + - os: windows-2019 + arch: x64 + fibjs: 0.37.0 + - os: windows-2019 + arch: x86 + fibjs: 0.34.0 + - os: windows-2019 + arch: x86 + fibjs: 0.35.0 + - os: windows-2019 + arch: x86 + fibjs: 0.36.0 + - os: windows-2019 + arch: x86 + fibjs: 0.37.0 + - os: ubuntu-20.04 + arch: x64 + fibjs: 0.34.0 + - os: ubuntu-20.04 + arch: x64 + fibjs: 0.35.0 + - os: ubuntu-20.04 + arch: x64 + fibjs: 0.36.0 + - os: ubuntu-20.04 + arch: x64 + fibjs: 0.37.0 + - os: ubuntu-20.04 + arch: x86 + fibjs: 0.34.0 + - os: ubuntu-20.04 + arch: x86 + fibjs: 0.35.0 + - os: ubuntu-20.04 + arch: x86 + fibjs: 0.36.0 + - os: ubuntu-20.04 + arch: x86 + fibjs: 0.37.0 + - os: macos-11 + arch: x64 + fibjs: 0.34.0 + - os: macos-11 + arch: x64 + fibjs: 0.35.0 + - os: macos-11 + arch: x64 + fibjs: 0.36.0 + - os: macos-11 + arch: x64 + fibjs: 0.37.0 + steps: - name: Check out Git repository @@ -41,7 +95,7 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: '14' + node-version: '16' - name: Set Env Variables id: set-env-vars @@ -51,26 +105,20 @@ jobs: env: ARCH: ${{ matrix.arch }} OS: ${{ matrix.os }} + FIBJS_VERSION: ${{ matrix.fibjs }} - name: Install FIBJS shell: bash run: | mkdir -p ./node_modules/.bin; rm -rf ./node_modules/.bin/fibjs; - if [[ "$RUNNER_OS" == "Linux" ]]; then - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.xz" -o ./node_modules/.bin/fibjs.xz; - xz -d ./node_modules/.bin/fibjs.xz; - chmod a+x ./node_modules/.bin/fibjs; - elif [[ "$RUNNER_OS" == "macOS" ]]; then - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}" -o ./node_modules/.bin/fibjs; - chmod a+x ./node_modules/.bin/fibjs; - else - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${FIBJS_VERSION}/fibjs-v${FIBJS_VERSION}-${FIBJS_OS}-${FIBJS_ARCH}.exe" -o ./node_modules/.bin/fibjs.exe; - fi + . ./.github/workflows/fns.sh --source-only + install_fibjs $FIBJS_VERSION $FIBJS_OS $FIBJS_ARCH; env: FIBJS_OS: ${{ steps.set-env-vars.outputs.FIBJS_OS }} FIBJS_ARCH: ${{ steps.set-env-vars.outputs.FIBJS_ARCH }} - FIBJS_VERSION: ${{ matrix.version }} + lower_than_0_37_0: ${{ steps.set-env-vars.outputs.lower_than_0_37_0 }} + FIBJS_VERSION: ${{ matrix.fibjs }} - name: Run CI shell: bash diff --git a/.github/workflows/set-env-vars.sh b/.github/workflows/set-env-vars.sh index 9798ca8..64bb0c3 100644 --- a/.github/workflows/set-env-vars.sh +++ b/.github/workflows/set-env-vars.sh @@ -1,3 +1,5 @@ +. ./.github/workflows/fns.sh --source-only + export GIT_BRANCH=${GITHUB_REF#refs/heads/} echo "::set-output name=GIT_BRANCH::$GIT_BRANCH" export GIT_TAG=$(git tag | grep $(git describe --tags HEAD)) @@ -25,9 +27,23 @@ if [ -z "$IS_GIT_TAG_MATCH_SEMVER" ]; then fi echo "::set-output name=RELEASE_TAG::$RELEASE_TAG"; +vercomp "${FIBJS_VERSION}" "0.37.0" +if [[ "$vercomp_last_result" -eq "2" ]]; then + export lower_than_0_37_0="true" +else + export lower_than_0_37_0="false" +fi + +echo "::set-output name=lower_than_0_37_0::$lower_than_0_37_0"; + case "${RUNNER_OS}" in Windows) - export FIBJS_OS=windows + # lower than 0.37.0 + if [[ "$lower_than_0_37_0" == "true" ]]; then + export FIBJS_OS=windows + else + export FIBJS_OS=win32 + fi ;; macOS) export FIBJS_OS=darwin @@ -43,10 +59,14 @@ esac echo "::set-output name=FIBJS_OS::$FIBJS_OS"; case "${ARCH}" in - i386) - export FIBJS_ARCH=x86 + i386|ia32|x86) + if [[ "$lower_than_0_37_0" == "true" ]]; then + export FIBJS_ARCH=x86 + else + export FIBJS_ARCH=ia32 + fi ;; - amd64) + amd64|x64) export FIBJS_ARCH=x64 ;; *) diff --git a/@types/basic.d.ts b/@types/basic.d.ts index 705a3fb..4d55f1f 100644 --- a/@types/basic.d.ts +++ b/@types/basic.d.ts @@ -41,7 +41,14 @@ declare namespace FibSessionNS { cache_size?: number; cache_timeout?: number; } - interface Options extends StoreOptions, FibKvOptions { + type FibJwtOptions = { + /** + * @description if disable_auto_hex_key is set, we would make sure all keys are hex string/Buffer + */ + disable_auto_hex_key?: boolean + } + + interface Options extends StoreOptions, FibKvOptions, FibJwtOptions { expires?: number; } interface Store { diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index b6b839b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,18 +0,0 @@ -environment: - nodejs_version: '6' - matrix: - - VERSION: 0.33.0 - - VERSION: 0.34.0 - - VERSION: 0.35.0 - -install: - - ps: Install-Product node $env:nodejs_version - - npm i - - If Not Exist "node_modules\.bin" (mkdir node_modules\.bin) - - curl -fsSL -o node_modules\.bin\fibjs.cab "https://github.com/fibjs/fibjs/releases/download/v%VERSION%/fibjs-v%VERSION%-windows-x64.cab" - - expand node_modules\.bin\fibjs.cab node_modules\.bin\fibjs.exe - -test_script: - - npm run ci - -build: off diff --git a/package.json b/package.json index dab7993..5de4385 100644 --- a/package.json +++ b/package.json @@ -26,22 +26,24 @@ "ci-sqlite": "npm run build && npm run test" }, "ci": { - "type": "actions, appveyor", + "type": "actions", "version": [ - "0.33.0", "0.34.0", - "0.35.0" + "0.35.0", + "0.36.0", + "0.37.0" ] }, "dependencies": { - "fib-jws": "^0.1.1", + "fib-jws": "^0.4.1", "fib-kv": "^1.3.1" }, "devDependencies": { - "@fibjs/ci": "^2.6.0", + "@fibjs/ci": "^2.7.1", + "@fibjs/detect-port": "^1.0.2", "@fibjs/types": "^0.35.0", "cross-env": "^5.2.0", "fib-pool": "^1.6.0", - "fib-typify": "^0.11.4" + "fib-typify": "^0.11.6" } } diff --git a/src/index.ts b/src/index.ts index 5d77814..7a54eed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,9 +29,11 @@ const Session = function (conn: FibKV.FibKVInstance | Class_DbConnection | FibPo // JWT(JSON Web Token) const jwt_algo = utils.jwt_algo(opts); const jwt_key = utils.jwt_key(opts); + const fib_jwt_opts = { disable_auto_hex_key: opts.disable_auto_hex_key }; + if (jwt_algo && jwt_key) { - this.getToken = jwt.getToken(jwt_algo); - this.setTokenCookie = jwt.setTokenCookie(jwt_algo, utils.sid(opts)); + this.getToken = jwt.getToken(jwt_algo, fib_jwt_opts); + this.setTokenCookie = jwt.setTokenCookie(jwt_algo, utils.sid(opts), fib_jwt_opts); } this.cookie_filter = (r: FibSessionNS.HttpRequest) => { @@ -39,7 +41,7 @@ const Session = function (conn: FibKV.FibKVInstance | Class_DbConnection | FibPo r.sessionid = sessionid; if (jwt_algo && jwt_key) { //JWT - jwt.filter(r, jwt_algo, jwt_key, utils.sid(opts), proxy); + jwt.filter(r, jwt_algo, jwt_key, utils.sid(opts), proxy, fib_jwt_opts); } else { let obj = {}; if (!sessionid || util.isEmpty(obj = store.get(sessionid))) { @@ -63,7 +65,7 @@ const Session = function (conn: FibKV.FibKVInstance | Class_DbConnection | FibPo r.sessionid = sessionid || undefined; if (jwt_algo && jwt_key) { - jwt.filter(r, jwt_algo, jwt_key, utils.sid(opts), proxy); + jwt.filter(r, jwt_algo, jwt_key, utils.sid(opts), proxy, fib_jwt_opts); } else { let obj = {}; if (!sessionid || !(obj = store.get(sessionid))) { diff --git a/src/jwt.ts b/src/jwt.ts index 46e9a06..9d0faa5 100644 --- a/src/jwt.ts +++ b/src/jwt.ts @@ -1,7 +1,13 @@ const jws = require('fib-jws'); -export function getToken (jwt_algo: string) { - return (obj: FibSessionNS.Object, key: string) => { +function inputIsBuffer (bufOrString: string | Class_Buffer): bufOrString is Class_Buffer { + return Buffer.isBuffer(bufOrString); +} + +export function getToken (jwt_algo: string, opts?: FibSessionNS.FibJwtOptions) { + return (obj: FibSessionNS.Object, key: string | Class_Buffer) => { + if (!opts?.disable_auto_hex_key && !inputIsBuffer(key)) + key = new Buffer(key, 'hex') /** * jws.sign * header={ alg: 'HS256' } @@ -12,9 +18,11 @@ export function getToken (jwt_algo: string) { } } -export function setTokenCookie (jwt_algo: string, cookie_name: string) { - return (r: FibSessionNS.HttpRequest, obj: FibSessionNS.Object, key: string) => { +export function setTokenCookie (jwt_algo: string, cookie_name: string, opts?: FibSessionNS.FibJwtOptions) { + return (r: FibSessionNS.HttpRequest, obj: FibSessionNS.Object, key: string | Class_Buffer) => { r.session = obj; + if (!opts?.disable_auto_hex_key && !inputIsBuffer(key)) + key = new Buffer(key, 'hex') r.sessionid = jws.sign({alg: jwt_algo}, obj, key); r.response.addCookie({ @@ -26,7 +34,10 @@ export function setTokenCookie (jwt_algo: string, cookie_name: string) { }; } -export function getPayload (text: string, key: string, algo: string) { +export function getPayload (text: string, key: string | Class_Buffer, algo: string, opts?: FibSessionNS.FibJwtOptions) { + if (!opts?.disable_auto_hex_key && !inputIsBuffer(key)) + key = new Buffer(key, 'hex') + if (jws.verify(text, key, algo)) { var dc = jws.decode(text); if (dc && dc.payload) { @@ -39,10 +50,17 @@ export function getPayload (text: string, key: string, algo: string) { } } -export function filter (r: FibSessionNS.HttpRequest, jwt_algo: string, jwt_key: string, cookie_name: string, proxy: FibSessionNS.SessionProxyGenerator) { +export function filter ( + r: FibSessionNS.HttpRequest, + jwt_algo: string, + jwt_key: string, + cookie_name: string, + proxy: FibSessionNS.SessionProxyGenerator, + opts?: FibSessionNS.FibJwtOptions +) { let obj; if (r.sessionid) { - obj = getPayload(r.sessionid, jwt_key, jwt_algo); + obj = getPayload(r.sessionid, jwt_key, jwt_algo, opts); } r.session = proxy(null, obj, r.sessionid, true, true); diff --git a/test/index.js b/test/index.js index 80e2294..a07e5a3 100644 --- a/test/index.js +++ b/test/index.js @@ -15,6 +15,8 @@ const pool = require('fib-pool'); const util = require('util'); const coroutine = require('coroutine'); +const detect_port = require('@fibjs/detect-port'); + const { startServer, stopServer } = require('./spec_helper'); // the assertions before `wait()` might fail if the leading operations take too long to finish @@ -25,7 +27,7 @@ let wait = function (n = delay) { let url = { protocol: 'http', domain: '127.0.0.1', - port: 8080, + port: detect_port(), get ['host']() { return this.protocol + '://' + this.domain + ':' + this.port }, @@ -57,7 +59,7 @@ function resDataToObj (resData) { function session_test(description, opts, test_opts, _before, _after) { describe(`${description} - ${querystring.stringify(test_opts, null)}`, () => { - var { use_existed_kv = false } = test_opts; + var { use_existed_kv = false, disable_auto_hex_key } = test_opts; before(() => { kv_db = new kv(_before(), opts); @@ -66,9 +68,9 @@ function session_test(description, opts, test_opts, _before, _after) { function setup_session(_opts) { if (use_existed_kv) - session = new Session(kv_db, _opts); + session = new Session(kv_db, {..._opts, disable_auto_hex_key }); else - session = new Session(conn, _opts); + session = new Session(conn, {..._opts, disable_auto_hex_key }); session.setup(); } @@ -82,13 +84,15 @@ function session_test(description, opts, test_opts, _before, _after) { after(() => stopServer(srv)); it('server', () => { - ++url.port; + url.port = detect_port(); srv = new http.Server(url.port, [ session.cookie_filter, { '^/user$': (r) => r.session && (r.session.username = r.query.username), - '^/get$': (r) => r.response.write(r.session.username), + '^/get$': (r) => { + r.response.write(r.session.username || '') + }, '^/del$': (r) => delete r.session.username, '^/remove$': (r) => session.remove(r.sessionid), '^/set$': (r) => { @@ -394,7 +398,7 @@ function session_test(description, opts, test_opts, _before, _after) { after(() => stopServer(srv)); it('server', () => { - ++url.port; + url.port = detect_port(); srv = new http.Server(url.port, [ session.cookie_filter, { @@ -466,7 +470,7 @@ function session_test(description, opts, test_opts, _before, _after) { after(() => stopServer(srv)); it('server', () => { - ++url.port; + url.port = detect_port(); srv = new http.Server(url.port, [ session.api_filter, { @@ -942,7 +946,7 @@ function session_test(description, opts, test_opts, _before, _after) { let srv; after(() => stopServer(srv)); it('check token', () => { - ++url.port; + url.port = detect_port(); srv = new http.Server(url.port, [ session.cookie_filter, (r) => { @@ -995,7 +999,11 @@ function session_test(description, opts, test_opts, _before, _after) { var b = true; for (var i = 0; res.cookies && i < res.cookies.length; i++) { if (res.cookies[i] && res.cookies[i].name == 'sessionID') { - assert.equal(res.cookies[i].value, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTIzNDUsIm5hbWUiOiJGcmFuayJ9.adE0u7POp1NG1GHQjZUGb9lfovw9-GdEVusqh2Sc0-M'); + if (disable_auto_hex_key) { + assert.equal(res.cookies[i].value, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTIzNDUsIm5hbWUiOiJGcmFuayJ9.AeI5krHDMPiNFc4IikrdrYbm9qdsDwdz8p1X9GwADEE'); + } else { + assert.equal(res.cookies[i].value, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTIzNDUsIm5hbWUiOiJGcmFuayJ9.adE0u7POp1NG1GHQjZUGb9lfovw9-GdEVusqh2Sc0-M'); + } b = false; } } @@ -1019,7 +1027,11 @@ function session_test(description, opts, test_opts, _before, _after) { var jwt_token = session.getToken({ abc: 'xyz' }, 'test'); - assert.equal(jwt_token, 'eyJhbGciOiJIUzI1NiJ9.eyJhYmMiOiJ4eXoifQ.ltcUVSz3Np3ZSLpk7TwtTFFjlNY8X2nikCGcuF2ZMgE') + if (disable_auto_hex_key) { + assert.equal(jwt_token, 'eyJhbGciOiJIUzI1NiJ9.eyJhYmMiOiJ4eXoifQ.qiVRBz9pUjJUDBO6-083u1wCyGxzFJ6B0USk8iSrEUE') + } else { + assert.equal(jwt_token, 'eyJhbGciOiJIUzI1NiJ9.eyJhYmMiOiJ4eXoifQ.ltcUVSz3Np3ZSLpk7TwtTFFjlNY8X2nikCGcuF2ZMgE') + } }); }); describe('api in JWT', function () { @@ -1044,7 +1056,7 @@ function session_test(description, opts, test_opts, _before, _after) { after(() => stopServer(srv)); it('server', () => { - ++url.port; + url.port = detect_port(); srv = new http.Server(url.port, [ (r) => { try { @@ -1099,7 +1111,11 @@ function session_test(description, opts, test_opts, _before, _after) { let res = new http.Client().get(url.host + '/user?id=50&username=hoo'); save_id = res.cookies[0].value; //console.error('save_id:', res.cookies[0].value); - assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUwIiwidXNlcm5hbWUiOiJob28ifQ.ubTia0QE_D-aT8ziMShJEwgnbujatqTJC7amOhxabzw'); + if (disable_auto_hex_key) { + assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUwIiwidXNlcm5hbWUiOiJob28ifQ.W3sB7wnqxIPxhLuxE2qLWWO5aCY8O2F6sIWA05u9B-Q'); + } else { + assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUwIiwidXNlcm5hbWUiOiJob28ifQ.ubTia0QE_D-aT8ziMShJEwgnbujatqTJC7amOhxabzw'); + } assert.deepEqual(request_session, { "id": "50", "username": "hoo" @@ -1111,7 +1127,12 @@ function session_test(description, opts, test_opts, _before, _after) { } }); //console.error('save_id2:', res.cookies[0].value); - assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + + if (disable_auto_hex_key) { + assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.aKU95JiljVGiJiw5OU4PmIk6Vm6wJoIrkXBSDbeCmac') + } else { + assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + } assert.deepEqual(request_session, { "id": "8", "username": "lion" @@ -1143,7 +1164,11 @@ function session_test(description, opts, test_opts, _before, _after) { let client = new http.Client(); let res = client.get(url.host + '/user?id=8&username=lion'); save_id = res.cookies[0].value; - assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + if (disable_auto_hex_key) { + assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.aKU95JiljVGiJiw5OU4PmIk6Vm6wJoIrkXBSDbeCmac') + } else { + assert.equal(save_id, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + } assert.equal(request_sessionid, save_id); assert.equal(request_session.username, 'lion'); res = client.get(url.host + '/get', { @@ -1151,7 +1176,11 @@ function session_test(description, opts, test_opts, _before, _after) { sessionID: save_id } }); - assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + if (disable_auto_hex_key) { + assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.aKU95JiljVGiJiw5OU4PmIk6Vm6wJoIrkXBSDbeCmac') + } else { + assert.equal(request_sessionid, 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjgiLCJ1c2VybmFtZSI6Imxpb24ifQ.bN9IiVDgy2qfQgndBv5SfyLSEotTw1RjK3hgjR-VJpM'); + } assert.equal(request_session.username, 'lion'); assert.equal(JSON.parse(res.data.toString()).username, 'lion'); assert.deepEqual(session.get(request_sessionid), {}); @@ -1253,8 +1282,9 @@ function session_test(description, opts, test_opts, _before, _after) { } ;[ - { use_existed_kv: true }, - { use_existed_kv: false }, + // { use_existed_kv: true }, + { use_existed_kv: true, disable_auto_hex_key: true }, + // { use_existed_kv: false }, ].forEach((test_opts) => { session_test( 'SQLite', { @@ -1316,5 +1346,5 @@ function session_test(description, opts, test_opts, _before, _after) { }); }); -const hr = test.run(console.DEBUG); -process.exit(hr); \ No newline at end of file +test.run(console.DEBUG); +process.exit(); \ No newline at end of file