From df1db951c512a58110171d046ef367789df02733 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Nov 2021 11:36:03 +0100 Subject: Support RTMPS --- server/tests/api/live/index.ts | 1 + server/tests/api/live/live-rtmps.ts | 146 ++++++++++++++++++++++++++++++++++++ server/tests/fixtures/rtmps.cert | 21 ++++++ server/tests/fixtures/rtmps.key | 28 +++++++ 4 files changed, 196 insertions(+) create mode 100644 server/tests/api/live/live-rtmps.ts create mode 100644 server/tests/fixtures/rtmps.cert create mode 100644 server/tests/fixtures/rtmps.key (limited to 'server/tests') diff --git a/server/tests/api/live/index.ts b/server/tests/api/live/index.ts index e6bcef49f..105416b8d 100644 --- a/server/tests/api/live/index.ts +++ b/server/tests/api/live/index.ts @@ -1,6 +1,7 @@ import './live-constraints' import './live-socket-messages' import './live-permanent' +import './live-rtmps' import './live-save-replay' import './live-views' import './live' diff --git a/server/tests/api/live/live-rtmps.ts b/server/tests/api/live/live-rtmps.ts new file mode 100644 index 000000000..378e6df3c --- /dev/null +++ b/server/tests/api/live/live-rtmps.ts @@ -0,0 +1,146 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { VideoPrivacy } from '@shared/models' +import { + buildAbsoluteFixturePath, + cleanupTests, + createSingleServer, + PeerTubeServer, + sendRTMPStream, + setAccessTokensToServers, + setDefaultVideoChannel, + stopFfmpeg, + testFfmpegStreamError, + waitUntilLivePublishedOnAllServers +} from '../../../../shared/extra-utils' + +const expect = chai.expect + +describe('Test live RTMPS', function () { + let server: PeerTubeServer + let rtmpUrl: string + let rtmpsUrl: string + + async function createLiveWrapper () { + const liveAttributes = { + name: 'live', + channelId: server.store.channel.id, + privacy: VideoPrivacy.PUBLIC, + saveReplay: false + } + + const { uuid } = await server.live.create({ fields: liveAttributes }) + + const live = await server.live.get({ videoId: uuid }) + const video = await server.videos.get({ id: uuid }) + + return Object.assign(video, live) + } + + before(async function () { + this.timeout(120000) + + server = await createSingleServer(1) + + // Get the access tokens + await setAccessTokensToServers([ server ]) + await setDefaultVideoChannel([ server ]) + + await server.config.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } + } + } + }) + + rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live' + rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live' + }) + + it('Should enable RTMPS endpoint only', async function () { + this.timeout(240000) + + await server.kill() + await server.run({ + live: { + rtmp: { + enabled: false + }, + rtmps: { + enabled: true, + port: server.rtmpsPort, + key_file: buildAbsoluteFixturePath('rtmps.key'), + cert_file: buildAbsoluteFixturePath('rtmps.cert') + } + } + }) + + { + const liveVideo = await createLiveWrapper() + + expect(liveVideo.rtmpUrl).to.not.exist + expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl) + + const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey }) + await testFfmpegStreamError(command, true) + } + + { + const liveVideo = await createLiveWrapper() + + const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey }) + await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) + await stopFfmpeg(command) + } + }) + + it('Should enable both RTMP and RTMPS', async function () { + this.timeout(240000) + + await server.kill() + await server.run({ + live: { + rtmp: { + enabled: true, + port: server.rtmpPort + }, + rtmps: { + enabled: true, + port: server.rtmpsPort, + key_file: buildAbsoluteFixturePath('rtmps.key'), + cert_file: buildAbsoluteFixturePath('rtmps.cert') + } + } + }) + + { + const liveVideo = await createLiveWrapper() + + expect(liveVideo.rtmpUrl).to.equal(rtmpUrl) + expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl) + + const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey }) + await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) + await stopFfmpeg(command) + } + + { + const liveVideo = await createLiveWrapper() + + const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey }) + await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) + await stopFfmpeg(command) + } + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) diff --git a/server/tests/fixtures/rtmps.cert b/server/tests/fixtures/rtmps.cert new file mode 100644 index 000000000..3ef606c52 --- /dev/null +++ b/server/tests/fixtures/rtmps.cert @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDazCCAlOgAwIBAgIUKNycLAZUs2jFsWUW+zZhBkpLB2wwDQYJKoZIhvcNAQEL +BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM +GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMTExMDUxMDA4MzhaFw0yMTEy +MDUxMDA4MzhaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw +HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB +AQUAA4IBDwAwggEKAoIBAQDak20d81KG/9mVLU6Qw/uRniC935yf9Rlp8FVCDxUd +zLbfHjrnIOv8kqinUI0nuEQC4DnF7Rbafe88WDU33Q8ixU/R0czUGq1AEwIjyN30 +5NjokCb26xWIly7RCfc/Ot6tjguHwKvcxqJMNC0Lit9Go9MDVnGFLkgHia68P72T +ZDVV44YpzwYDicwQs5C4nZ4yzAeclia07qfUY0VAEZlxJ/9zjwYHCT0AKaEPH35E +dUvjuvJ1OSHSN1S4acR+TPR3FwKQh3H/M/GWIqoiIOpdjFUBLs80QOM2aNrLmlyP +JtyFJLxCP7Ery9fGY/yzHeSxpgOKwZopD6uHZKi5yazNAgMBAAGjUzBRMB0GA1Ud +DgQWBBSSjhRQdWsybNQMLMhkwV+xiP2uoDAfBgNVHSMEGDAWgBSSjhRQdWsybNQM +LMhkwV+xiP2uoDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQC8 +rJu3J5sqVKNQaXOmLPd49RM7KG3Y1KPqbQi1lh+sW6aefZ9daeh3JDYGBZGPG/Fi +IMMP+LhGG0WqDm4ClK00wyNhBuNPEyzvuN/WMRX5djPxO1IZi+KogFwXsn853Ov9 +oV3nxArNNjDu2n92FiB7RTlXRXPIoRo2zEBcLvveGySn9XUazRzlqx6FAxYe2xsw +U3cZ6/wwU1YsEZa5bwIQk+gkFj3zDsTyEkn2ntcE2NlR+AhCHKa/yAxgPFycAVPX +2o+wNnc6H4syP98mMGj9hEE3RSJyCPgGBlgi7Swl64G3YygFPJzfLX9YTuxwr/eI +oitEjF9ljtmdEnf0RdOj +-----END CERTIFICATE----- diff --git a/server/tests/fixtures/rtmps.key b/server/tests/fixtures/rtmps.key new file mode 100644 index 000000000..14a85e70a --- /dev/null +++ b/server/tests/fixtures/rtmps.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDak20d81KG/9mV +LU6Qw/uRniC935yf9Rlp8FVCDxUdzLbfHjrnIOv8kqinUI0nuEQC4DnF7Rbafe88 +WDU33Q8ixU/R0czUGq1AEwIjyN305NjokCb26xWIly7RCfc/Ot6tjguHwKvcxqJM +NC0Lit9Go9MDVnGFLkgHia68P72TZDVV44YpzwYDicwQs5C4nZ4yzAeclia07qfU +Y0VAEZlxJ/9zjwYHCT0AKaEPH35EdUvjuvJ1OSHSN1S4acR+TPR3FwKQh3H/M/GW +IqoiIOpdjFUBLs80QOM2aNrLmlyPJtyFJLxCP7Ery9fGY/yzHeSxpgOKwZopD6uH +ZKi5yazNAgMBAAECggEAND7C+UK8+jnTl13CBsZhrnfemaQGexGJ5pGkv2p9gKb7 +Gy/Nooty/OdNWtjdNJ5N22YfSRkXulgZxBHNfrHfOU9yedOtIxHRUZx5iXYs36mH +02cJeUHN3t1MOnk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