|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const path = require("path"); |
| 4 | +const del = require("del"); |
| 5 | +const Server = require("../../lib/Server"); |
| 6 | +const { testBin, normalizeStderr } = require("../helpers/test-bin"); |
| 7 | +const port = require("../ports-map")["cli-https"]; |
| 8 | + |
| 9 | +const httpsCertificateDirectory = path.resolve( |
| 10 | + __dirname, |
| 11 | + "../fixtures/https-certificate" |
| 12 | +); |
| 13 | + |
| 14 | +const defaultCertificateDir = Server.findCacheDir(); |
| 15 | + |
| 16 | +describe('"server" CLI options', () => { |
| 17 | + beforeEach(async () => { |
| 18 | + await del([defaultCertificateDir]); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should work using "--server-type http"', async () => { |
| 22 | + const { exitCode, stderr } = await testBin([ |
| 23 | + "--port", |
| 24 | + port, |
| 25 | + "--server-type", |
| 26 | + "http", |
| 27 | + ]); |
| 28 | + |
| 29 | + expect(exitCode).toEqual(0); |
| 30 | + expect( |
| 31 | + normalizeStderr(stderr, { ipv6: true, https: false }) |
| 32 | + ).toMatchSnapshot(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should work using "--server-type https"', async () => { |
| 36 | + const { exitCode, stderr } = await testBin([ |
| 37 | + "--port", |
| 38 | + port, |
| 39 | + "--server-type", |
| 40 | + "https", |
| 41 | + ]); |
| 42 | + |
| 43 | + expect(exitCode).toEqual(0); |
| 44 | + expect( |
| 45 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 46 | + ).toMatchSnapshot(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should work using "--server-type spdy"', async () => { |
| 50 | + const { exitCode, stderr } = await testBin([ |
| 51 | + "--port", |
| 52 | + port, |
| 53 | + "--server-type", |
| 54 | + "spdy", |
| 55 | + ]); |
| 56 | + |
| 57 | + expect(exitCode).toEqual(0); |
| 58 | + expect( |
| 59 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 60 | + ).toMatchSnapshot(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path> --server-options-cacert <path>"', async () => { |
| 64 | + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); |
| 65 | + const key = path.join(httpsCertificateDirectory, "server.key"); |
| 66 | + const cert = path.join(httpsCertificateDirectory, "server.crt"); |
| 67 | + const cacert = path.join(httpsCertificateDirectory, "ca.pem"); |
| 68 | + const passphrase = "webpack-dev-server"; |
| 69 | + |
| 70 | + const { exitCode, stderr } = await testBin([ |
| 71 | + "--port", |
| 72 | + port, |
| 73 | + "--server-options-key", |
| 74 | + key, |
| 75 | + "--server-options-pfx", |
| 76 | + pfxFile, |
| 77 | + "--server-options-passphrase", |
| 78 | + passphrase, |
| 79 | + "--server-options-cert", |
| 80 | + cert, |
| 81 | + "--server-options-cacert", |
| 82 | + cacert, |
| 83 | + ]); |
| 84 | + |
| 85 | + expect(exitCode).toEqual(0); |
| 86 | + expect( |
| 87 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 88 | + ).toMatchSnapshot(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path> --server-options-ca <path>"', async () => { |
| 92 | + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); |
| 93 | + const key = path.join(httpsCertificateDirectory, "server.key"); |
| 94 | + const cert = path.join(httpsCertificateDirectory, "server.crt"); |
| 95 | + const ca = path.join(httpsCertificateDirectory, "ca.pem"); |
| 96 | + const passphrase = "webpack-dev-server"; |
| 97 | + |
| 98 | + const { exitCode, stderr } = await testBin([ |
| 99 | + "--port", |
| 100 | + port, |
| 101 | + "--server-options-key", |
| 102 | + key, |
| 103 | + "--server-options-pfx", |
| 104 | + pfxFile, |
| 105 | + "--server-options-passphrase", |
| 106 | + passphrase, |
| 107 | + "--server-options-cert", |
| 108 | + cert, |
| 109 | + "--server-options-ca", |
| 110 | + ca, |
| 111 | + ]); |
| 112 | + |
| 113 | + expect(exitCode).toEqual(0); |
| 114 | + expect( |
| 115 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 116 | + ).toMatchSnapshot(); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should work using "--server-options-key-reset --server-options-key <path> --server-options-pfx-reset --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert-reset --server-options-cert <path> --server-options-ca-reset --server-options-ca <path>"', async () => { |
| 120 | + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); |
| 121 | + const key = path.join(httpsCertificateDirectory, "server.key"); |
| 122 | + const cert = path.join(httpsCertificateDirectory, "server.crt"); |
| 123 | + const ca = path.join(httpsCertificateDirectory, "ca.pem"); |
| 124 | + const passphrase = "webpack-dev-server"; |
| 125 | + |
| 126 | + const { exitCode, stderr } = await testBin([ |
| 127 | + "--port", |
| 128 | + port, |
| 129 | + "--server-options-key-reset", |
| 130 | + "--server-options-key", |
| 131 | + key, |
| 132 | + "--server-options-pfx-reset", |
| 133 | + "--server-options-pfx", |
| 134 | + pfxFile, |
| 135 | + "--server-options-passphrase", |
| 136 | + passphrase, |
| 137 | + "--server-options-cert-reset", |
| 138 | + "--server-options-cert", |
| 139 | + cert, |
| 140 | + "--server-options-ca-reset", |
| 141 | + "--server-options-ca", |
| 142 | + ca, |
| 143 | + ]); |
| 144 | + |
| 145 | + expect(exitCode).toEqual(0); |
| 146 | + expect( |
| 147 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 148 | + ).toMatchSnapshot(); |
| 149 | + }); |
| 150 | + |
| 151 | + it('should warn using "--server-options-cacert" and "--server-options-ca" together', async () => { |
| 152 | + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); |
| 153 | + const key = path.join(httpsCertificateDirectory, "server.key"); |
| 154 | + const cert = path.join(httpsCertificateDirectory, "server.crt"); |
| 155 | + const cacert = path.join(httpsCertificateDirectory, "ca.pem"); |
| 156 | + const passphrase = "webpack-dev-server"; |
| 157 | + |
| 158 | + const { exitCode, stderr } = await testBin([ |
| 159 | + "--port", |
| 160 | + port, |
| 161 | + "--server-options-key", |
| 162 | + key, |
| 163 | + "--server-options-pfx", |
| 164 | + pfxFile, |
| 165 | + "--server-options-passphrase", |
| 166 | + passphrase, |
| 167 | + "--server-options-cert", |
| 168 | + cert, |
| 169 | + "--server-options-cacert", |
| 170 | + cacert, |
| 171 | + "--server-options-ca", |
| 172 | + cacert, |
| 173 | + ]); |
| 174 | + |
| 175 | + expect(exitCode).toEqual(0); |
| 176 | + expect( |
| 177 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 178 | + ).toMatchSnapshot(); |
| 179 | + }); |
| 180 | + |
| 181 | + // For https://github.com/webpack/webpack-dev-server/issues/3306 |
| 182 | + it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>"', async () => { |
| 183 | + const pfxFile = path.join(httpsCertificateDirectory, "server.pfx"); |
| 184 | + const key = path.join(httpsCertificateDirectory, "server.key"); |
| 185 | + const cert = path.join(httpsCertificateDirectory, "server.crt"); |
| 186 | + const passphrase = "webpack-dev-server"; |
| 187 | + |
| 188 | + const { exitCode, stderr } = await testBin([ |
| 189 | + "--port", |
| 190 | + port, |
| 191 | + "--server-options-key", |
| 192 | + key, |
| 193 | + "--server-options-pfx", |
| 194 | + pfxFile, |
| 195 | + "--server-options-passphrase", |
| 196 | + passphrase, |
| 197 | + "--server-options-cert", |
| 198 | + cert, |
| 199 | + ]); |
| 200 | + |
| 201 | + expect(exitCode).toEqual(0); |
| 202 | + expect( |
| 203 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 204 | + ).toMatchSnapshot(); |
| 205 | + }); |
| 206 | + |
| 207 | + it('should work using "--server-options-request-cert"', async () => { |
| 208 | + const { exitCode, stderr } = await testBin([ |
| 209 | + "--port", |
| 210 | + port, |
| 211 | + "--server-options-request-cert", |
| 212 | + ]); |
| 213 | + |
| 214 | + expect(exitCode).toEqual(0); |
| 215 | + expect( |
| 216 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 217 | + ).toMatchSnapshot(); |
| 218 | + }); |
| 219 | + |
| 220 | + it('should work using "--no-server-options-request-cert"', async () => { |
| 221 | + const { exitCode, stderr } = await testBin([ |
| 222 | + "--port", |
| 223 | + port, |
| 224 | + "--no-server-options-request-cert", |
| 225 | + ]); |
| 226 | + |
| 227 | + expect(exitCode).toEqual(0); |
| 228 | + expect( |
| 229 | + normalizeStderr(stderr, { ipv6: true, https: true }) |
| 230 | + ).toMatchSnapshot(); |
| 231 | + }); |
| 232 | +}); |
0 commit comments