Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan committed Dec 6, 2023
1 parent 8d95302 commit 28a613e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 5 additions & 14 deletions Imouto.BooruParser/Implementations/Sankaku/SankakuAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,15 @@ public async Task<IReadOnlyCollection<FlurlCookie>> GetSankakuChannelSessionAsyn
{
if (_options.Value.Login is null || _options.Value.Password is null)
return Array.Empty<FlurlCookie>();

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")
Expand All @@ -82,6 +72,7 @@ public async Task<IReadOnlyCollection<FlurlCookie>> GetSankakuChannelSessionAsyn
IReadOnlyList<FlurlCookie>? cookies = null;
var response = await client
.Request("en", "users", "authenticate")
.WithCookies(jar)
.OnRedirect(x => cookies = x.Response.Cookies)
.PostUrlEncodedAsync(new Dictionary<string, string>()
{
Expand Down

0 comments on commit 28a613e

Please sign in to comment.