Commit Graph
100 Commits
Author SHA1 Message Date
evazion f020070b7d Add .editorconfig. 2020-06-21 15:15:47 -05:00
evazion a4efeb2260 gems: drop Mechanize, HTTParty, and Sinatra gems. 2020-06-21 15:13:42 -05:00
evazion 5c7843bd3d scripts: refactor mocked services.
Replace the mocked services in scripts/mocked_services with Rails-level
mocked services.

The scripts in scripts/mocked_services were a set of stub Sinatra
servers used to mock the Reportbooru, Recommender, and IQDBs services
during development. They return fake data so you can test pages that use
these services.

Implementing these services in Rails makes it easier to run them. It
also lets us drop a dependency on Sinatra and drop a use of HTTParty.

To use these services, set the following configuration in danbooru_local_config.rb
or .env.local:

* reportbooru_server: http://localhost:3000/mock/reportbooru
* recommender_server: http://localhost:3000/mock/recommender
* iqdbs_server: http://localhost:3000/mock/iqdb

where `http://localhost:300` is the url for your local Danbooru server
(may need to be changed depending on your configuration).
2020-06-21 15:11:56 -05:00
evazion 29a5f7dfc8 image proxy: replace HTTParty with Danbooru::Http. 2020-06-21 15:11:56 -05:00
evazion 7e471fe223 sources: replace HTTParty with Danbooru::Http in http_exists?. 2020-06-21 15:11:56 -05:00
evazion 3ad8c708c5 pixiv: replace HTTParty with Danbooru::Http. 2020-06-21 15:11:56 -05:00
evazion 5604ab0079 pixiv: remove fanbox support.
This is broken and it needs to be rewritten as a separate source
strategy anyway.
2020-06-21 11:59:51 -05:00
evazion 2da8174ce2 hentai foundry: replace HTTParty with Danbooru::Http. 2020-06-21 05:22:57 -05:00
evazion 6e6ce6e62f nijie: replace Mechanize with Danbooru::Http.
The Nijie login process works like this:

* First we submit our `email` and `password` to `https://nijie.info/login_int.php`.
* Then we save the NIJIEIEID session cookie from the response.
* We optionally retry if login failed. Nijie returns 429 errors with a
  `Retry-After: 5` header if we send too many login requests. This can
  happen during parallel testing.
* We cache the login cookies for only 1 hour so we don't have to worry
  about them becoming invalid if we cache them too long.

Cookies and retrying errors on failure are handled transparently by Danbooru::Http.
2020-06-21 05:22:57 -05:00
evazion 05d7355ebb danbooru::http: support automatically following redirects.
Replace http.rb's builtin redirect following option with our own
redirect follower. This fixes an issue with http.rb losing cookies after
following a redirect.
2020-06-21 05:22:57 -05:00
evazion 71b0bc6c0f danbooru::http: support tracking cookies between requests.
Allow cookies to be saved and sent back when making several requests in
a row. Usage:

    http = Danbooru::Http.use(:session)

    # saves the foo=42 cookie sent by the response.
    http.get("https://httpbin.org/cookies/set/foo/42")

    # sends back the foo=42 cookie from the previous request.
    http.get("https://httpbin.org/cookies")
2020-06-21 05:22:56 -05:00
evazion 87ed882234 danbooru::http: support automatically retrying 429 errors. 2020-06-21 05:22:30 -05:00
evazion a929f3134e danbooru::http: parse html responses. 2020-06-21 05:22:27 -05:00
evazion f730951e7f gems: drop webmock. 2020-06-20 00:20:39 -05:00
evazion 26ad844bbe downloads: refactor Downloads::File into Danbooru::Http.
Remove the Downloads::File class. Move download methods to
Danbooru::Http instead. This means that:

* HTTParty has been replaced with http.rb for downloading files.

* Downloading is no longer tightly coupled to source strategies. Before
  Downloads::File tried to automatically look up the source and download
  the full size image instead if we gave it a sample url. Now we can
  do plain downloads without source strategies altering the url.

* The Cloudflare Polish check has been changed from checking for a
  Cloudflare IP to checking for the CF-Polished header. Looking up the
  list of Cloudflare IPs was slow and flaky during testing.

* The SSRF protection code has been factored out so it can be used for
  normal http requests, not just for downloads.

* The Webmock gem can be removed, since it was only used for stubbing
  out certain HTTParty requests in the download tests. The Webmock gem
  is buggy and caused certain tests to fail during CI.

* The retriable gem can be removed, since we no longer autoretry failed
  downloads. We assume that if a download fails once then retrying
  probably won't help.
