nijie: clear session cookie if it's expired (#4665).

If we detect that the session cookie has expired (by the presence of the
`#login_illust` element on the page), then clear the cached session
cookie. The current source fetch will still fail, but the next fetch
will try to login again and hopefully succeed.
This commit is contained in:
evazion
2021-03-07 23:03:10 -06:00
parent 5e4865701c
commit 869a99d9a3
2 changed files with 57 additions and 22 deletions

View File

@@ -305,6 +305,18 @@ module Sources
end
end
context "when the cached session cookie is invalid" do
should "clear the cached cookie after failing to fetch the data" do
site = Sources::Strategies.find("https://nijie.info/view.php?id=203688")
Cache.put("nijie-session-cookie", HTTP::Cookie.new(name: "NIJIEIJIEID", value: "fake", domain: "nijie.info", path: "/"))
assert_equal("fake", site.cached_session_cookie.value)
assert_equal([], site.image_urls)
assert_nil(Cache.get("nijie-session-cookie"))
end
end
context "a doujin post" do
should "work" do
image = "https://pic.nijie.net/01/dojin_main/dojin_sam/20120213044700%E3%82%B3%E3%83%94%E3%83%BC%20%EF%BD%9E%200011%E3%81%AE%E3%82%B3%E3%83%94%E3%83%BC.jpg"