using Febe.Core.Abstractions; using Febe.Core.Collection; using Febe.Tests.Browser.TestSupport; namespace Febe.Tests.Collection; /// /// Rule 7 of §2 against §7.6: the pages Alberto opens while he drives and no session runs — the login of «Accedi a /// Instagram», a verification he completes — are not the page «going back to the login»; Instagram's own answers /// (status, text) still are signals. /// [TestClass] public sealed class SignalOwnershipTests { [TestMethod] public void PathRulesAreNotSignalsWhileThePageIsAlbertos() { var clock = new VirtualClock(); var breaker = new RecordingBreaker(); var albertos = true; var detector = new SignalDetector(SignalRules.LoadDefault(), breaker, clock, TimeSpan.Zero) { UserOwnsPage = () => albertos }; NavigationDescriptor Nav(string path) => new(HostKind.Site, "https://www.instagram.com" + path, "www.instagram.com", path, clock.Now); ResponseDescriptor Document(string path, int status) => new("1", HostKind.Site, "https://www.instagram.com" + path, "www.instagram.com", path, status, "text/html", "Document", true, clock.Now); Assert.IsNull(detector.ObserveNavigation(Nav("/accounts/login/"))); Assert.IsNull(detector.ObserveNavigation(Nav("/challenge/AbC123/"))); Assert.IsNull(detector.ObserveResponse(Document("/accounts/login/", 200))); Assert.IsEmpty(breaker.Signals); // Instagram's own answers keep counting: a 429 is a 429 whoever loaded the page. Assert.AreEqual(SignalLevel.Throttle, detector.ObserveResponse(Document("/accounts/login/", 429))?.Level); Assert.IsFalse(detector.ObserveSessionCookie(false) is null, "the recipes' cookie check is not a path rule"); // The engine's page (Alberto not at the browser, or a session running): the same addresses are signals. albertos = false; Assert.AreEqual(SignalLevel.Disconnect, detector.ObserveNavigation(Nav("/accounts/login/"))?.Level); Assert.AreEqual(SignalLevel.Challenge, detector.ObserveResponse(Document("/challenge/AbC123/", 200))?.Level); } }