|
| 1 | +/* |
| 2 | + * Copyright 2026 LiveKit |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +#include <algorithm> |
| 20 | +#include <cstdint> |
| 21 | +#include <memory> |
| 22 | +#include <string> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +#include "../common/audio_utils.h" |
| 26 | +#include "../common/test_common.h" |
| 27 | + |
| 28 | +namespace livekit::test { |
| 29 | + |
| 30 | +class E2EEIntegrationTest : public LiveKitTestBase {}; |
| 31 | + |
| 32 | +TEST_F(E2EEIntegrationTest, FrameCryptorsIncludePublishedTrack) { |
| 33 | + failIfNotConfigured(); |
| 34 | + |
| 35 | + Room room; |
| 36 | + RoomOptions room_options; |
| 37 | + room_options.encryption = E2EEOptions{}; |
| 38 | + room_options.encryption->key_provider_options.shared_key = std::vector<std::uint8_t>{'k', 'e', 'y'}; |
| 39 | + ASSERT_TRUE(room.connect(config_.url, config_.token_a, room_options)); |
| 40 | + auto participant = lockLocalParticipant(room); |
| 41 | + |
| 42 | + auto source = std::make_shared<AudioSource>(kDefaultAudioSampleRate, kDefaultAudioChannels, 0); |
| 43 | + auto track = participant->publishAudioTrack("e2ee-frame-cryptors", source, TrackSource::SOURCE_MICROPHONE); |
| 44 | + auto manager = room.e2eeManager().lock(); |
| 45 | + ASSERT_NE(manager, nullptr); |
| 46 | + |
| 47 | + std::vector<E2EEManager::FrameCryptor> cryptors; |
| 48 | + ASSERT_NO_THROW(cryptors = manager->frameCryptors()); |
| 49 | + const bool found = std::any_of(cryptors.begin(), cryptors.end(), [&](const auto& cryptor) { |
| 50 | + return cryptor.participantIdentity() == participant->identity(); |
| 51 | + }); |
| 52 | + EXPECT_TRUE(found) << "No frame cryptor for the local participant's track"; |
| 53 | + participant->unpublishTrack(track->publication()->sid()); |
| 54 | +} |
| 55 | + |
| 56 | +} // namespace livekit::test |
0 commit comments