Codebase list ruby-cms-scanner / 105ecbd
New upstream version 0.8.1 Sophie Brun 4 years ago
7 changed file(s) with 61 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
0 name: Ruby Gem
1
2 on:
3 release:
4 types: [published]
5
6 jobs:
7 build:
8 name: Build + Publish
9 runs-on: ubuntu-latest
10
11 steps:
12 - uses: actions/checkout@master
13 - name: Set up Ruby 2.6
14 uses: actions/setup-ruby@v1
15 with:
16 ruby-version: 2.6.x
17
18 #- name: Publish to GPR
19 # run: |
20 # mkdir -p $HOME/.gem
21 # touch $HOME/.gem/credentials
22 # chmod 0600 $HOME/.gem/credentials
23 # printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
24 # gem build *.gemspec
25 # gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
26 # env:
27 # GEM_HOST_API_KEY: ${{secrets.GITHUB_TOKEN}}
28 # OWNER: wpscanteam
29
30 - name: Publish to RubyGems
31 run: |
32 mkdir -p $HOME/.gem
33 touch $HOME/.gem/credentials
34 chmod 0600 $HOME/.gem/credentials
35 printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
36 gem build *.gemspec
37 gem push *.gem
38 env:
39 GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
44 - '*.gemspec'
55 - 'vendor/**/*'
66 - 'example/**/*'
7 Layout/LineLength:
8 Max: 120
79 Lint/UriEscapeUnescape:
810 Enabled: false
911 Metrics/AbcSize:
1315 - 'spec/**/*'
1416 Metrics/CyclomaticComplexity:
1517 Max: 10
16 Metrics/LineLength:
17 Max: 120
1818 Metrics/MethodLength:
1919 Max: 18
2020 Exclude:
2424 - 2.6.3
2525 - 2.6.4
2626 - 2.6.5
27 before_install:
28 - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
29 - gem update --system
27 - 2.7.0
3028 script:
3129 - bundle exec rubocop
3230 - bundle exec rspec
3434 s.add_development_dependency 'rake', '~> 13.0'
3535 s.add_development_dependency 'rspec', '~> 3.9.0'
3636 s.add_development_dependency 'rspec-its', '~> 1.3.0'
37 s.add_development_dependency 'rubocop', '~> 0.76.0'
37 s.add_development_dependency 'rubocop', '~> 0.78.0'
3838 s.add_development_dependency 'rubocop-performance', '~> 1.5.0'
3939 s.add_development_dependency 'simplecov', '~> 0.16.1'
4040 s.add_development_dependency 'webmock', '~> 3.7.0'
11
22 # Version
33 module CMSScanner
4 VERSION = '0.7.1'
4 VERSION = '0.8.1'
55 end
2222 @uri = Addressable::URI.parse(site_url).normalize
2323 end
2424
25 # Used for convenience
26 #
27 # URI.encode is preferered over Addressable::URI.encode as it will encode
28 # leading # character:
29 # URI.encode('#t#') => %23t%23
30 # Addressable::URI.encode('#t#') => #t%23
31 #
3225 # @param [ String ] path Optional path to merge with the uri
3326 #
3427 # @return [ String ]
3528 def url(path = nil)
3629 return @uri.to_s unless path
3730
38 @uri.join(URI.encode(path)).to_s
31 @uri.join(Addressable::URI.encode(path).gsub('#', '%23')).to_s
3932 end
4033
4134 attr_writer :homepage_res
6154
6255 # @return [ String ] The URL of an unlikely existant page
6356 def error_404_url
64 @error_404_url ||= non_existant_page_url
65 end
66
67 # @return [ String ] The URL of an unlikely existant page
68 # TODO: This will be removed in the next major version (0.7)
69 def non_existant_page_url
70 uri.join(Digest::MD5.hexdigest(rand(999_999).to_s)[0..6] + '.html').to_s
57 @error_404_url ||= uri.join(Digest::MD5.hexdigest(rand(999_999).to_s)[0..6] + '.html').to_s
7158 end
7259
7360 # Checks if the remote website is up.
11198
11299 return unless [301, 302].include?(NS::Browser.get(url).code)
113100
114 res = NS::Browser.get(url, followlocation: true)
101 res = NS::Browser.get(url, followlocation: true, maxredirs: 10)
115102
116103 res.effective_url == url ? nil : res.effective_url
117104 end
171171 stub_request(:get, target_urls.key(2)).to_return(status: 200, body: 'rspec')
172172 end
173173
174 it 'yield the expected items' do
174 it 'yield the expected item' do
175175 expect { |b| finder.enumerate(target_urls, opts, &b) }.to yield_with_args(Typhoeus::Response, 2)
176176 end
177177 end
204204 expect { |b| finder.enumerate(target_urls, opts, &b) }.to yield_successive_args(
205205 [Typhoeus::Response, 1], [Typhoeus::Response, 2]
206206 )
207 end
208 end
209
210 context 'when one header matches but the other not, using negative look-arounds' do
211 let(:opts) { super().merge(exclude_content: /\A((?!x\-cacheable)[\s\S])*\z/i) }
212
213 before do
214 stub_request(:head, target_urls.keys.last).and_return(status: 200, headers: { 'x-cacheable' => 'YES' })
215 end
216
217 it 'yield the expected item' do
218 expect { |b| finder.enumerate(target_urls, opts, &b) }.to yield_with_args(Typhoeus::Response, 2)
207219 end
208220 end
209221 end