Pass normalized URI to OpenGraphReader
This ensures the hostname is downcase and thus subsequent third party library assumptions hold, namely http-cookie (pulled through faraday-cookie_jar) doesn't raise closes #8021
This commit is contained in:
parent
4a22f08539
commit
1227f34b2a
3 changed files with 23 additions and 3 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
## Refactor
|
## Refactor
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
* Improve handling of mixed case hostnames while fetching OpenGraph data [#8021](https://github.com/diaspora/diaspora/pull/8021)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Add line mentioning diaspora\* on the splash page [#7966](https://github.com/diaspora/diaspora/pull/7966)
|
* Add line mentioning diaspora\* on the splash page [#7966](https://github.com/diaspora/diaspora/pull/7966)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ class OpenGraphCache < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_and_save_opengraph_data!
|
def fetch_and_save_opengraph_data!
|
||||||
object = OpenGraphReader.fetch!(self.url)
|
uri = URI.parse(url.start_with?("http") ? url : "http://#{url}")
|
||||||
|
uri.normalize!
|
||||||
|
object = OpenGraphReader.fetch!(uri)
|
||||||
|
|
||||||
return unless object
|
return unless object
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ describe OpenGraphCache, type: :model do
|
||||||
describe "fetch_and_save_opengraph_data!" do
|
describe "fetch_and_save_opengraph_data!" do
|
||||||
context "with an unsecure video url" do
|
context "with an unsecure video url" do
|
||||||
it "doesn't save the video url" do
|
it "doesn't save the video url" do
|
||||||
expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return(
|
expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return(
|
||||||
double(
|
double(
|
||||||
og: double(
|
og: double(
|
||||||
description: "This is the article lead",
|
description: "This is the article lead",
|
||||||
|
|
@ -34,7 +34,7 @@ describe OpenGraphCache, type: :model do
|
||||||
|
|
||||||
context "with a secure video url" do
|
context "with a secure video url" do
|
||||||
it "saves the video url" do
|
it "saves the video url" do
|
||||||
expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return(
|
expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return(
|
||||||
double(
|
double(
|
||||||
og: double(
|
og: double(
|
||||||
description: "This is the article lead",
|
description: "This is the article lead",
|
||||||
|
|
@ -57,5 +57,22 @@ describe OpenGraphCache, type: :model do
|
||||||
expect(ogc.video_url).to eq("https://bandcamp.com/EmbeddedPlayer/v=2/track=12/size=small")
|
expect(ogc.video_url).to eq("https://bandcamp.com/EmbeddedPlayer/v=2/track=12/size=small")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "a mixed case hostname" do
|
||||||
|
it "downcases the hostname" do
|
||||||
|
stub_request(:head, "http:///wetter.com")
|
||||||
|
.with(headers: {
|
||||||
|
"Accept" => "text/html",
|
||||||
|
"User-Agent" => "OpenGraphReader/0.6.2 (+https://github.com/jhass/open_graph_reader)"
|
||||||
|
})
|
||||||
|
.to_return(status: 200, body: "", headers:
|
||||||
|
{"Set-Cookie" => "Dabgroup=A;path=/;Expires=Thu, 23 May 2019 16:12:01 GMT;httpOnly"})
|
||||||
|
|
||||||
|
ogc = OpenGraphCache.new(url: "Wetter.com")
|
||||||
|
expect {
|
||||||
|
ogc.fetch_and_save_opengraph_data!
|
||||||
|
}.to_not raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue