Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
304afee3
Commit
304afee3
authored
Mar 13, 2020
by
rpereira2
Committed by
Ryan Cobb
Mar 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for domain and ip_whitelist_entry
- Also fix other minor review suggestions.
parent
2edc570d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
6 deletions
+140
-6
lib/gitlab/url_blockers/domain_whitelist_entry.rb
lib/gitlab/url_blockers/domain_whitelist_entry.rb
+3
-3
lib/gitlab/url_blockers/ip_whitelist_entry.rb
lib/gitlab/url_blockers/ip_whitelist_entry.rb
+4
-3
spec/lib/gitlab/url_blockers/domain_whitelist_entry_spec.rb
spec/lib/gitlab/url_blockers/domain_whitelist_entry_spec.rb
+58
-0
spec/lib/gitlab/url_blockers/ip_whitelist_entry_spec.rb
spec/lib/gitlab/url_blockers/ip_whitelist_entry_spec.rb
+75
-0
No files found.
lib/gitlab/url_blockers/domain_whitelist_entry.rb
View file @
304afee3
...
...
@@ -11,10 +11,10 @@ module Gitlab
end
def
match?
(
requested_domain
,
requested_port
=
nil
)
return
false
unless
@
domain
==
requested_domain
return
true
if
@
port
.
nil?
return
false
unless
domain
==
requested_domain
return
true
if
port
.
nil?
@port
==
requested_port
.
to_i
port
==
requested_port
end
end
end
...
...
lib/gitlab/url_blockers/ip_whitelist_entry.rb
View file @
304afee3
...
...
@@ -5,16 +5,17 @@ module Gitlab
class
IpWhitelistEntry
attr_reader
:ip
,
:port
# Argument ip should be an IPAddr object
def
initialize
(
ip
,
port:
nil
)
@ip
=
ip
@port
=
port
end
def
match?
(
requested_ip
,
requested_port
=
nil
)
return
false
unless
@
ip
.
include?
(
requested_ip
)
return
true
if
@
port
.
nil?
return
false
unless
ip
.
include?
(
requested_ip
)
return
true
if
port
.
nil?
@port
==
requested_port
.
to_i
port
==
requested_port
end
end
end
...
...
spec/lib/gitlab/url_blockers/domain_whitelist_entry_spec.rb
0 → 100644
View file @
304afee3
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
UrlBlockers
::
DomainWhitelistEntry
do
let
(
:domain
)
{
'www.example.com'
}
describe
'#initialize'
do
it
'initializes without port'
do
domain_whitelist_entry
=
described_class
.
new
(
domain
)
expect
(
domain_whitelist_entry
.
domain
).
to
eq
(
domain
)
expect
(
domain_whitelist_entry
.
port
).
to
be
(
nil
)
end
it
'initializes with port'
do
port
=
8080
domain_whitelist_entry
=
described_class
.
new
(
domain
,
port:
port
)
expect
(
domain_whitelist_entry
.
domain
).
to
eq
(
domain
)
expect
(
domain_whitelist_entry
.
port
).
to
eq
(
port
)
end
end
describe
'#match?'
do
it
'matches when domain and port are equal'
do
port
=
8080
domain_whitelist_entry
=
described_class
.
new
(
domain
,
port:
port
)
expect
(
domain_whitelist_entry
).
to
be_match
(
domain
,
port
)
end
it
'matches any port when port is nil'
do
domain_whitelist_entry
=
described_class
.
new
(
domain
)
expect
(
domain_whitelist_entry
).
to
be_match
(
domain
,
8080
)
expect
(
domain_whitelist_entry
).
to
be_match
(
domain
,
9090
)
end
it
'does not match when port is present but requested_port is nil'
do
domain_whitelist_entry
=
described_class
.
new
(
domain
,
port:
8080
)
expect
(
domain_whitelist_entry
).
not_to
be_match
(
domain
,
nil
)
end
it
'matches when port and requested_port are nil'
do
domain_whitelist_entry
=
described_class
.
new
(
domain
)
expect
(
domain_whitelist_entry
).
to
be_match
(
domain
)
end
it
'does not match if domain is not equal'
do
domain_whitelist_entry
=
described_class
.
new
(
domain
)
expect
(
domain_whitelist_entry
).
not_to
be_match
(
'www.gitlab.com'
,
8080
)
end
end
end
spec/lib/gitlab/url_blockers/ip_whitelist_entry_spec.rb
0 → 100644
View file @
304afee3
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
UrlBlockers
::
IpWhitelistEntry
do
let
(
:ipv4
)
{
IPAddr
.
new
(
'192.168.1.1'
)
}
describe
'#initialize'
do
it
'initializes without port'
do
ip_whitelist_entry
=
described_class
.
new
(
ipv4
)
expect
(
ip_whitelist_entry
.
ip
).
to
eq
(
ipv4
)
expect
(
ip_whitelist_entry
.
port
).
to
be
(
nil
)
end
it
'initializes with port'
do
port
=
8080
ip_whitelist_entry
=
described_class
.
new
(
ipv4
,
port:
port
)
expect
(
ip_whitelist_entry
.
ip
).
to
eq
(
ipv4
)
expect
(
ip_whitelist_entry
.
port
).
to
eq
(
port
)
end
end
describe
'#match?'
do
it
'matches with equivalent IP and port'
do
port
=
8080
ip_whitelist_entry
=
described_class
.
new
(
ipv4
,
port:
port
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv4
.
to_s
,
port
)
end
it
'matches any port when port is nil'
do
ip_whitelist_entry
=
described_class
.
new
(
ipv4
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv4
.
to_s
,
8080
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv4
.
to_s
,
9090
)
end
it
'does not match when port is present but requested_port is nil'
do
ip_whitelist_entry
=
described_class
.
new
(
ipv4
,
port:
8080
)
expect
(
ip_whitelist_entry
).
not_to
be_match
(
ipv4
.
to_s
,
nil
)
end
it
'matches when port and requested_port are nil'
do
ip_whitelist_entry
=
described_class
.
new
(
ipv4
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv4
.
to_s
)
end
it
'works with ipv6'
do
ipv6
=
IPAddr
.
new
(
'fe80::c800:eff:fe74:8'
)
ip_whitelist_entry
=
described_class
.
new
(
ipv6
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv6
.
to_s
,
8080
)
end
it
'matches ipv4 within IPv4 range'
do
ipv4_range
=
IPAddr
.
new
(
'127.0.0.0/28'
)
ip_whitelist_entry
=
described_class
.
new
(
ipv4_range
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv4_range
.
to_range
.
last
.
to_s
,
8080
)
expect
(
ip_whitelist_entry
).
not_to
be_match
(
'127.0.1.1'
,
8080
)
end
it
'matches IPv6 within IPv6 range'
do
ipv6_range
=
IPAddr
.
new
(
'fd84:6d02:f6d8:c89e::/124'
)
ip_whitelist_entry
=
described_class
.
new
(
ipv6_range
)
expect
(
ip_whitelist_entry
).
to
be_match
(
ipv6_range
.
to_range
.
last
.
to_s
,
8080
)
expect
(
ip_whitelist_entry
).
not_to
be_match
(
'fd84:6d02:f6d8:f::f'
,
8080
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment