/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of Auth-Server-Helper which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , January 2022 */ import { build_cookie, extract_cookie } from '../../lib/cookie'; describe ('cookie', () => { it ('should create a cookie', () => { const pairs = [ { name: 'foo', value: 'bar', result: 'foo=bar; Secure; HttpOnly; SameSite=Strict' }, { name: 'foäöüo', value: 'baäöür', result: 'foäöüo=baäöür; Secure; HttpOnly; SameSite=Strict' } ]; for (const pair of pairs) { expect (build_cookie (pair.name, pair.value)) .toEqual (pair.result); } }); it ('should parse a cookie', () => { const pairs = [ { header: 'foo=bar; Secure; HttpOnly; SameSite=Strict', name: 'foo', value: 'bar' }, { header: '134=567;foäöüo=baäöür;tesT=123', name: 'foäöüo', value: 'baäöür' } ]; for (const pair of pairs) { expect (extract_cookie (pair.name, pair.header)) .toEqual (pair.value); } }); });