discourse/spec/lib/onebox/engine/github_issue_onebox_spec.rb
Martin Brennan 97e2b353f6
FEATURE: Allow for multiple GitHub onebox tokens (#27887)
Followup 560e8aff75

GitHub auth tokens cannot be made with permissions to
access multiple organisations. This is quite limiting.
This commit changes the site setting to be a "secret list"
type, which allows for a key/value mapping where the value
is treated like a password in the UI.

Now when a GitHub URL is requested for oneboxing, the
org name from the URL is used to determine which token
to use for the request.

Just in case anyone used the old site setting already,
there is a migration to create a `default` entry
with that token in the new list setting, and for
a period of time we will consider that token valid to
use for all GitHub oneboxes as well.
2024-07-15 13:07:36 +10:00

40 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Onebox::Engine::GithubIssueOnebox do
let(:issue_uri) { "https://api.github.com/repos/discourse/discourse/issues/1" }
before do
stub_request(:get, issue_uri).to_return(
status: 200,
body: onebox_response("github_issue_onebox"),
)
end
include_context "with engines" do
let(:link) { "https://github.com/discourse/discourse/issues/1" }
end
it_behaves_like "an engine"
describe "#to_html" do
it "sanitizes the input and transform the emoji into an img tag" do
sanitized_label =
'Test <img src="/images/emoji/twitter/+1.png?v=12" title="+1" class="emoji" alt="+1" loading="lazy" width="20" height="20">'
expect(html).to include(sanitized_label)
end
context "when github_onebox_access_token is configured" do
before { SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234" }
it "sends it as part of the request" do
html
expect(WebMock).to have_requested(:get, issue_uri).with(
headers: {
"Authorization" => "Bearer github_pat_1234",
},
)
end
end
end
end