forked from libp2p/test-plans
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add [email protected] to transport-interop #8
Open
github-actions
wants to merge
5
commits into
master
Choose a base branch
from
add/transport-interop/js-libp2p
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d75e35
chore: add [email protected] to transport-interop
AlejandroCabeza c5f7b87
chore: add [email protected] to transport-interop
AlejandroCabeza 0168dc5
chore: add [email protected] to transport-interop
AlejandroCabeza 07ad8a8
chore: add [email protected] to transport-interop
AlejandroCabeza 23bf381
chore: add [email protected] to transport-interop
AlejandroCabeza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,117 @@ | ||
/* eslint-disable no-console */ | ||
import http from 'http' | ||
import { pEvent } from 'p-event' | ||
import { createClient } from 'redis' | ||
|
||
const redisAddr = process.env.redis_addr || 'redis:6379' | ||
const transport = process.env.transport | ||
const isDialer = process.env.is_dialer === 'true' | ||
|
||
/** @type {import('aegir/types').PartialOptions} */ | ||
export default { | ||
test: { | ||
browser: { | ||
config: { | ||
// Ignore self signed certificates | ||
browserContextOptions: { ignoreHTTPSErrors: true } | ||
} | ||
}, | ||
async before () { | ||
// import after build is complete | ||
const { createRelay } = await import('./dist/test/fixtures/relay.js') | ||
|
||
let relayNode | ||
let relayAddr | ||
if (transport === 'webrtc' && !isDialer) { | ||
relayNode = await createRelay() | ||
|
||
const sortByNonLocalIp = (a, b) => { | ||
if (a.toString().includes('127.0.0.1')) { | ||
return 1 | ||
} | ||
return -1 | ||
} | ||
|
||
relayAddr = relayNode.getMultiaddrs().sort(sortByNonLocalIp)[0].toString() | ||
} | ||
|
||
const redisClient = createClient({ | ||
url: `redis://${redisAddr}` | ||
}) | ||
redisClient.on('error', (err) => { | ||
console.error('Redis client error:', err) | ||
}) | ||
await redisClient.connect() | ||
|
||
const requestListener = async function (req, res) { | ||
const requestJSON = await new Promise(resolve => { | ||
let body = '' | ||
req.on('data', function (data) { | ||
body += data | ||
}) | ||
|
||
req.on('end', function () { | ||
resolve(JSON.parse(body)) | ||
}) | ||
}) | ||
|
||
try { | ||
const redisRes = await redisClient.sendCommand(requestJSON) | ||
|
||
if (redisRes == null) { | ||
console.error('Redis failure - sent', requestJSON, 'received', redisRes) | ||
|
||
res.writeHead(500, { | ||
'Access-Control-Allow-Origin': '*' | ||
}) | ||
res.end(JSON.stringify({ | ||
message: 'Redis sent back null' | ||
})) | ||
|
||
return | ||
} | ||
|
||
res.writeHead(200, { | ||
'Access-Control-Allow-Origin': '*' | ||
}) | ||
res.end(JSON.stringify(redisRes)) | ||
} catch (err) { | ||
console.error('Error in redis command:', err) | ||
res.writeHead(500, { | ||
'Access-Control-Allow-Origin': '*' | ||
}) | ||
res.end(err.toString()) | ||
} | ||
} | ||
|
||
const proxyServer = http.createServer(requestListener) | ||
proxyServer.listen(0) | ||
|
||
await pEvent(proxyServer, 'listening', { | ||
signal: AbortSignal.timeout(5000) | ||
}) | ||
|
||
return { | ||
redisClient, | ||
relayNode, | ||
proxyServer, | ||
env: { | ||
...process.env, | ||
RELAY_ADDR: relayAddr, | ||
REDIS_PROXY_PORT: proxyServer.address().port | ||
} | ||
} | ||
}, | ||
async after (_, { proxyServer, redisClient, relayNode }) { | ||
await new Promise(resolve => { | ||
proxyServer?.close(() => resolve()) | ||
}) | ||
|
||
try { | ||
// We don't care if this fails | ||
await redisClient?.disconnect() | ||
await relayNode?.stop() | ||
} catch { } | ||
} | ||
} | ||
} |
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,24 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Copied since we won't have the repo to use if expanding from cache. | ||
|
||
# Workaround: https://github.com/docker/cli/issues/996 | ||
ARG BASE_IMAGE=node-js-libp2p-head | ||
FROM ${BASE_IMAGE} as js-libp2p-base | ||
|
||
FROM mcr.microsoft.com/playwright | ||
|
||
COPY --from=js-libp2p-base /app/ /app/ | ||
WORKDIR /app | ||
|
||
# We install browsers here instead of the cached version so that we use the latest browsers at run time. | ||
# Ideally this would also be pinned, but playwright controls this, so there isn't much we can do about it. | ||
# By installing here, we avoid installing it at test time. | ||
RUN npx playwright install-deps | ||
RUN npx playwright install | ||
|
||
# Options: chromium, firefox, webkit | ||
ARG BROWSER=chromium | ||
ENV BROWSER=${BROWSER} | ||
|
||
ENTRYPOINT npm test -- -t browser -- --browser $BROWSER |
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,17 @@ | ||
# Here because we want to fetch the node_modules within docker so that it's | ||
# installed on the same platform the test is run. Otherwise tools like `esbuild` will fail to run | ||
FROM node:lts | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json .aegir.js tsconfig.json ./ | ||
COPY src ./src | ||
COPY test ./test | ||
|
||
# disable colored output and CLI animation from test runners | ||
ENV CI true | ||
|
||
RUN npm ci | ||
RUN npm run build | ||
|
||
ENTRYPOINT npm test -- -t node |
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,35 @@ | ||
image_name := js-v1.x | ||
|
||
# TODO Enable webkit once https://github.com/libp2p/js-libp2p/pull/1627 is in | ||
all: image.json chromium-image.json firefox-image.json update-lock-file | ||
|
||
# Necessary because multistage builds require a docker image name rather than a digest to be used | ||
load-image-json: image.json | ||
docker image tag $$(jq -r .imageID image.json) ${image_name} | ||
|
||
chromium-image.json: load-image-json BrowserDockerfile | ||
docker build -f BrowserDockerfile --build-arg=BASE_IMAGE=${image_name} --build-arg=BROWSER=chromium -t chromium-${image_name} . | ||
docker image inspect chromium-${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
firefox-image.json: load-image-json BrowserDockerfile | ||
docker build -f BrowserDockerfile --build-arg=BASE_IMAGE=${image_name} --build-arg=BROWSER=firefox -t firefox-${image_name} . | ||
docker image inspect firefox-${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
# We update the lock file here so that we make sure we are always using the correct lock file. | ||
# If this changes, CI will fail since there are unstaged changes. | ||
update-lock-file: image.json | ||
CONTAINER_ID=$$(docker create $$(jq -r .imageID image.json)); \ | ||
docker cp $$CONTAINER_ID:/app/package-lock.json ./package-lock.json; \ | ||
docker rm $$CONTAINER_ID | ||
|
||
image.json: | ||
docker build -t ${image_name} -f ./Dockerfile . | ||
docker image inspect ${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
clean: | ||
rm -rf image.json *-image.json | ||
|
||
.PHONY: all clean browser-images load-image-json |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Copilot Autofix AI about 1 month ago
To fix the problem, we need to ensure that any error messages sent back in the HTTP response are properly sanitized to prevent XSS attacks. The best way to achieve this is by using a library that provides HTML escaping functionality. One such library is
he
, which can encode HTML entities to prevent XSS.he
library to handle HTML escaping.he
library in the file.he.encode
function to escape the error message before sending it in the HTTP response.