2020-06-20 00:20:39 -05:00
evazion 10b7a53449 unicorn: increase socket backlog. 2020-06-19 15:09:43 -05:00
evazion 7a1efc2744 Fix #4522: Sidebar doesn't show most searched tags at certain times of day.
Revert back to previous workaround of fetching previous day if current
day returns no result. A terrible hack, really we should convert dates
to Reportbooru's timezone, but that has other complications.
2020-06-19 14:00:50 -05:00
evazion 67a52dbc2d tumblr: support new va.media.tumblr.com urls. 2020-06-19 13:53:35 -05:00
evazion 05f78f9bef saved searches: fix call to redis.exists?
https://github.com/redis/redis-rb/blob/master/CHANGELOG.md#421
2020-06-19 13:53:35 -05:00
evazion cd9e3e7f3d Update Rails to 6.0.3.2.
Fixes CVE-2020-8185: Untrusted users able to run pending migrations in production.
2020-06-19 03:14:25 -05:00
evazion 440bbbb288 Update nokogiri gem.
Fix gem version conflicts described in 20abd8a5f. Nokogiri couldn't be
upgraded past 1.10.9 because 1.11.0 causes a build failure in Nokogumbo
2.0.2, but we couldn't stay on 1.10.9 either because it has a hard
requirement on Ruby <2.7 and we require Ruby >=2.7. This made `bundle
update` fail with a Gemfile conflict.

The fix is to disable libxml2 support when building Nokogumbo. Nokogumbo
wants to use the same version of libxml2 as Nokogiri, but Nokogiri
1.11.0 changed how it reports which version of libxml2 it's using, which
causes Nokogumbo's build to fail. Disabling libxml2 may reduce
performance of Nokogumbo ([1]).

While we're at it, we also make Nokogiri use the system version of
libxml2 instead of its own bundled version. Nokogiri really wants
us to use its own patched version of libxml2 instead of the system
version, but the patches it applies look relatively minor and don't seem
relevant to us ([2]). Using the system version reduces build time during CI.

This adds libxml2 and libxslt as OS-level dependencies of Danbooru. You
may need to do `sudo apt-get install libxml2-dev libxslt-dev` to install
these libraries after this commit.

[1]: https://github.com/rubys/nokogumbo#flavors-of-nokogumbo
[2]: https://github.com/sparklemotion/nokogiri/tree/master/patches/libxml2
2020-06-19 02:27:15 -05:00
evazion 491a53ffe3 Update mock_redis. 2020-06-19 02:25:28 -05:00
evazion ae7fc7d1bc Update eslint to 7.0, add babel-eslint plugin.
Add babel-eslint plugin so that eslint can recognize optional chaining
syntax (a?.b).
2020-06-19 02:25:28 -05:00
evazion 213766fac9 posts: fix "view original" not working on mobile.
ref: https://github.com/danbooru/danbooru/commit/38f385d1ca93dba6d7de9f228f61c1f9a1eb4c27#r40000777
2020-06-18 12:25:45 -05:00
evazion 459f67c431 iqdb: fix 599 timeout errors.
Increase timeout to 30 seconds when uploading files to IQDB. Previously
we used the default timeout of 3 seconds, which could cause 599 timeout
errors sometimes if the upload took too long.
2020-06-18 00:57:51 -05:00
evazion f790a1aeed http: increase default timeout to 10 seconds.
Three seconds was little tight and might have caused timeouts in source
strategies sometimes.
2020-06-18 00:56:42 -05:00
evazion fd6ba473a5 tests: possible fix for images getting nuked by tests. 2020-06-17 12:30:37 -05:00
evazion d5a7eef53d uploads: fix remote file size not appearing. 2020-06-17 04:13:16 -05:00
evazion b8b5c8d6a0 iqdb: fix error with file uploads.
Fix "cannot determine size of body" errors on upload page. Caused by
exception during IQDB lookup. We were posting the form data wrong, we
need to wrap the file with HTTP::FormData::File and pass it through the
`form` parameter.
2020-06-17 02:28:16 -05:00
evazion 91beb288b6 reportbooru: cache post views endpoint.
Cache most viewed posts endpoint for /explore/posts/viewed page.
2020-06-17 00:57:55 -05:00
evazion 8d4844d485 Merge pull request #4517 from nonamethanks/fix_4509
Add more tags to post replacements filtering and modqueue highlighting.
2020-06-17 00:49:01 -05:00
evazion b551e3634f Fix misc rubocop warnings. 2020-06-16 21:36:15 -05:00
evazion dc460aab53 Merge pull request #4514 from danbooru/dependabot/bundler/sanitize-5.2.1
build(deps): bump sanitize from 5.2.0 to 5.2.1
2020-06-16 19:52:59 -05:00
evazion a572a6614d popular/missed searches: fix blank views.
Fix missing call to `.each`.
2020-06-16 13:09:05 -05:00
evazion 101e8a13b8 /posts: fix blank tag sidebars.
Fix the sidebar on the /posts index page sometimes being blank. This
could happen when either the related tag calculation was too slow and
timed out, or when Reporbooru was unavailable and we couldn't fetch the
list of popular tags.

