|
| 1 | +'use strict'; |
| 2 | +varcommon=require('../common'); |
| 3 | +varassert=require('assert'); |
| 4 | + |
| 5 | +if(!common.hasCrypto){ |
| 6 | +console.log('1..0 # Skipped: missing crypto'); |
| 7 | +return; |
| 8 | +} |
| 9 | + |
| 10 | +varhttps=require('https'); |
| 11 | +varcrypto=require('crypto'); |
| 12 | + |
| 13 | +varfs=require('fs'); |
| 14 | + |
| 15 | +varoptions={ |
| 16 | +key: fs.readFileSync(common.fixturesDir+'/keys/agent1-key.pem'), |
| 17 | +cert: fs.readFileSync(common.fixturesDir+'/keys/agent1-cert.pem') |
| 18 | +}; |
| 19 | + |
| 20 | +varca=fs.readFileSync(common.fixturesDir+'/keys/ca1-cert.pem'); |
| 21 | + |
| 22 | +varclientSessions={}; |
| 23 | +varserverRequests=0; |
| 24 | + |
| 25 | +varagent=newhttps.Agent({ |
| 26 | +maxCachedSessions: 1 |
| 27 | +}); |
| 28 | + |
| 29 | +varserver=https.createServer(options,function(req,res){ |
| 30 | +if(req.url==='/drop-key') |
| 31 | +server.setTicketKeys(crypto.randomBytes(48)); |
| 32 | + |
| 33 | +serverRequests++; |
| 34 | +res.end('ok'); |
| 35 | +}).listen(common.PORT,function(){ |
| 36 | +varqueue=[ |
| 37 | +{ |
| 38 | +name: 'first', |
| 39 | + |
| 40 | +method: 'GET', |
| 41 | +path: '/', |
| 42 | +servername: 'agent1', |
| 43 | +ca: ca, |
| 44 | +port: common.PORT |
| 45 | +}, |
| 46 | +{ |
| 47 | +name: 'first-reuse', |
| 48 | + |
| 49 | +method: 'GET', |
| 50 | +path: '/', |
| 51 | +servername: 'agent1', |
| 52 | +ca: ca, |
| 53 | +port: common.PORT |
| 54 | +}, |
| 55 | +{ |
| 56 | +name: 'cipher-change', |
| 57 | + |
| 58 | +method: 'GET', |
| 59 | +path: '/', |
| 60 | +servername: 'agent1', |
| 61 | + |
| 62 | +// Choose different cipher to use different cache entry |
| 63 | +ciphers: 'AES256-SHA', |
| 64 | +ca: ca, |
| 65 | +port: common.PORT |
| 66 | +}, |
| 67 | +// Change the ticket key to ensure session is updated in cache |
| 68 | +{ |
| 69 | +name: 'before-drop', |
| 70 | + |
| 71 | +method: 'GET', |
| 72 | +path: '/drop-key', |
| 73 | +servername: 'agent1', |
| 74 | +ca: ca, |
| 75 | +port: common.PORT |
| 76 | +}, |
| 77 | + |
| 78 | +// Ticket will be updated starting from this |
| 79 | +{ |
| 80 | +name: 'after-drop', |
| 81 | + |
| 82 | +method: 'GET', |
| 83 | +path: '/', |
| 84 | +servername: 'agent1', |
| 85 | +ca: ca, |
| 86 | +port: common.PORT |
| 87 | +}, |
| 88 | +{ |
| 89 | +name: 'after-drop-reuse', |
| 90 | + |
| 91 | +method: 'GET', |
| 92 | +path: '/', |
| 93 | +servername: 'agent1', |
| 94 | +ca: ca, |
| 95 | +port: common.PORT |
| 96 | +} |
| 97 | +]; |
| 98 | + |
| 99 | +functionrequest(){ |
| 100 | +varoptions=queue.shift(); |
| 101 | +options.agent=agent; |
| 102 | +https.request(options,function(res){ |
| 103 | +clientSessions[options.name]=res.socket.getSession(); |
| 104 | + |
| 105 | +res.resume(); |
| 106 | +res.on('end',function(){ |
| 107 | +if(queue.length!==0) |
| 108 | +returnrequest(); |
| 109 | +server.close(); |
| 110 | +}); |
| 111 | +}).end(); |
| 112 | +} |
| 113 | +request(); |
| 114 | +}); |
| 115 | + |
| 116 | +process.on('exit',function(){ |
| 117 | +assert.equal(serverRequests,6); |
| 118 | +assert.equal(clientSessions['first'].toString('hex'), |
| 119 | +clientSessions['first-reuse'].toString('hex')); |
| 120 | +assert.notEqual(clientSessions['first'].toString('hex'), |
| 121 | +clientSessions['cipher-change'].toString('hex')); |
| 122 | +assert.notEqual(clientSessions['first'].toString('hex'), |
| 123 | +clientSessions['before-drop'].toString('hex')); |
| 124 | +assert.notEqual(clientSessions['cipher-change'].toString('hex'), |
| 125 | +clientSessions['before-drop'].toString('hex')); |
| 126 | +assert.notEqual(clientSessions['before-drop'].toString('hex'), |
| 127 | +clientSessions['after-drop'].toString('hex')); |
| 128 | +assert.equal(clientSessions['after-drop'].toString('hex'), |
| 129 | +clientSessions['after-drop-reuse'].toString('hex')); |
| 130 | +}); |
0 commit comments