Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: Gil Desmarais <git@desmarais.de>
  • Loading branch information
gildesmarais committed Dec 23, 2024
1 parent edd5bd0 commit 63f8f21
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 125 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
cache-version: 1

- run: bundle exec rspec

Expand Down
2 changes: 2 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def self.development? = ENV['RACK_ENV'] == 'development'
require_relative f
end
end
@show_backtrace = !ENV['CI'].empty? || self.class.development?


route do |r|
r.public
Expand Down
2 changes: 1 addition & 1 deletion routes/auto_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class App
end

r.on String, method: :get do |encoded_url|
strategy = request.params.fetch('strategy', :ssrf_filter).to_sym
strategy = request.params['strategy']&.to_sym || :ssrf_filter
unless Html2rss::RequestService.strategy_registered?(strategy)
raise Html2rss::RequestService::UnknownStrategy
end
Expand Down
31 changes: 16 additions & 15 deletions spec/fixtures/vcr_cassettes/auto_source-github-h2r-web.yml

Large diffs are not rendered by default.

103 changes: 0 additions & 103 deletions spec/fixtures/vcr_cassettes/auto_source-h2r-web.yml

This file was deleted.

18 changes: 12 additions & 6 deletions spec/routes/auto_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def app = described_class
let(:request_headers) do
{ 'HTTP_HOST' => 'localhost' }
end
let(:encoded_url) { Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web/commits/master') }

let(:username) { 'username' }
let(:password) { 'password' }
Expand Down Expand Up @@ -66,14 +67,17 @@ def app = described_class
describe "GET '/auto_source/:encoded_url'" do
context 'with provided basic auth' do
subject(:response) do
VCR.use_cassette 'auto_source-h2r-web' do
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}",
VCR.use_cassette('auto_source-github-h2r-web', match_requests_on: [:path]) do
get "/auto_source/#{encoded_url}?strategy",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
end
end

it 'responds successfully', :aggregate_failures do
puts '*' * 80
puts response.body
puts '*' * 80
expect(response).to be_ok
expect(response.body).to start_with '<?xml version="1.0" encoding="UTF-8"?>'
expect(response.get_header('cache-control')).to eq 'must-revalidate, private, max-age=0'
Expand All @@ -83,9 +87,11 @@ def app = described_class

context 'when strategy is not registered' do
subject(:response) do
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}?strategy=nope",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
VCR.use_cassette('auto_source-github-h2r-web', match_requests_on: [:path]) do
get "/auto_source/#{encoded_url}?strategy=nope",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))
end
end

it 'responds with Error', :aggregate_failures do
Expand All @@ -111,7 +117,7 @@ def app = described_class

describe "GET '/auto_source/:encoded_url'" do
it 'responds with 400 Bad Request', :aggregate_failures do
get "/auto_source/#{Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web')}",
get "/auto_source/#{encoded_url}",
{},
request_headers.merge('HTTP_AUTHORIZATION' => basic_authorize(username, password))

Expand Down

0 comments on commit 63f8f21

Please sign in to comment.