In the tag list would otherwise be blank, we fall back to frequent tags
(the most common tags on the current page of results).

Also change it so that if Reportbooru is unconfigured, we fail
gracefully by returning blank results instead of failing with an
exception. This is so we can still view the popular searches and missed
searches pages during testing (even though they'll be blank).
2020-06-16 12:58:41 -05:00
evazion ed152a780b Upgrade ruby gems and yarn packages. 2020-06-16 00:38:09 -05:00
evazion 1aa0f65187 sources: fix rubocop warnings. 2020-06-16 00:10:37 -05:00
evazion 049f33916b tests: fix random username conflicts.
Fix parallel tests randomly failing because of username conflicts.
2020-06-16 00:10:37 -05:00
evazion b583b3c810 tests: fix nicoseiga download tests. 2020-06-16 00:10:35 -05:00
evazion 7868e5045e nicoseiga: fix regression with http redirects.
3cdf67920 changed it so that Danbooru::Http follows redirects by
default. This broke some things in the Nico Seiga strategy, so disable
following redirects in the Nico Seiga API client for now.

Also change it so that Danbooru::Http follows redirects after a POST
request (by setting `strict: false`). Nico Seiga needs this because it
sends a redirect after we POST the login form.
2020-06-15 22:13:28 -05:00
evazion 962e60f4f1 Merge pull request #4496 from nonamethanks/refactor_nicoseiga
Refactor nicoseiga
2020-06-15 21:05:10 -05:00
evazion 19727ab5c4 Merge pull request #4505 from nonamethanks/pixiv_digital_tags
Pixiv: don't blacklist digital tools anymore
2020-06-15 20:56:56 -05:00
evazion 52367c79e2 ci: upload code coverage even when tests fail. 2020-06-15 20:21:09 -05:00
evazion 4c56447d66 ci: add codecov.io integration. 2020-06-15 17:32:59 -05:00
evazion 107729e17f ci: enable codeclimate reporter debug output. 2020-06-15 17:21:41 -05:00
evazion a615a28b1b ci: disable warnings during tests. 2020-06-15 16:45:37 -05:00
evazion f60b184a12 ci: don't trigger twice on pull requests. 2020-06-15 16:45:37 -05:00
evazion 6a7d25591b ci: use more permissive rubocop / codeclimate settings. 2020-06-15 16:45:37 -05:00
evazion ec5aa6c662 tests: fix saved search index action test.
This passed in development but failed in CI because SavedSearch.redis
used the live Redis server, which worked by accident as long as you had
a Redis server running.
2020-06-15 16:45:37 -05:00
evazion 3cdf679202 http: automatically follow redirects.
* Automatically follow redirects (up to 5, return a synthetic 598 error after that).
* Add `put` and `timeout` methods.
* Add tests.
2020-06-14 01:39:55 -05:00
evazion cd501fe27b iqdb: switch to Danbooru::Http. 2020-06-14 01:06:51 -05:00
evazion a4df18e650 Refactor Reportbooru API clients.
* Combine MissedSearchService, PostViewCountService, and
  PopularSearchService into single ReportbooruService class.
* Use Danbooru::Http for these services instead of HTTParty.
2020-06-14 00:32:42 -05:00
evazion 1846133cd6 post view count service: switch to Danbooru::Http. 2020-06-13 21:50:06 -05:00
evazion 9e29326b96 README.md: add Discord status badge. 2020-06-12 00:49:01 -05:00
evazion 025e09ff7f tests: upload test coverage reports to code climate.
Downgrade simplecov to 0.17 because 0.18 is incompatible with code
climate. Ref: github.com codeclimate/test-reporter/issues/413
2020-06-11 15:35:15 -05:00
evazion 8181ee6a1d Update rubocop config. 2020-06-11 14:08:23 -05:00
evazion 889c4ce4d9 Add Code Climate integration. 2020-06-11 13:31:17 -05:00
evazion be4646aa6f tests: fix username conflicts in parallel tests.
Parallel tests sometimes failed because the username generator sometimes
generated duplicate usernames.
2020-06-11 02:43:19 -05:00
evazion e14a577ed9 tests: clean up test_helper.rb initialization. 2020-06-11 02:41:44 -05:00
evazion 8e50f1d1a0 tests: remove unused test images in tmp/. 2020-06-11 02:41:17 -05:00
evazion 27c5361b96 tests: add minimum test coverage requirements. 2020-06-11 02:40:02 -05:00
evazion a829fbfb8d tests: fix test coverage reporting for parallel testing.
* Fix simplecov clobbering test coverage reports when using parallel tests.
* Generate coverage reports by default (remove $SIMPLECOV flag).
* Store coverage reports in tmp/coverage/ instead of coverage/.
* Enable branch coverage.

ref: github.com /colszowka/simplecov/issues/718#issuecomment-538201587
2020-06-11 02:16:20 -05:00
evazion 99a9149fc4 tests: eliminate as_user helper. 2020-06-11 01:02:01 -05:00
evazion 2d05004bef tests: don't cache pixiv sessions. 2020-06-11 00:47:12 -05:00
evazion 7ba786010d tests: store test uploads in temp dir.
Fixes parallel tests failing because uploads for different tests were
stored in the same directory and uploads got clobbered when cleaning up
this directory.
2020-06-10 22:54:33 -05:00
evazion 04c8c25976 tests: initialize pawoo credentials in github tests. 2020-06-10 22:49:28 -05:00
evazion 88dfc463a1 db/seeds: fix deprecation warning in find_or_create_by!.
`User.find_or_create_by!` calls `User.name_matches` during username
validation, which triggers a deprecation warning for some reason:

    DEPRECATION WARNING: Class level methods will no longer inherit scoping
    from `create!` in Rails 6.1. To continue using the scoped relation,
    pass it into the block directly. To instead access the full set of
    models, as Rails 6.1 will, use `User.default_scoped`.
2020-06-10 22:33:36 -05:00
evazion 5919fa0ca1 tests: enable parallel tests. 2020-06-10 22:26:47 -05:00
evazion 60e96f0e01 tests: fix post url generation test. 2020-06-10 20:22:21 -05:00
evazion 2ede41c4dc tests: fix twitter test broken by deleted tweet. 2020-06-10 20:22:16 -05:00
evazion ab1931a920 tests: fix artstation download tests.
Fix ArtStation download tests that were broken when 266e4054 added the
ability to download /4k/ files.
2020-06-10 19:45:56 -05:00
evazion d6b266514b tests: disable known broken pixiv fanbox tests. 2020-06-10 18:21:44 -05:00
evazion 45b3370d49 models: fix exception in api_attributes.
Fixup bug in eacb4d4df when calling `api_attributes` on an object that
doesn't have a policy (its policy inherited from ApplicationPolicy).
2020-06-10 18:16:58 -05:00
evazion 8a2ae91ff2 tests: skip video file tests if ffmpeg isn't installed. 2020-06-10 18:07:54 -05:00
evazion 15423e0b7b tests: add progress bar to test output.
Add minitest-reporters gem. Replace the default output of `bin/rails
test` with a progress bar. The default output just emits periods for
passed tests, which makes it hard to tell how long tests will take and
causes test runner output on Github to appear to hang. The web console
on Github is line buffered, but the default test runner doesn't normally
emit newlines (unless a test fails), so the output can hang for a long
time.
2020-06-10 17:52:33 -05:00
evazion 5e63a7cf77 Add test workflow. 2020-06-10 17:52:13 -05:00
evazion 8b5b320be7 docker: fix file permission problems.
Store the app in /home/danbooru/app instead of in /app so that we have
permission to write inside the app dir. /app was owned by root, which
prevented the danbooru user from writing to it.
2020-06-09 17:50:47 -05:00
evazion 15799f8af7 Fix #4260: Unable to replace cdn.donmai.us images?
Bug: Replacing posts hosted on cdn.donmai.us didn't work.

Cause: Original files on cdn.donmai.us are hosted under /var/www/danbooru/original/, but replacements
were trying to store them directly under /var/www/danbooru, which failed with a permission error.
We were trying to store them in the wrong directory because we didn't respect the `original_subdir`
option when generating file paths.
2020-06-09 15:57:43 -05:00
evazion 20abd8a5fd Fix build failure in nokogumbo.
Nokogumbo-2.0.2 fails to build when Nokogiri-1.11.0 is installed.
Nokogiri introduced some changes that are apparently incompatible with
Nokogumbo.

ref: https://nokogiri.org/CHANGELOG.html#versioninfo-and-the-output-of-nokogiri-v
2020-06-09 13:20:46 -05:00
evazion 8b5ffb4c43 uploads: allow admins to upload videos more than 2 minutes long.
At some point the ability for admins to bypass the video length
restriction got lost.

ref: https://danbooru.donmai.us/forum_topics/14647
2020-06-09 03:08:06 -05:00
evazion d002701bc1 Merge pull request #4494 from nonamethanks/fix_deviantart_api_downloads
Deviantart: fix api downloads
2020-06-09 01:37:03 -05:00
evazion 1ea0141ae1 Merge pull request #4499 from BrokenEagle/fix-4408
Fix notes having absolute coordinates upon creation
2020-06-09 01:36:44 -05:00
evazion 38f385d1ca js, css: fix eslint and stylelint warnings. 2020-06-09 01:35:44 -05:00
evazion b1f22df4ab Upgrade ruby version to 2.7.1. 2020-06-09 01:35:40 -05:00
evazion 470c3edd94 Upgrade ruby gems and yarn packages. 2020-06-09 01:21:56 -05:00
evazion 3a8d894154 Merge pull request #4498 from danbooru/dependabot/bundler/websocket-extensions-0.1.5
build(deps): bump websocket-extensions from 0.1.4 to 0.1.5
2020-06-09 01:11:41 -05:00
evazion f1581789ac Merge pull request #4500 from danbooru/dependabot/npm_and_yarn/websocket-extensions-0.1.4
build(deps): bump websocket-extensions from 0.1.3 to 0.1.4
2020-06-09 01:10:49 -05:00
evazion 3033bb4530 Update danbooru Dockerfile.
Split into build stage and runtime stage to reduce image size.
2020-06-09 01:07:42 -05:00
evazion eacb4d4df3 models: factor out api_attributes to policies.
Refactor models so that we define attribute API permissions in policy
files instead of directly in models.

This is cleaner because a) permissions are better handled by policies
and b) which attributes are visible to the API is an API-level concern
that models shouldn't have to care about.

