From 28a613ecc5f99cefd11e171b7b9a90ee0bae3727 Mon Sep 17 00:00:00 2001 From: ImoutoChan Date: Wed, 6 Dec 2023 09:47:05 +0400 Subject: [PATCH] Fix tests --- .../Loaders/Fixtures/SankakuLoaderFixture.cs | 2 +- .../Loaders/SankakuLoaderTests.cs | 2 +- .../Sankaku/SankakuAuthManager.cs | 19 +++++-------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Imouto.BooruParser.Tests/Loaders/Fixtures/SankakuLoaderFixture.cs b/Imouto.BooruParser.Tests/Loaders/Fixtures/SankakuLoaderFixture.cs index ff19d9c..5d59f0a 100644 --- a/Imouto.BooruParser.Tests/Loaders/Fixtures/SankakuLoaderFixture.cs +++ b/Imouto.BooruParser.Tests/Loaders/Fixtures/SankakuLoaderFixture.cs @@ -11,7 +11,7 @@ public class SankakuLoaderFixture private IBooruApiLoader? _withAuth; private IBooruApiLoader? _withoutAuth; private IBooruApiAccessor? _apiAccessor; - private readonly bool _enableCache = false; + private readonly bool _enableCache = true; private IFlurlClientFactory Factory => _enableCache ? new HardCachePerBaseUrlFlurlClientFactory() : new PerBaseUrlFlurlClientFactory(); diff --git a/Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs b/Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs index 07c45cd..47634ab 100644 --- a/Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs +++ b/Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs @@ -160,7 +160,7 @@ public async Task ShouldGetPostByMd5Async_d62ed6aebd2b75aa9661795b54a957d7() var post = await loader.GetPostByMd5Async("d62ed6aebd2b75aa9661795b54a957d7"); post.Should().NotBeNull(); - post!.Tags.Should().HaveCount(61); + post!.Tags.Should().HaveCount(62); } [Fact] diff --git a/Imouto.BooruParser/Implementations/Sankaku/SankakuAuthManager.cs b/Imouto.BooruParser/Implementations/Sankaku/SankakuAuthManager.cs index 7b77dea..90c59df 100644 --- a/Imouto.BooruParser/Implementations/Sankaku/SankakuAuthManager.cs +++ b/Imouto.BooruParser/Implementations/Sankaku/SankakuAuthManager.cs @@ -53,25 +53,15 @@ public async Task> GetSankakuChannelSessionAsyn { if (_options.Value.Login is null || _options.Value.Password is null) return Array.Empty(); + + var jar = new CookieJar(); var client = _factory.Get(new Url("https://chan.sankakucomplex.com")) - .WithHeader("Connection", "keep-alive") - .WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"") - .WithHeader("sec-ch-ua-mobile", "?0") - .WithHeader("sec-ch-ua-platform", "\"Windows\"") - .WithHeader("DNT", "1") - .WithHeader("Upgrade-Insecure-Requests", "1") - .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36") - .WithHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9") - .WithHeader("Sec-Fetch-Site", "none") - .WithHeader("Sec-Fetch-Mode", "navigate") - .WithHeader("Sec-Fetch-User", "?1") - .WithHeader("Sec-Fetch-Dest", "document") - .WithHeader("Accept-Encoding", "gzip, deflate, br") - .WithHeader("Accept-Language", "en"); + .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"); var doc = await client .Request("users", "login") + .WithCookies(jar) .GetHtmlDocumentAsync(); var authenticityToken = doc.DocumentNode.SelectNodes("//form") @@ -82,6 +72,7 @@ public async Task> GetSankakuChannelSessionAsyn IReadOnlyList? cookies = null; var response = await client .Request("en", "users", "authenticate") + .WithCookies(jar) .OnRedirect(x => cookies = x.Response.Cookies) .PostUrlEncodedAsync(new Dictionary() {