How to use cookieSession method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

MobileMicToPC_node_modules_express_node_modules_connect_lib-cov_middleware_cookieSession.js

Source:MobileMicToPC_node_modules_express_node_modules_connect_lib-cov_middleware_cookieSession.js Github

copy

Full Screen

...40}41_$jscoverage['middleware/cookieSession.js'][12]++;42var utils = require("./../utils"), Cookie = require("./session/cookie"), debug = require("debug")("connect:cookieSession"), signature = require("cookie-signature"), crc16 = require("crc").crc16;43_$jscoverage['middleware/cookieSession.js'][46]++;44module.exports = (function cookieSession(options) {45 _$jscoverage['middleware/cookieSession.js'][48]++;46 options = options || {};47 _$jscoverage['middleware/cookieSession.js'][49]++;48 var key = options.key || "connect.sess", trustProxy = options.proxy;49 _$jscoverage['middleware/cookieSession.js'][52]++;50 return (function cookieSession(req, res, next) {51 _$jscoverage['middleware/cookieSession.js'][55]++;52 var secret = options.secret || req.secret;53 _$jscoverage['middleware/cookieSession.js'][56]++;54 if (! secret) {55 _$jscoverage['middleware/cookieSession.js'][56]++;56 throw new Error("`secret` option required for cookie sessions");57 }58 _$jscoverage['middleware/cookieSession.js'][59]++;59 req.session = {};60 _$jscoverage['middleware/cookieSession.js'][60]++;61 var cookie = req.session.cookie = new Cookie(options.cookie);62 _$jscoverage['middleware/cookieSession.js'][63]++;63 if (0 != req.originalUrl.indexOf(cookie.path)) {64 _$jscoverage['middleware/cookieSession.js'][63]++;65 return next();66 }67 _$jscoverage['middleware/cookieSession.js'][66]++;68 if (! options.secret && req.secret) {69 _$jscoverage['middleware/cookieSession.js'][67]++;70 req.session = req.signedCookies[key] || {};71 }72 else {73 _$jscoverage['middleware/cookieSession.js'][70]++;74 var rawCookie = req.cookies[key];75 _$jscoverage['middleware/cookieSession.js'][71]++;76 if (rawCookie) {77 _$jscoverage['middleware/cookieSession.js'][72]++;78 var unsigned = utils.parseSignedCookie(rawCookie, secret);79 _$jscoverage['middleware/cookieSession.js'][73]++;80 if (unsigned) {81 _$jscoverage['middleware/cookieSession.js'][74]++;82 var originalHash = crc16(unsigned);83 _$jscoverage['middleware/cookieSession.js'][75]++;84 req.session = utils.parseJSONCookie(unsigned) || {};85 }86 }87 }88 _$jscoverage['middleware/cookieSession.js'][80]++;89 res.on("header", (function () {90 _$jscoverage['middleware/cookieSession.js'][82]++;91 if (! req.session) {92 _$jscoverage['middleware/cookieSession.js'][83]++;93 debug("clear session");94 _$jscoverage['middleware/cookieSession.js'][84]++;95 cookie.expires = new Date(0);96 _$jscoverage['middleware/cookieSession.js'][85]++;97 res.setHeader("Set-Cookie", cookie.serialize(key, ""));98 _$jscoverage['middleware/cookieSession.js'][86]++;99 return;100 }101 _$jscoverage['middleware/cookieSession.js'][89]++;102 delete req.session.cookie;103 _$jscoverage['middleware/cookieSession.js'][92]++;104 var proto = (req.headers["x-forwarded-proto"] || "").toLowerCase(), tls = req.connection.encrypted || (trustProxy && "https" == proto), secured = cookie.secure && tls;105 _$jscoverage['middleware/cookieSession.js'][97]++;106 if (cookie.secure && ! secured) {107 _$jscoverage['middleware/cookieSession.js'][97]++;108 return debug("not secured");109 }110 _$jscoverage['middleware/cookieSession.js'][100]++;111 debug("serializing %j", req.session);112 _$jscoverage['middleware/cookieSession.js'][101]++;113 var val = "j:" + JSON.stringify(req.session);114 _$jscoverage['middleware/cookieSession.js'][104]++;115 if (originalHash == crc16(val)) {116 _$jscoverage['middleware/cookieSession.js'][104]++;117 return debug("unmodified session");118 }119 _$jscoverage['middleware/cookieSession.js'][107]++;120 val = "s:" + signature.sign(val, secret);121 _$jscoverage['middleware/cookieSession.js'][108]++;122 val = cookie.serialize(key, val);123 _$jscoverage['middleware/cookieSession.js'][109]++;124 debug("set-cookie %j", cookie);125 _$jscoverage['middleware/cookieSession.js'][110]++;126 res.setHeader("Set-Cookie", val);127}));128 _$jscoverage['middleware/cookieSession.js'][113]++;129 next();130});131});...

Full Screen

Full Screen

sessionStore.ts

Source:sessionStore.ts Github

copy

Full Screen

