|
| 1 | +import { expect } from "chai"; |
| 2 | +import { parseWindowsProxySetting } from "./proxy"; |
| 3 | +describe("proxy", () => { |
| 4 | + describe("parseWindowsProxySetting", () => { |
| 5 | + it("should return null if null or undefined", () => { |
| 6 | + expect(parseWindowsProxySetting(null)).to.be.null; |
| 7 | + expect(parseWindowsProxySetting(undefined)).to.be.null; |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return same url for http and https if just a url is provided", () => { |
| 11 | + const value = parseWindowsProxySetting("http://localhost:8888"); |
| 12 | + expect(value).not.to.be.null; |
| 13 | + expect(value.http.host).to.eql("localhost"); |
| 14 | + expect(value.http.port).to.eql("8888"); |
| 15 | + expect(value.https.host).to.eql("localhost"); |
| 16 | + expect(value.https.port).to.eql("8888"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should coresponding http and https urls", () => { |
| 20 | + const value = parseWindowsProxySetting("http=http://localhost:8888;https=http://localhost:9999"); |
| 21 | + expect(value).not.to.be.null; |
| 22 | + expect(value.http.host).to.eql("localhost"); |
| 23 | + expect(value.http.port).to.eql("8888"); |
| 24 | + expect(value.https.host).to.eql("localhost"); |
| 25 | + expect(value.https.port).to.eql("9999"); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should assign https automatically if missing but http provided", () => { |
| 29 | + const value = parseWindowsProxySetting("http=http://localhost:8888"); |
| 30 | + expect(value).not.to.be.null; |
| 31 | + expect(value.http.host).to.eql("localhost"); |
| 32 | + expect(value.http.port).to.eql("8888"); |
| 33 | + expect(value.https.host).to.eql("localhost"); |
| 34 | + expect(value.https.port).to.eql("8888"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should assign http automatically if missing but https provided", () => { |
| 38 | + const value = parseWindowsProxySetting("https=http://localhost:8888"); |
| 39 | + expect(value).not.to.be.null; |
| 40 | + expect(value.http.host).to.eql("localhost"); |
| 41 | + expect(value.http.port).to.eql("8888"); |
| 42 | + expect(value.https.host).to.eql("localhost"); |
| 43 | + expect(value.https.port).to.eql("8888"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should return null if invalid url is provided", () => { |
| 47 | + expect(parseWindowsProxySetting("invalid-url")).to.be.null; |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments