|
4 | 4 |
|
5 | 5 | namespace policy = autoConfig::probePolicy; |
6 | 6 |
|
| 7 | +TEST_CASE("Standard Twitch probes accept only official endpoints and bounded keys") |
| 8 | +{ |
| 9 | + const std::string acceptedServers[] = { |
| 10 | + "auto", |
| 11 | + "AUTO", |
| 12 | + "rtmp://live.twitch.tv/app", |
| 13 | + "RTMPS://LIVE.TWITCH.TV/app", |
| 14 | + "rtmps://video-weaver.example.live-video.net:443/app", |
| 15 | + "rtmp://ingest.example.twitch.tv/app", |
| 16 | + }; |
| 17 | + for (const std::string &server : acceptedServers) { |
| 18 | + CAPTURE(server); |
| 19 | + CHECK(policy::isOfficialTwitchServer(server)); |
| 20 | + } |
| 21 | + |
| 22 | + const std::string rejectedServers[] = { |
| 23 | + "", |
| 24 | + "live.twitch.tv", |
| 25 | + "http://live.twitch.tv/app", |
| 26 | + "rtmp:///app", |
| 27 | + "rtmp://user@live.twitch.tv/app", |
| 28 | + "rtmp://live.twitch.tv@evil.example/app", |
| 29 | + "rtmp://live.twitch.tv.evil.example/app", |
| 30 | + "rtmp://evil-live-video.net/app", |
| 31 | + "rtmp://twitch.tv.evil.example/app", |
| 32 | + }; |
| 33 | + for (const std::string &server : rejectedServers) { |
| 34 | + CAPTURE(server); |
| 35 | + CHECK_FALSE(policy::isOfficialTwitchServer(server)); |
| 36 | + } |
| 37 | + |
| 38 | + CHECK(policy::isBoundedTwitchKey("live_123_example")); |
| 39 | + CHECK(policy::isBoundedTwitchKey(std::string(4096, 'k'))); |
| 40 | + CHECK_FALSE(policy::isBoundedTwitchKey("")); |
| 41 | + CHECK_FALSE(policy::isBoundedTwitchKey(std::string(4097, 'k'))); |
| 42 | + CHECK_FALSE(policy::isBoundedTwitchKey("live key")); |
| 43 | + CHECK_FALSE(policy::isBoundedTwitchKey("live\tkey")); |
| 44 | + CHECK_FALSE(policy::isBoundedTwitchKey(std::string("live\0key", 8))); |
| 45 | +} |
| 46 | + |
| 47 | +TEST_CASE("Unbound YouTube probes accept only the official RTMPS endpoint and bounded keys") |
| 48 | +{ |
| 49 | + const std::string acceptedServers[] = { |
| 50 | + "rtmps://a.rtmps.youtube.com/live2", |
| 51 | + "RTMPS://A.RTMPS.YOUTUBE.COM/live2", |
| 52 | + "rtmps://a.rtmps.youtube.com:443/live2", |
| 53 | + }; |
| 54 | + for (const std::string &server : acceptedServers) { |
| 55 | + CAPTURE(server); |
| 56 | + CHECK(policy::isOfficialYoutubeRtmpsServer(server)); |
| 57 | + } |
| 58 | + |
| 59 | + const std::string rejectedServers[] = { |
| 60 | + "", |
| 61 | + "rtmp://a.rtmps.youtube.com/live2", |
| 62 | + "rtmps://a.rtmps.youtube.com", |
| 63 | + "rtmps://a.rtmps.youtube.com/", |
| 64 | + "rtmps://a.rtmps.youtube.com/live2/", |
| 65 | + "rtmps://b.rtmps.youtube.com/live2", |
| 66 | + "rtmps://sub.a.rtmps.youtube.com/live2", |
| 67 | + "rtmps://a.rtmps.youtube.com.evil.example/live2", |
| 68 | + "rtmps://user@a.rtmps.youtube.com/live2", |
| 69 | + "rtmps://a.rtmps.youtube.com:80/live2", |
| 70 | + "rtmps://a.rtmps.youtube.com:443:443/live2", |
| 71 | + "rtmps://a.rtmps.youtube.com/live2?query", |
| 72 | + "rtmps://a.rtmps.youtube.com/live2#fragment", |
| 73 | + "rtmps://a.rtmps.youtube.com/live 2", |
| 74 | + }; |
| 75 | + for (const std::string &server : rejectedServers) { |
| 76 | + CAPTURE(server); |
| 77 | + CHECK_FALSE(policy::isOfficialYoutubeRtmpsServer(server)); |
| 78 | + } |
| 79 | + |
| 80 | + CHECK(policy::isBoundedYoutubeKey("abcd-1234_efgh.example")); |
| 81 | + CHECK(policy::isBoundedYoutubeKey(std::string(1024, 'k'))); |
| 82 | + CHECK_FALSE(policy::isBoundedYoutubeKey("")); |
| 83 | + CHECK_FALSE(policy::isBoundedYoutubeKey(std::string(1025, 'k'))); |
| 84 | + CHECK_FALSE(policy::isBoundedYoutubeKey("live key")); |
| 85 | + CHECK_FALSE(policy::isBoundedYoutubeKey("live\nkey")); |
| 86 | + CHECK_FALSE(policy::isBoundedYoutubeKey(std::string("live\0key", 8))); |
| 87 | + for (const char reserved : std::string("/\\?#@:")) { |
| 88 | + CAPTURE(reserved); |
| 89 | + CHECK_FALSE(policy::isBoundedYoutubeKey(std::string("live") + reserved + "key")); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +TEST_CASE("Active probe eligibility preserves specific Dual Output denials") |
| 94 | +{ |
| 95 | + const auto eligible = policy::decideActiveProbeEligibility(true, true, true, true, true, false, false); |
| 96 | + CHECK(eligible.eligible); |
| 97 | + CHECK(eligible.denialReason.empty()); |
| 98 | + |
| 99 | + const auto customProvider = policy::decideActiveProbeEligibility(false, true, true, true, true, false, false); |
| 100 | + CHECK_FALSE(customProvider.eligible); |
| 101 | + CHECK(customProvider.denialReason == "active_probe_not_eligible"); |
| 102 | + |
| 103 | + const auto nonOfficialEndpoint = policy::decideActiveProbeEligibility(true, true, true, false, true, false, false); |
| 104 | + CHECK_FALSE(nonOfficialEndpoint.eligible); |
| 105 | + CHECK(nonOfficialEndpoint.denialReason == "active_probe_not_eligible"); |
| 106 | + |
| 107 | + CHECK_FALSE(policy::decideActiveProbeEligibility(true, false, true, true, true, false, false).eligible); |
| 108 | + CHECK_FALSE(policy::decideActiveProbeEligibility(true, true, false, true, true, false, false).eligible); |
| 109 | + CHECK_FALSE(policy::decideActiveProbeEligibility(true, true, true, true, false, false, false).eligible); |
| 110 | + |
| 111 | + const auto unsupportedJointPair = policy::decideActiveProbeEligibility(true, true, true, true, true, true, false); |
| 112 | + CHECK_FALSE(unsupportedJointPair.eligible); |
| 113 | + CHECK(unsupportedJointPair.denialReason == "dual_output_multiple_active_legs"); |
| 114 | + |
| 115 | + const auto supportedJointPair = policy::decideActiveProbeEligibility(true, true, true, true, true, true, true); |
| 116 | + CHECK(supportedJointPair.eligible); |
| 117 | + CHECK(supportedJointPair.denialReason.empty()); |
| 118 | + |
| 119 | + const auto duplicateJointProbe = policy::decideActiveProbeEligibility(true, true, true, true, false, true, true); |
| 120 | + CHECK_FALSE(duplicateJointProbe.eligible); |
| 121 | + CHECK(duplicateJointProbe.denialReason == "active_probe_not_eligible"); |
| 122 | +} |
| 123 | + |
| 124 | +TEST_CASE("Standard Dual Output probing requires distinct registered horizontal and vertical canvases") |
| 125 | +{ |
| 126 | + CHECK(policy::standardDualOutputCanvasPairIsValid("horizontal", 1, true, "vertical", 2, true)); |
| 127 | + CHECK(policy::standardDualOutputCanvasPairIsValid("vertical", 2, true, "horizontal", 1, true)); |
| 128 | + CHECK_FALSE(policy::standardDualOutputCanvasPairIsValid("horizontal", 1, true, "vertical", 1, true)); |
| 129 | + CHECK_FALSE(policy::standardDualOutputCanvasPairIsValid("horizontal", 1, false, "vertical", 2, true)); |
| 130 | + CHECK_FALSE(policy::standardDualOutputCanvasPairIsValid("horizontal", 1, true, "vertical", 2, false)); |
| 131 | + CHECK_FALSE(policy::standardDualOutputCanvasPairIsValid("horizontal", 1, true, "horizontal", 2, true)); |
| 132 | +} |
| 133 | + |
7 | 134 | TEST_CASE("Provider probe coverage distinguishes absent, partial, and complete evidence") |
8 | 135 | { |
9 | 136 | CHECK(policy::classifyProviderProbeCoverage(2, 0) == policy::ProviderProbeCoverage::None); |
|
0 commit comments