2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-11-07 10:01:58 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require_dependency 'issue_2715_fix_broken_twitter_urls_job' # Rails autoloading expects `issue2715_fix...`
|
|
|
|
|
|
|
|
RSpec.describe Issue2715FixBrokenTwitterUrlsJob, type: :job do
|
|
|
|
context 'with existing Twitter articles' do
|
Fixes #2715 - Twitter status URLs are broken
This commit is a complement of its parent:
the parent fixes broken links to Twitter DMs,
while this one fixes broken links to Twitter statuses.
When importing tweets (articles of type "twitter status"),
Zammad generates a source link URL using the following format:
https://twitter.com/statuses/:id
and then stores that URL under `article.preferences[:links]`.
This URL template worked until as recently as 2017[0],
but currently fails for users actively logged in to Twitter.
Now, the correct URL template appears to be
https://twitter.com/:user_id/status/:id
where `:user_id` is not strict, and may be any word (\w+) <= 20 chars.
Try it yourself:
$ curl https://twitter.com/elonmusk/status/1069382411899817990
<html><body>You are being <a href="https://twitter.com/medenhofer/status/1069382411899817990">redirected</a>.</body></html>
In this commit, we replace `:user_id` with a single underscore (`_`).
This behavior is not officially documented anywhere (as far as I know),
but it works (for now).
This commit also extends the previous commit's DB migration/bg job
to rectify existing, broken tweet URLs stored in the database.
For performance purposes, this migration is performed in the background
and limited to the latest 10,000 Twitter articles.
[0]: https://stackoverflow.com/questions/41786123
GitHub: https://github.com/zammad/zammad/issues/2715
2019-11-14 06:03:34 +00:00
|
|
|
let!(:tweet) { create(:twitter_article, preferences: tweet_preferences) }
|
2019-11-07 10:01:58 +00:00
|
|
|
let!(:dm) { create(:twitter_dm_article, preferences: dm_preferences) }
|
|
|
|
|
Fixes #2715 - Twitter status URLs are broken
This commit is a complement of its parent:
the parent fixes broken links to Twitter DMs,
while this one fixes broken links to Twitter statuses.
When importing tweets (articles of type "twitter status"),
Zammad generates a source link URL using the following format:
https://twitter.com/statuses/:id
and then stores that URL under `article.preferences[:links]`.
This URL template worked until as recently as 2017[0],
but currently fails for users actively logged in to Twitter.
Now, the correct URL template appears to be
https://twitter.com/:user_id/status/:id
where `:user_id` is not strict, and may be any word (\w+) <= 20 chars.
Try it yourself:
$ curl https://twitter.com/elonmusk/status/1069382411899817990
<html><body>You are being <a href="https://twitter.com/medenhofer/status/1069382411899817990">redirected</a>.</body></html>
In this commit, we replace `:user_id` with a single underscore (`_`).
This behavior is not officially documented anywhere (as far as I know),
but it works (for now).
This commit also extends the previous commit's DB migration/bg job
to rectify existing, broken tweet URLs stored in the database.
For performance purposes, this migration is performed in the background
and limited to the latest 10,000 Twitter articles.
[0]: https://stackoverflow.com/questions/41786123
GitHub: https://github.com/zammad/zammad/issues/2715
2019-11-14 06:03:34 +00:00
|
|
|
let(:tweet_preferences) do
|
|
|
|
# NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
|
2021-07-01 11:23:52 +00:00
|
|
|
{ links: [{ url: "https://twitter.com/statuses/#{Faker::Number.number(digits: 20)}" }] }
|
Fixes #2715 - Twitter status URLs are broken
This commit is a complement of its parent:
the parent fixes broken links to Twitter DMs,
while this one fixes broken links to Twitter statuses.
When importing tweets (articles of type "twitter status"),
Zammad generates a source link URL using the following format:
https://twitter.com/statuses/:id
and then stores that URL under `article.preferences[:links]`.
This URL template worked until as recently as 2017[0],
but currently fails for users actively logged in to Twitter.
Now, the correct URL template appears to be
https://twitter.com/:user_id/status/:id
where `:user_id` is not strict, and may be any word (\w+) <= 20 chars.
Try it yourself:
$ curl https://twitter.com/elonmusk/status/1069382411899817990
<html><body>You are being <a href="https://twitter.com/medenhofer/status/1069382411899817990">redirected</a>.</body></html>
In this commit, we replace `:user_id` with a single underscore (`_`).
This behavior is not officially documented anywhere (as far as I know),
but it works (for now).
This commit also extends the previous commit's DB migration/bg job
to rectify existing, broken tweet URLs stored in the database.
For performance purposes, this migration is performed in the background
and limited to the latest 10,000 Twitter articles.
[0]: https://stackoverflow.com/questions/41786123
GitHub: https://github.com/zammad/zammad/issues/2715
2019-11-14 06:03:34 +00:00
|
|
|
end
|
|
|
|
|
2019-11-07 10:01:58 +00:00
|
|
|
let(:dm_preferences) do
|
|
|
|
{
|
Fixes #2715 - Twitter status URLs are broken
This commit is a complement of its parent:
the parent fixes broken links to Twitter DMs,
while this one fixes broken links to Twitter statuses.
When importing tweets (articles of type "twitter status"),
Zammad generates a source link URL using the following format:
https://twitter.com/statuses/:id
and then stores that URL under `article.preferences[:links]`.
This URL template worked until as recently as 2017[0],
but currently fails for users actively logged in to Twitter.
Now, the correct URL template appears to be
https://twitter.com/:user_id/status/:id
where `:user_id` is not strict, and may be any word (\w+) <= 20 chars.
Try it yourself:
$ curl https://twitter.com/elonmusk/status/1069382411899817990
<html><body>You are being <a href="https://twitter.com/medenhofer/status/1069382411899817990">redirected</a>.</body></html>
In this commit, we replace `:user_id` with a single underscore (`_`).
This behavior is not officially documented anywhere (as far as I know),
but it works (for now).
This commit also extends the previous commit's DB migration/bg job
to rectify existing, broken tweet URLs stored in the database.
For performance purposes, this migration is performed in the background
and limited to the latest 10,000 Twitter articles.
[0]: https://stackoverflow.com/questions/41786123
GitHub: https://github.com/zammad/zammad/issues/2715
2019-11-14 06:03:34 +00:00
|
|
|
# NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
|
2021-07-01 11:23:52 +00:00
|
|
|
links: [{ url: "https://twitter.com/statuses/#{Faker::Number.number(digits: 20)}" }],
|
2019-11-07 10:01:58 +00:00
|
|
|
twitter: {
|
|
|
|
recipient_id: recipient_id,
|
|
|
|
sender_id: sender_id,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:recipient_id) { '1234567890' }
|
|
|
|
let(:sender_id) { '0987654321' }
|
|
|
|
|
Fixes #2715 - Twitter status URLs are broken
This commit is a complement of its parent:
the parent fixes broken links to Twitter DMs,
while this one fixes broken links to Twitter statuses.
When importing tweets (articles of type "twitter status"),
Zammad generates a source link URL using the following format:
https://twitter.com/statuses/:id
and then stores that URL under `article.preferences[:links]`.
This URL template worked until as recently as 2017[0],
but currently fails for users actively logged in to Twitter.
Now, the correct URL template appears to be
https://twitter.com/:user_id/status/:id
where `:user_id` is not strict, and may be any word (\w+) <= 20 chars.
Try it yourself:
$ curl https://twitter.com/elonmusk/status/1069382411899817990
<html><body>You are being <a href="https://twitter.com/medenhofer/status/1069382411899817990">redirected</a>.</body></html>
In this commit, we replace `:user_id` with a single underscore (`_`).
This behavior is not officially documented anywhere (as far as I know),
but it works (for now).
This commit also extends the previous commit's DB migration/bg job
to rectify existing, broken tweet URLs stored in the database.
For performance purposes, this migration is performed in the background
and limited to the latest 10,000 Twitter articles.
[0]: https://stackoverflow.com/questions/41786123
GitHub: https://github.com/zammad/zammad/issues/2715
2019-11-14 06:03:34 +00:00
|
|
|
it 'reformats all Twitter status URLs' do
|
|
|
|
expect { described_class.perform_now }
|
|
|
|
.to change { urls_of(tweet) }
|
|
|
|
.to all(match(%r{^https://twitter.com/_/status/#{tweet.message_id}$}))
|
|
|
|
end
|
|
|
|
|
2019-11-07 10:01:58 +00:00
|
|
|
it 'reformats all Twitter DM URLs' do
|
|
|
|
expect { described_class.perform_now }
|
|
|
|
.to change { urls_of(dm) }
|
|
|
|
.to all(match(%r{^https://twitter.com/messages/#{recipient_id}-#{sender_id}$}))
|
|
|
|
end
|
|
|
|
|
|
|
|
def urls_of(article)
|
2020-09-30 09:07:01 +00:00
|
|
|
article.reload.preferences[:links].pluck(:url)
|
2019-11-07 10:01:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|