summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/reports/security/scanned_resource_spec.rb
blob: 74a5344f79efb89f83ba587f2743541e0e842459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Reports::Security::ScannedResource do
  let(:url) { 'http://example.com:3001/1?foo=bar' }
  let(:request_method) { 'GET' }

  context 'when the URI is not a URI' do
    subject { ::Gitlab::Ci::Reports::Security::ScannedResource.new(url, request_method) }

    it 'raises an error' do
      expect { subject }.to raise_error(ArgumentError)
    end
  end

  context 'when the URL is valid' do
    subject { ::Gitlab::Ci::Reports::Security::ScannedResource.new(URI.parse(url), request_method) }

    it 'sets the URL attributes' do
      expect(subject.request_method).to eq(request_method)
      expect(subject.request_uri.to_s).to eq(url)
      expect(subject.url_scheme).to eq('http')
      expect(subject.url_host).to eq('example.com')
      expect(subject.url_port).to eq(3001)
      expect(subject.url_path).to eq('/1')
      expect(subject.url_query).to eq('foo=bar')
    end
  end
end