This fixes an issue with not being able to precompile CSS/JS assets
unless the database was up and running. This was a problem when building
Docker images because we don't have a database at build time. We needed
the database because `api_attributes` was a class-level macro in some
places, which meant it ran at boot time, but this triggered a database
call because api_attributes used database introspection to get the list
of allowed API attributes.
2020-06-08 18:38:02 -05:00
evazion b6ed63841d footer: fix exception if git hash isn't defined.
The git hash may be undefined when running in a Docker container.
2020-06-08 18:12:32 -05:00
evazion 6d78d22571 Update docker test configuration. 2020-06-07 17:14:41 -05:00
evazion aa9d34a3f0 config: make danbooru_local_config.rb optional.
Make it so that if danbooru_local_config.rb doesn't exist, we continue
with the default config instead of failing.
2020-06-05 15:49:51 -05:00
evazion 82c09858f2 Remove unused data attributes from <body> tag.
Fixup for 647556761.
2020-06-03 11:51:21 -05:00
evazion 647556761b Fix antiproxying (again).
Fuck it, just hardcode it. They rewrite certain parts of our markup so
we can't rely on anything in the html.
2020-06-02 23:30:15 -05:00
evazion bfa76abb56 layouts/default: move <script> tag from header to footer.
* Inline Javascript in the <head> is a minor bottleneck because it
  blocks page rendering.
* Fix antiproxying protection (proxy sites like to strip <script> tags
  from the header).
2020-06-02 22:09:44 -05:00
evazion 91640447c0 Fix antiproxying config options.
Don't embed config options directly in Javascript. Including them in the
Javascript forces us to recompile the Javascript whenever these options
change, which requires us to redeploy the entire site instead of just
restarting the app server.
2020-06-02 20:50:39 -05:00
evazion 18ce552dae tests: fix upload controller tests.
We can't use the name `test_file_upload` because then the helper method
gets treated like it's a test case.
2020-06-02 18:25:45 -05:00
evazion 276f23ba8d config: refactor remove_tag_after_replacement? config option. 2020-06-02 18:25:45 -05:00
evazion 47e6821a31 config: remove customize_new_user config option. 2020-06-02 18:25:45 -05:00
evazion 484eacfd3b config: remove is_unlimited_metatag? config option. 2020-06-02 18:25:42 -05:00