|
| 1 | +var expect = require('chai').expect; |
| 2 | +var fs = require('fs'); |
| 3 | + |
| 4 | + |
| 5 | +(typeof window === 'undefined' ? describe : describe.skip)('Requester Spec: sslKeyLogFile', function () { |
| 6 | + var tmp, |
| 7 | + path, |
| 8 | + testrun, |
| 9 | + tmpDir, |
| 10 | + sslKeyLogFilePath; |
| 11 | + |
| 12 | + before(function () { |
| 13 | + tmp = require('tmp'); |
| 14 | + path = require('path'); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('with sslKeyLogFile', function () { |
| 18 | + before(function (done) { |
| 19 | + tmpDir = tmp.dirSync({ unsafeCleanup: true }); |
| 20 | + sslKeyLogFilePath = path.join(tmpDir.name, 'ssl-keylog.txt'); |
| 21 | + |
| 22 | + |
| 23 | + this.run({ |
| 24 | + requester: { |
| 25 | + strictSSL: false, |
| 26 | + sslKeyLogFile: sslKeyLogFilePath |
| 27 | + }, |
| 28 | + collection: { |
| 29 | + item: [{ |
| 30 | + request: global.servers.https |
| 31 | + }] |
| 32 | + } |
| 33 | + }, function (err, results) { |
| 34 | + testrun = results; |
| 35 | + done(err); |
| 36 | + }); |
| 37 | + }); |
| 38 | + after(function () { |
| 39 | + // Clean up temporary directory |
| 40 | + if (tmpDir) { |
| 41 | + tmpDir.removeCallback(); |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + it('should complete the run', function () { |
| 46 | + expect(testrun).to.be.ok; |
| 47 | + expect(testrun).to.nested.include({ |
| 48 | + 'done.calledOnce': true, |
| 49 | + 'start.calledOnce': true, |
| 50 | + 'request.calledOnce': true |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should write SSL key log data to the specified file', function () { |
| 55 | + // Check that the file exists |
| 56 | + expect(fs.existsSync(sslKeyLogFilePath)).to.be.true; |
| 57 | + |
| 58 | + // Read the file contents |
| 59 | + const fileContents = fs.readFileSync(sslKeyLogFilePath, 'utf8'); |
| 60 | + |
| 61 | + // Verify the file has content (SSL key log entries) |
| 62 | + expect(fileContents).to.be.a('string'); |
| 63 | + expect(fileContents.length).to.be.greaterThan(0); |
| 64 | + |
| 65 | + // SSL key log format should contain CLIENT_RANDOM or other SSL key log entries |
| 66 | + // The format is typically lines like: "CLIENT_RANDOM <hex> <hex>" |
| 67 | + expect(fileContents).to.match(/CLIENT_/); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + describe('with sslKeyLogFile and non-empty file', function () { |
| 72 | + before(function (done) { |
| 73 | + tmpDir = tmp.dirSync({ unsafeCleanup: true }); |
| 74 | + sslKeyLogFilePath = path.join(tmpDir.name, 'ssl-keylog.txt'); |
| 75 | + |
| 76 | + // Write some content to the file |
| 77 | + fs.writeFileSync(sslKeyLogFilePath, '1234567890'); |
| 78 | + |
| 79 | + this.run({ |
| 80 | + requester: { |
| 81 | + strictSSL: false, |
| 82 | + sslKeyLogFile: sslKeyLogFilePath |
| 83 | + }, |
| 84 | + collection: { |
| 85 | + item: [{ |
| 86 | + request: global.servers.https |
| 87 | + }] |
| 88 | + } |
| 89 | + }, function (err, results) { |
| 90 | + testrun = results; |
| 91 | + done(err); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + after(function () { |
| 96 | + // Clean up temporary directory |
| 97 | + if (tmpDir) { |
| 98 | + tmpDir.removeCallback(); |
| 99 | + } |
| 100 | + }); |
| 101 | + |
| 102 | + it('should complete the run', function () { |
| 103 | + expect(testrun).to.be.ok; |
| 104 | + expect(testrun).to.nested.include({ |
| 105 | + 'done.calledOnce': true, |
| 106 | + 'start.calledOnce': true, |
| 107 | + 'request.calledOnce': true |
| 108 | + }); |
| 109 | + }); |
| 110 | + it('should append to the existing SSL key log data in the specified file', function () { |
| 111 | + // Check that the file exists |
| 112 | + expect(fs.existsSync(sslKeyLogFilePath)).to.be.true; |
| 113 | + |
| 114 | + // Read the file contents |
| 115 | + const fileContents = fs.readFileSync(sslKeyLogFilePath, 'utf8'); |
| 116 | + |
| 117 | + // Verify the file has content (SSL key log entries) |
| 118 | + expect(fileContents).to.be.a('string'); |
| 119 | + expect(fileContents.length).to.be.greaterThan(0); |
| 120 | + |
| 121 | + // Verify the file contains the existing content |
| 122 | + expect(fileContents).to.include('1234567890'); |
| 123 | + |
| 124 | + // Verify the file contains the new content |
| 125 | + expect(fileContents).to.include('CLIENT_HANDSHAKE_TRAFFIC_SECRET'); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + describe('without sslKeyLogFile', function () { |
| 130 | + before(function (done) { |
| 131 | + tmpDir = tmp.dirSync({ unsafeCleanup: true }); |
| 132 | + sslKeyLogFilePath = path.join(tmpDir.name, 'ssl-keylog.txt'); |
| 133 | + |
| 134 | + this.run({ |
| 135 | + requester: { |
| 136 | + strictSSL: false |
| 137 | + }, |
| 138 | + collection: { |
| 139 | + item: [{ |
| 140 | + request: global.servers.https |
| 141 | + }] |
| 142 | + } |
| 143 | + }, function (err, results) { |
| 144 | + testrun = results; |
| 145 | + done(err); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + after(function () { |
| 150 | + // Clean up temporary directory |
| 151 | + if (tmpDir) { |
| 152 | + tmpDir.removeCallback(); |
| 153 | + } |
| 154 | + }); |
| 155 | + |
| 156 | + it('should complete the run', function () { |
| 157 | + expect(testrun).to.be.ok; |
| 158 | + expect(testrun).to.nested.include({ |
| 159 | + 'done.calledOnce': true, |
| 160 | + 'start.calledOnce': true, |
| 161 | + 'request.calledOnce': true |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should not have any SSL key log data in the file', function () { |
| 166 | + // Check that the file does not exist |
| 167 | + expect(fs.existsSync(sslKeyLogFilePath)).to.be.false; |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + describe('with invalid sslKeyLogFile path', function () { |
| 172 | + before(function (done) { |
| 173 | + tmpDir = tmp.dirSync({ unsafeCleanup: true }); |
| 174 | + sslKeyLogFilePath = path.join(tmpDir.name, 'ssl-keylog.txt'); |
| 175 | + |
| 176 | + this.run({ |
| 177 | + requester: { |
| 178 | + strictSSL: false, |
| 179 | + sslKeyLogFile: '/invalid/path/that/does/not/exist/ssl-keylog.txt' |
| 180 | + }, |
| 181 | + collection: { |
| 182 | + item: [{ |
| 183 | + request: global.servers.https |
| 184 | + }] |
| 185 | + } |
| 186 | + }, function (err, results) { |
| 187 | + testrun = results; |
| 188 | + done(err); |
| 189 | + }); |
| 190 | + }); |
| 191 | + |
| 192 | + after(function () { |
| 193 | + // Clean up temporary directory |
| 194 | + if (tmpDir) { |
| 195 | + tmpDir.removeCallback(); |
| 196 | + } |
| 197 | + }); |
| 198 | + |
| 199 | + it('should complete the run despite invalid path', function () { |
| 200 | + expect(testrun).to.be.ok; |
| 201 | + expect(testrun).to.nested.include({ |
| 202 | + 'done.calledOnce': true, |
| 203 | + 'start.calledOnce': true, |
| 204 | + 'request.calledOnce': true |
| 205 | + }); |
| 206 | + }); |
| 207 | + it('should not have any SSL key log data in the file', function () { |
| 208 | + // Check that the file does not exist |
| 209 | + expect(fs.existsSync(sslKeyLogFilePath)).to.be.false; |
| 210 | + }); |
| 211 | + }); |
| 212 | + |
| 213 | + describe('with multiple HTTPS requests', function () { |
| 214 | + before(function (done) { |
| 215 | + tmpDir = tmp.dirSync({ unsafeCleanup: true }); |
| 216 | + sslKeyLogFilePath = path.join(tmpDir.name, 'ssl-keylog.txt'); |
| 217 | + |
| 218 | + this.run({ |
| 219 | + requester: { |
| 220 | + strictSSL: false, |
| 221 | + sslKeyLogFile: sslKeyLogFilePath |
| 222 | + }, |
| 223 | + collection: { |
| 224 | + item: [ |
| 225 | + { |
| 226 | + request: global.servers.https |
| 227 | + }, |
| 228 | + { |
| 229 | + request: global.servers.https |
| 230 | + } |
| 231 | + ] |
| 232 | + } |
| 233 | + }, function (err, results) { |
| 234 | + testrun = results; |
| 235 | + done(err); |
| 236 | + }); |
| 237 | + }); |
| 238 | + |
| 239 | + after(function () { |
| 240 | + // Clean up temporary directory |
| 241 | + if (tmpDir) { |
| 242 | + tmpDir.removeCallback(); |
| 243 | + } |
| 244 | + }); |
| 245 | + |
| 246 | + it('should complete the run', function () { |
| 247 | + expect(testrun).to.be.ok; |
| 248 | + expect(testrun).to.nested.include({ |
| 249 | + 'done.calledOnce': true, |
| 250 | + 'start.calledOnce': true |
| 251 | + }); |
| 252 | + expect(testrun.request.callCount).to.equal(2); |
| 253 | + }); |
| 254 | + |
| 255 | + it('should write SSL key log data from all requests to the same file', function () { |
| 256 | + // Check that the file exists |
| 257 | + expect(fs.existsSync(sslKeyLogFilePath)).to.be.true; |
| 258 | + |
| 259 | + // Read the file contents |
| 260 | + const fileContents = fs.readFileSync(sslKeyLogFilePath, 'utf8'); |
| 261 | + |
| 262 | + // Verify the file has content |
| 263 | + expect(fileContents).to.be.a('string'); |
| 264 | + expect(fileContents.length).to.be.greaterThan(0); |
| 265 | + |
| 266 | + // Should contain SSL key log entries |
| 267 | + expect(fileContents).to.match(/CLIENT_/); |
| 268 | + }); |
| 269 | + }); |
| 270 | +}); |
| 271 | + |
0 commit comments