1import type { CookieOptions } from '../../browser/cookie'2import { COOKIE_ACCESS_DELAY } from '../../browser/cookie'3import { monitor } from '../../tools/monitor'4import { Observable } from '../../tools/observable'5import { dateNow } from '../../tools/timeUtils'6import * as utils from '../../tools/utils'7import { SESSION_TIME_OUT_DELAY } from './sessionConstants'8import { retrieveSession, withCookieLockAccess } from './sessionCookieStore'9export interface SessionStore {10 expandOrRenewSession: () => void11 expandSession: () => void12 getSession: () => SessionState13 renewObservable: Observable<void>14 expireObservable: Observable<void>15 stop: () => void16}17export interface SessionState {18 id?: string19 created?: string20 expire?: string21 lock?: string22 [key: string]: string | undefined23}24/**25 * Different session concepts:26 * - tracked, the session has an id and is updated along the user navigation27 * - not tracked, the session does not have an id but it is updated along the user navigation28 * - inactive, no session in store or session expired, waiting for a renew session29 */30export function startSessionStore<TrackingType extends string>(31 options: CookieOptions,32 productKey: string,33 computeSessionState: (rawTrackingType?: string) => { trackingType: TrackingType; isTracked: boolean }34): SessionStore {35 const renewObservable = new Observable<void>()36 const expireObservable = new Observable<void>()37 const watchSessionTimeoutId = setInterval(monitor(watchSession), COOKIE_ACCESS_DELAY)38 let sessionCache: SessionState = retrieveActiveSession()39 function expandOrRenewSession() {40 let isTracked: boolean41 withCookieLockAccess({42 options,43 process: (cookieSession) => {44 const synchronizedSession = synchronizeSession(cookieSession)45 isTracked = expandOrRenewCookie(synchronizedSession)46 return synchronizedSession47 },48 after: (cookieSession) => {49 if (isTracked && !hasSessionInCache()) {50 renewSession(cookieSession)51 }52 sessionCache = cookieSession53 },54 })55 }56 function expandSession() {57 withCookieLockAccess({58 options,59 process: (cookieSession) => (hasSessionInCache() ? synchronizeSession(cookieSession) : undefined),60 })61 }62 /**63 * allows two behaviors:64 * - if the session is active, synchronize the session cache without updating the session cookie65 * - if the session is not active, clear the session cookie and expire the session cache66 */67 function watchSession() {68 withCookieLockAccess({69 options,70 process: (cookieSession) => (!isActiveSession(cookieSession) ? {} : undefined),71 after: synchronizeSession,72 })73 }74 function synchronizeSession(cookieSession: SessionState) {75 if (!isActiveSession(cookieSession)) {76 cookieSession = {}77 }78 if (hasSessionInCache()) {79 if (isSessionInCacheOutdated(cookieSession)) {80 expireSession()81 } else {82 sessionCache = cookieSession83 }84 }85 return cookieSession86 }87 function expandOrRenewCookie(cookieSession: SessionState) {88 const { trackingType, isTracked } = computeSessionState(cookieSession[productKey])89 cookieSession[productKey] = trackingType90 if (isTracked && !cookieSession.id) {91 cookieSession.id = utils.generateUUID()92 cookieSession.created = String(dateNow())93 }94 return isTracked95 }96 function hasSessionInCache() {97 return sessionCache[productKey] !== undefined98 }99 function isSessionInCacheOutdated(cookieSession: SessionState) {100 return sessionCache.id !== cookieSession.id || sessionCache[productKey] !== cookieSession[productKey]101 }102 function expireSession() {103 sessionCache = {}104 expireObservable.notify()105 }106 function renewSession(cookieSession: SessionState) {107 sessionCache = cookieSession108 renewObservable.notify()109 }110 function retrieveActiveSession(): SessionState {111 const session = retrieveSession()112 if (isActiveSession(session)) {113 return session114 }115 return {}116 }117 function isActiveSession(session: SessionState) {118 // created and expire can be undefined for versions which was not storing them119 // these checks could be removed when older versions will not be available/live anymore120 return (121 (session.created === undefined || dateNow() - Number(session.created) < SESSION_TIME_OUT_DELAY) &&122 (session.expire === undefined || dateNow() < Number(session.expire))123 )124 }125 return {126 expandOrRenewSession: utils.throttle(monitor(expandOrRenewSession), COOKIE_ACCESS_DELAY).throttled,127 expandSession,128 getSession: () => sessionCache,129 renewObservable,130 expireObservable,131 stop: () => {132 clearInterval(watchSessionTimeoutId)133 },134 }...

Full Screen

Full Screen

CookieSession.js

Source:CookieSession.js Github

copy

Full Screen

...4 constructor({ req, session }) {5 this._cookieSession = session6 this._init(req)7 }8 get cookieSession() {9 return this.cookieSession10 }11 setUser({ id, accessToken }) {12 if (!id) {13 throw new Error('User must have id')14 }15 if (!accessToken) {16 throw new Error('User must have accessToken')17 }18 this.cookieSession._saUserId = id19 this.cookieSession._saUserAccessToken = accessToken20 this.cookieSession._saUserSetAt = Date.now()21 return this.getUser()22 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful