From 67067c97d5ef91fae88ed086541fe68c46f8bc64 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 21 Jan 2021 09:27:27 +0100 Subject: [PATCH] chore: connection encryption example test (#843) --- .github/workflows/main.yml | 7 +++++ .../1.js | 2 +- .../README.md | 2 +- examples/connection-encryption/test.js | 30 +++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) rename examples/{encrypted-communications => connection-encryption}/1.js (96%) rename examples/{encrypted-communications => connection-encryption}/README.md (98%) create mode 100644 examples/connection-encryption/test.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5faac18f..73231510 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,6 +72,13 @@ jobs: - uses: actions/checkout@v2 - run: yarn - run: cd examples && yarn && npm run test -- chat + test-connection-encryption-example: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: cd examples && yarn && npm run test -- connection-encryption test-echo-example: needs: check runs-on: ubuntu-latest diff --git a/examples/encrypted-communications/1.js b/examples/connection-encryption/1.js similarity index 96% rename from examples/encrypted-communications/1.js rename to examples/connection-encryption/1.js index d17498af..1d3f0bcb 100644 --- a/examples/encrypted-communications/1.js +++ b/examples/connection-encryption/1.js @@ -1,6 +1,6 @@ 'use strict' -const Libp2p = require('../../') +const Libp2p = require('../..') const TCP = require('libp2p-tcp') const Mplex = require('libp2p-mplex') const { NOISE } = require('libp2p-noise') diff --git a/examples/encrypted-communications/README.md b/examples/connection-encryption/README.md similarity index 98% rename from examples/encrypted-communications/README.md rename to examples/connection-encryption/README.md index 3e23ea6d..2d1c0614 100644 --- a/examples/encrypted-communications/README.md +++ b/examples/connection-encryption/README.md @@ -1,4 +1,4 @@ -# Encrypted Communications +# Connection Encryption libp2p can leverage the encrypted communications from the transports it uses (i.e WebRTC). To ensure that every connection is encrypted, independently of how it was set up, libp2p also supports a set of modules that encrypt every communication established. diff --git a/examples/connection-encryption/test.js b/examples/connection-encryption/test.js new file mode 100644 index 00000000..9be0ab21 --- /dev/null +++ b/examples/connection-encryption/test.js @@ -0,0 +1,30 @@ +'use strict' + +const path = require('path') +const execa = require('execa') +const pDefer = require('p-defer') +const uint8ArrayToString = require('uint8arrays/to-string') + +async function test () { + const messageReceived = pDefer() + process.stdout.write('1.js\n') + + const proc = execa('node', [path.join(__dirname, '1.js')], { + cwd: path.resolve(__dirname), + all: true + }) + + proc.all.on('data', async (data) => { + process.stdout.write(data) + + const s = uint8ArrayToString(data) + if (s.includes('This information is sent out encrypted to the other peer')) { + messageReceived.resolve() + } + }) + + await messageReceived.promise + proc.kill() +} + +module.exports = test