|
1 | | -import { isExternalAppUrl } from "./isExternalAppUrl"; |
| 1 | +import { isSaleorOfficialAppUrl } from "./isSaleorOfficialAppUrl"; |
2 | 2 |
|
3 | 3 | const setCloudDomain = (value: string | undefined): void => { |
4 | 4 | window.__SALEOR_CONFIG__ = { ...window.__SALEOR_CONFIG__, SALEOR_CLOUD_APP_DOMAIN: value }; |
5 | 5 | }; |
6 | 6 |
|
7 | | -describe("isExternalAppUrl", () => { |
| 7 | +describe("isSaleorOfficialAppUrl", () => { |
8 | 8 | const originalConfig = window.__SALEOR_CONFIG__; |
9 | 9 |
|
10 | 10 | afterEach(() => { |
11 | 11 | window.__SALEOR_CONFIG__ = originalConfig; |
12 | 12 | }); |
13 | 13 |
|
14 | | - it("returns true when cloud domain env var is not set", () => { |
| 14 | + it("returns false when cloud domain env var is not set", () => { |
15 | 15 | // Arrange |
16 | 16 | setCloudDomain(undefined); |
17 | 17 |
|
18 | 18 | // Act |
19 | | - const result = isExternalAppUrl("https://anything.example.com/widget"); |
| 19 | + const result = isSaleorOfficialAppUrl("https://app.saleor.app/widget"); |
20 | 20 |
|
21 | 21 | // Assert |
22 | | - expect(result).toBe(true); |
| 22 | + expect(result).toBe(false); |
23 | 23 | }); |
24 | 24 |
|
25 | | - it("returns true when cloud domain env var is empty string", () => { |
| 25 | + it("returns false when cloud domain env var is empty string", () => { |
26 | 26 | // Arrange |
27 | 27 | setCloudDomain(""); |
28 | 28 |
|
29 | 29 | // Act |
30 | | - const result = isExternalAppUrl("https://app.saleor.app/widget"); |
| 30 | + const result = isSaleorOfficialAppUrl("https://app.saleor.app/widget"); |
31 | 31 |
|
32 | 32 | // Assert |
33 | | - expect(result).toBe(true); |
| 33 | + expect(result).toBe(false); |
34 | 34 | }); |
35 | 35 |
|
36 | | - it("returns false for URL hosted exactly on the cloud domain", () => { |
| 36 | + it("returns true for URL hosted exactly on the cloud domain", () => { |
37 | 37 | // Arrange |
38 | 38 | setCloudDomain("saleor.app"); |
39 | 39 |
|
40 | 40 | // Act |
41 | | - const result = isExternalAppUrl("https://saleor.app/widget"); |
| 41 | + const result = isSaleorOfficialAppUrl("https://saleor.app/widget"); |
42 | 42 |
|
43 | 43 | // Assert |
44 | | - expect(result).toBe(false); |
| 44 | + expect(result).toBe(true); |
45 | 45 | }); |
46 | 46 |
|
47 | | - it("returns false for URL hosted on a subdomain of the cloud domain", () => { |
| 47 | + it("returns true for URL hosted on a subdomain of the cloud domain", () => { |
48 | 48 | // Arrange |
49 | 49 | setCloudDomain("saleor.app"); |
50 | 50 |
|
51 | 51 | // Act |
52 | | - const result = isExternalAppUrl("https://my-app.saleor.app/widget"); |
| 52 | + const result = isSaleorOfficialAppUrl("https://my-app.saleor.app/widget"); |
53 | 53 |
|
54 | 54 | // Assert |
55 | | - expect(result).toBe(false); |
| 55 | + expect(result).toBe(true); |
56 | 56 | }); |
57 | 57 |
|
58 | | - it("returns true for URL hosted outside the cloud domain", () => { |
| 58 | + it("returns false for URL hosted outside the cloud domain", () => { |
59 | 59 | // Arrange |
60 | 60 | setCloudDomain("saleor.app"); |
61 | 61 |
|
62 | 62 | // Act |
63 | | - const result = isExternalAppUrl("https://example.com/widget"); |
| 63 | + const result = isSaleorOfficialAppUrl("https://example.com/widget"); |
64 | 64 |
|
65 | 65 | // Assert |
66 | | - expect(result).toBe(true); |
| 66 | + expect(result).toBe(false); |
67 | 67 | }); |
68 | 68 |
|
69 | 69 | it("does not match a domain that merely ends with the cloud domain string", () => { |
70 | 70 | // Arrange |
71 | 71 | setCloudDomain("saleor.app"); |
72 | 72 |
|
73 | 73 | // Act - "evilsaleor.app" must not be treated as a subdomain of "saleor.app" |
74 | | - const result = isExternalAppUrl("https://evilsaleor.app/widget"); |
| 74 | + const result = isSaleorOfficialAppUrl("https://evilsaleor.app/widget"); |
75 | 75 |
|
76 | 76 | // Assert |
77 | | - expect(result).toBe(true); |
| 77 | + expect(result).toBe(false); |
78 | 78 | }); |
79 | 79 |
|
80 | | - it("returns true when URL cannot be parsed", () => { |
| 80 | + it("returns false when URL cannot be parsed", () => { |
81 | 81 | // Arrange |
82 | 82 | setCloudDomain("saleor.app"); |
83 | 83 |
|
84 | 84 | // Act |
85 | | - const result = isExternalAppUrl("not-a-url"); |
| 85 | + const result = isSaleorOfficialAppUrl("not-a-url"); |
86 | 86 |
|
87 | 87 | // Assert |
88 | | - expect(result).toBe(true); |
| 88 | + expect(result).toBe(false); |
89 | 89 | }); |
90 | 90 | }); |
0 commit comments