|
8 | 8 | getVersionFromFileContent, |
9 | 9 | isVersionSatisfies, |
10 | 10 | isCacheFeatureAvailable, |
11 | | - isGhes |
| 11 | + isGhes, |
| 12 | + validatePaginationUrl |
12 | 13 | } from '../src/util'; |
13 | 14 |
|
14 | 15 | jest.mock('@actions/cache'); |
@@ -100,13 +101,54 @@ describe('getNextPageUrlFromLinkHeader', () => { |
100 | 101 | }, |
101 | 102 | 'https://example.com/next?page=2' |
102 | 103 | ], |
| 104 | + [ |
| 105 | + { |
| 106 | + link: '<https://api.adoptium.net/v3/versions?page=3>; type="application/json"; rel="next"' |
| 107 | + }, |
| 108 | + 'https://api.adoptium.net/v3/versions?page=3' |
| 109 | + ], |
103 | 110 | [{link: '<https://example.com/last?page=5>; rel="last"'}, null], |
104 | 111 | [undefined, null] |
105 | 112 | ])('returns %s -> %s', (headers, expected) => { |
106 | 113 | expect(getNextPageUrlFromLinkHeader(headers)).toBe(expected); |
107 | 114 | }); |
108 | 115 | }); |
109 | 116 |
|
| 117 | +describe('validatePaginationUrl', () => { |
| 118 | + it('accepts URL with matching origin', () => { |
| 119 | + expect( |
| 120 | + validatePaginationUrl( |
| 121 | + 'https://api.adoptium.net/v3/assets?page=2', |
| 122 | + 'https://api.adoptium.net' |
| 123 | + ) |
| 124 | + ).toBe(true); |
| 125 | + }); |
| 126 | + |
| 127 | + it('rejects URL with different host', () => { |
| 128 | + expect( |
| 129 | + validatePaginationUrl( |
| 130 | + 'https://evil.example.com/steal?data=1', |
| 131 | + 'https://api.adoptium.net' |
| 132 | + ) |
| 133 | + ).toBe(false); |
| 134 | + }); |
| 135 | + |
| 136 | + it('rejects URL with different protocol', () => { |
| 137 | + expect( |
| 138 | + validatePaginationUrl( |
| 139 | + 'http://api.adoptium.net/v3/assets?page=2', |
| 140 | + 'https://api.adoptium.net' |
| 141 | + ) |
| 142 | + ).toBe(false); |
| 143 | + }); |
| 144 | + |
| 145 | + it('returns false for invalid URL', () => { |
| 146 | + expect( |
| 147 | + validatePaginationUrl('not-a-url', 'https://api.adoptium.net') |
| 148 | + ).toBe(false); |
| 149 | + }); |
| 150 | +}); |
| 151 | + |
110 | 152 | describe('getVersionFromFileContent', () => { |
111 | 153 | describe('.sdkmanrc', () => { |
112 | 154 | it.each([ |
|
0 commit comments