-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #911 from serlo/staging
Deployment
- Loading branch information
Showing
31 changed files
with
243 additions
and
112 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+820 KB
...lugin-npm-8.9.0-0e592890ad-d72bda52eb.zip → ...ugin-npm-8.12.0-84fc5ba2a7-c5016fca4d.zip
Binary file not shown.
Binary file renamed
BIN
+333 KB
...nager-npm-8.9.0-29ba0d0ae3-56b71993f3.zip → ...ager-npm-8.12.0-f9e588e4a2-5ea2589cac.zip
Binary file not shown.
Binary file added
BIN
+59.4 KB
.yarn/cache/@typescript-eslint-type-utils-npm-8.12.0-d58b784293-62ef69626c.zip
Binary file not shown.
Binary file removed
BIN
-59.4 KB
.yarn/cache/@typescript-eslint-type-utils-npm-8.9.0-402bffd40e-e4422ad2da.zip
Binary file not shown.
Binary file added
BIN
+33.7 KB
.yarn/cache/@typescript-eslint-types-npm-8.12.0-e8ae59575b-f3892161c9.zip
Binary file not shown.
Binary file removed
BIN
-33.5 KB
.yarn/cache/@typescript-eslint-types-npm-8.9.0-4a8793dbf3-bb79e8774b.zip
Binary file not shown.
Binary file added
BIN
+185 KB
.yarn/cache/@typescript-eslint-typescript-estree-npm-8.12.0-ec4a45b8a7-1c968ec73a.zip
Binary file not shown.
Binary file removed
BIN
-185 KB
.yarn/cache/@typescript-eslint-typescript-estree-npm-8.9.0-95b59ee531-307b317c2a.zip
Binary file not shown.
Binary file renamed
BIN
+115 KB
...utils-npm-8.9.0-57aeac8c66-23bb2a054f.zip → ...tils-npm-8.12.0-e7f6bcc10a-d45c89cfc7.zip
Binary file not shown.
Binary file renamed
BIN
+9.75 KB
...-keys-npm-8.9.0-490798ec54-9afb7eabfc.zip → ...keys-npm-8.12.0-20aa4e1884-7897a66ba0.zip
Binary file not shown.
Binary file renamed
BIN
+76.5 KB
...pers-npm-1.0.19-5a0b930ca7-7ae112b883.zip → ...lpers-npm-1.1.0-47deee3fe3-4ba3a32ab7.zip
Binary file not shown.
Binary file renamed
BIN
+341 KB
...eact-npm-7.37.1-c62b7e0250-22d1bdf0dd.zip → ...eact-npm-7.37.2-9fdf577e3b-7f5203afee.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+218 KB
.../jose-npm-5.9.4-eb1e38a597-d1c3dd0fb6.zip → .../jose-npm-5.9.6-8196c83d4f-4b536da020.zip
Binary file not shown.
Binary file renamed
BIN
+4.91 KB
...ejson-npm-2.5.2-702a288958-f280d69327.zip → ...ejson-npm-2.5.3-c48ac4cc48-0b3063cb3d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { http } from 'msw' | ||
|
||
import { | ||
currentTestEnvironment, | ||
expectIsPlaceholderResponse, | ||
} from './__utils__' | ||
|
||
beforeEach(() => { | ||
globalThis.server.use( | ||
http.get('https://whatever.org/image', () => { | ||
return new Response('', { | ||
headers: { | ||
'content-type': 'image/png', | ||
'Set-Cookie': | ||
'sessionId=abc123; Expires=Wed, 09 Nov 2024 07:28:00 GMT; Path=/; Domain=whatever.org; Secure; HttpOnly; SameSite=None', | ||
}, | ||
}) | ||
}), | ||
http.get('https://whatever.org/notimage', () => { | ||
return new Response('', { | ||
headers: { 'content-type': 'application/json' }, | ||
}) | ||
}), | ||
) | ||
}) | ||
|
||
test('request to https://asset-proxy.serlo.org/image?url=* gets asset from url query parameter', async () => { | ||
const env = currentTestEnvironment() | ||
const response = await env.fetch({ | ||
subdomain: 'asset-proxy', | ||
pathname: '/image?url=https://whatever.org/image', | ||
}) | ||
expect(response.status).toBe(200) | ||
expect(response.headers.get('content-type')).toBe('image/png') | ||
expect(response.headers.get('Set-Cookie')).toBeNull() | ||
expect(response.headers.get('cache-control')).toBe( | ||
'public, max-age=31536000, immutable', | ||
) | ||
}) | ||
|
||
describe('returns placeholder', () => { | ||
test('when url parameter is empty', async () => { | ||
const response = await requestAsset('') | ||
|
||
expectIsPlaceholderResponse(response) | ||
}) | ||
|
||
test('when url is invalid', async () => { | ||
const response = await requestAsset('42') | ||
|
||
expectIsPlaceholderResponse(response) | ||
}) | ||
|
||
test('when url query parameter is missing', async () => { | ||
const response = await currentTestEnvironment().fetch({ | ||
subdomain: 'asset-proxy', | ||
pathname: '/image', | ||
}) | ||
|
||
expectIsPlaceholderResponse(response) | ||
}) | ||
|
||
test('when response is not image', async () => { | ||
const response = await requestAsset('https://whatever.org/notimage') | ||
|
||
expectIsPlaceholderResponse(response) | ||
}) | ||
}) | ||
|
||
async function requestAsset( | ||
url: string, | ||
env = currentTestEnvironment(), | ||
): Promise<Response> { | ||
return await env.fetch({ | ||
subdomain: 'asset-proxy', | ||
pathname: '/image?url=' + encodeURIComponent(url), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Url, getPlaceholder, isImageResponse } from './utils' | ||
|
||
export async function assetProxy(request: Request): Promise<Response | null> { | ||
const url = Url.fromRequest(request) | ||
|
||
if (url.subdomain !== 'asset-proxy') return null | ||
if (url.pathname !== '/image') return null | ||
|
||
const urlParam = url.searchParams.get('url') | ||
|
||
if (!urlParam) return getPlaceholder() | ||
|
||
let assetUrl: Url | ||
|
||
try { | ||
assetUrl = new Url(urlParam) | ||
} catch { | ||
return getPlaceholder() | ||
} | ||
|
||
const originalResponse = await fetch(assetUrl, { | ||
cf: { cacheTtl: 24 * 60 * 60 * 30 }, | ||
}) | ||
|
||
if (originalResponse.ok && isImageResponse(originalResponse)) { | ||
const response = new Response(originalResponse.body, originalResponse) | ||
response.headers.delete('set-cookie') | ||
response.headers.set('cache-control', 'public, max-age=31536000, immutable') | ||
return response | ||
} | ||
|
||
return getPlaceholder() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function getPlaceholder() { | ||
const placeholderBase64 = | ||
'iVBORw0KGgoAAAANSUhEUgAAAwAAAAGwAQMAAAAkGpCRAAAAA1BMVEXv9/t0VvapAAAAP0lEQVR42u3BMQEAAADCIPuntsUuYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQOqOwAAHrgHqAAAAAAElFTkSuQmCC' | ||
const placeholder = Uint8Array.from(atob(placeholderBase64), (c) => | ||
c.charCodeAt(0), | ||
) | ||
return new Response(placeholder, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: { | ||
'Content-Type': 'image/png', | ||
'Content-Length': placeholder.length.toString(), | ||
}, | ||
}) | ||
} | ||
|
||
export function isImageResponse(res: Response): boolean { | ||
const contentType = res.headers.get('content-type') ?? '' | ||
return res.status === 200 && contentType.startsWith('image/') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.