|
| 1 | +import HttpURLConnectionClient from "../httpClient/httpURLConnectionClient"; |
| 2 | + |
| 3 | +describe("HttpURLConnectionClient", () => { |
| 4 | + let client: HttpURLConnectionClient; |
| 5 | + |
| 6 | + beforeEach(() => { |
| 7 | + client = new HttpURLConnectionClient(); |
| 8 | + }); |
| 9 | + |
| 10 | + describe("verifyLocation", () => { |
| 11 | + test.each([ |
| 12 | + "https://example.adyen.com/path", |
| 13 | + "https://sub.adyen.com", |
| 14 | + "http://another.adyen.com/a/b/c?q=1", |
| 15 | + "https://checkout-test.adyen.com", |
| 16 | + ])("should return true for valid adyen.com domain: %s", (location) => { |
| 17 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 18 | + // @ts-ignore - testing a private method |
| 19 | + expect(client.verifyLocation(location)).toBe(true); |
| 20 | + }); |
| 21 | + |
| 22 | + test.each([ |
| 23 | + "https://example.ADYEN.com/path", |
| 24 | + "HTTPS://sub.adyen.COM", |
| 25 | + ])("should be case-insensitive for valid adyen.com domain: %s", (location) => { |
| 26 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 27 | + // @ts-ignore - testing a private method |
| 28 | + expect(client.verifyLocation(location)).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + test.each([ |
| 32 | + "https://adyen.com.evil.com/path", |
| 33 | + "https://evil-adyen.com", |
| 34 | + "http://adyen.co", |
| 35 | + "https://www.google.com", |
| 36 | + "https://adyen.com-scam.com", |
| 37 | + ])("should return false for invalid domain: %s", (location) => { |
| 38 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 39 | + // @ts-ignore - testing a private method |
| 40 | + expect(client.verifyLocation(location)).toBe(false); |
| 41 | + }); |
| 42 | + |
| 43 | + test.each([ |
| 44 | + "https://adyen.com.another.domain/path", |
| 45 | + "https://myadyen.com.org", |
| 46 | + ])("should return false for domains that contain but do not end with adyen.com: %s", (location) => { |
| 47 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 48 | + // @ts-ignore - testing a private method |
| 49 | + expect(client.verifyLocation(location)).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + test.each([ |
| 53 | + "not a url", |
| 54 | + "adyen.com", |
| 55 | + "//adyen.com/path", |
| 56 | + ])("should return false for malformed URLs: %s", (location) => { |
| 57 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 58 | + // @ts-ignore - testing a private method |
| 59 | + expect(client.verifyLocation(location)).toBe(false); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments