Skip to content

Commit

Permalink
Merge pull request #84 from shiguredo/feature/e2e-test-ca-cert
Browse files Browse the repository at this point in the history
Feature/e2e test ca cert
  • Loading branch information
voluntas authored Sep 18, 2024
2 parents 0c37e46 + f640d29 commit 3113193
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 29 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ env:

jobs:
e2e_test_ubuntu:
# if: >-
# ${{
# contains(github.event.head_commit.message, '[e2e]') ||
# github.event_name == 'schedule'
# }}
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12"]
os: ["ubuntu-22.04", "ubuntu-24.04"]
runs-on: ${{ matrix.os}}
timeout-minutes: 30
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
# libx11-dev は Ubuntu 24.04 の時に必要になる模様
Expand All @@ -49,21 +44,17 @@ jobs:
- run: uv run pytest tests/test_signaling_message.py -s
- run: uv run pytest tests/test_re_offer_re_answer_sdp.py -s
- run: uv run pytest tests/test_messaging.py -s
- run: uv run pytest tests/test_ca_cert.py -s
- run: uv run pytest tests/test_vad.py -s

e2e_test_macos:
# if: >-
# ${{
# contains(github.event.head_commit.message, '[e2e]') ||
# github.event_name == 'schedule'
# }}
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12"]
# macos-13 は test_macos.py が上手くテストが動かないのでスキップ
os: ["macos-14"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Download openh264
Expand All @@ -83,19 +74,15 @@ jobs:
- run: uv run pytest tests/test_signaling_message.py -s
- run: uv run pytest tests/test_re_offer_re_answer_sdp.py -s
- run: uv run pytest tests/test_messaging.py -s
- run: uv run pytest tests/test_ca_cert.py -s
- run: uv run pytest tests/test_vad.py -s

e2e_test_windows:
# if: >-
# ${{
# contains(github.event.head_commit.message, '[e2e]') ||
# github.event_name == 'schedule'
# }}
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12"]
runs-on: windows-2022
timeout-minutes: 30
timeout-minutes: 15
env:
# Python を強制的に UTF-8 で利用するおまじない
PYTHONUTF8: 1
Expand All @@ -118,6 +105,7 @@ jobs:
- run: uv run pytest tests/test_signaling_message.py -s
- run: uv run pytest tests/test_re_offer_re_answer_sdp.py -s
- run: uv run pytest tests/test_messaging.py -s
- run: uv run pytest tests/test_ca_cert.py -s
- run: uv run pytest tests/test_vad.py -s

slack_notify_succeeded:
Expand Down
2 changes: 2 additions & 0 deletions tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
audio_sample_rate: int = 16000,
video_width: int = 640,
video_height: int = 480,
ca_cert: Optional[str] = None,
):
self._signaling_urls: list[str] = signaling_urls
self._channel_id: str = channel_id
Expand Down Expand Up @@ -72,6 +73,7 @@ def __init__(
data_channel_signaling=data_channel_signaling,
audio_source=self._audio_source,
video_source=self._video_source,
ca_cert=ca_cert,
)
self._connection_id: Optional[str] = None

Expand Down
107 changes: 107 additions & 0 deletions tests/test_ca_cert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import sys
import time
import uuid

import pytest
from client import Sendonly

"""
このテストは、Sora の CA 証明書が有効かどうかを確認するためのものです。
接続先の Sora が Let's Encrypt の CA 証明書を使用している前提のテストになっています。
"""

# https://letsencrypt.org/certificates/
# ISRG Root X1

letsencrypt_org_ca_cert = """
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
ZXQgU2VjdXJpdHkgU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A4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW
BBSATNbrdP9JNqPV2Py1PsVq8JQdjDAKBggqhkjOPQQDAwNpADBmAjEA6ED/g94D
9J+uHXqnLrmvT/aDHQ4thQEd0dlq7A/Cr8deVl5c1RxYIigL9zC2L7F8AjEA8GE8
p/SgguMh1YQdc4acLa/KNJvxn7kjNuK8YAOdgLOaVsjh4rsUecrNIdSUtUlD
-----END CERTIFICATE-----
"""


def test_ca_cert(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
metadata = setup.get("metadata")

channel_id = f"{channel_id_prefix}_{__name__}_{sys._getframe().f_code.co_name}_{uuid.uuid4()}"

sendonly = Sendonly(
signaling_urls,
channel_id,
audio=True,
video=True,
metadata=metadata,
ca_cert=letsencrypt_org_ca_cert,
)
sendonly.connect(fake_audio=True, fake_video=True)

time.sleep(5)

sendonly.disconnect()


@pytest.mark.xfail(reason="Invalid CA certificate")
def test_ca_cert_invalid(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
metadata = setup.get("metadata")

channel_id = f"{channel_id_prefix}_{__name__}_{sys._getframe().f_code.co_name}_{uuid.uuid4()}"

sendonly = Sendonly(
signaling_urls,
channel_id,
audio=True,
video=True,
metadata=metadata,
ca_cert=pki_goog_ca_cert,
)
sendonly.connect(fake_audio=True, fake_video=True)
18 changes: 7 additions & 11 deletions tests/test_signaling_message.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import random
import sys
import time
import uuid

from client import Sendonly


def test_random_signaling_message(setup):
def test_signaling_message(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
metadata = setup.get("metadata")

channel_id = f"{channel_id_prefix}_{__name__}_{sys._getframe().f_code.co_name}_{uuid.uuid4()}"

selected_audio = random.choice([True, False])
selected_video = random.choice([True, False])

sendonly = Sendonly(
signaling_urls,
channel_id,
audio=selected_audio,
video=selected_video,
audio=True,
video=True,
metadata=metadata,
)
sendonly.connect(fake_audio=selected_audio, fake_video=selected_video)
sendonly.connect(fake_audio=True, fake_video=True)

time.sleep(5)

Expand All @@ -34,7 +30,7 @@ def test_random_signaling_message(setup):
assert sendonly.answer_message is not None

assert sendonly.connect_message["role"] == "sendonly"
assert sendonly.connect_message["channel_id"] is channel_id
assert sendonly.connect_message["audio"] is selected_audio
assert sendonly.connect_message["video"] is selected_video
assert sendonly.connect_message["channel_id"] == channel_id
assert sendonly.connect_message["audio"] is True
assert sendonly.connect_message["video"] is True
assert sendonly.connect_message["metadata"] == metadata

0 comments on commit 3113193

Please sign in to comment.