Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tails
tails
Commits
18c79d54
Commit
18c79d54
authored
Jan 19, 2016
by
anonym
Browse files
Validate IP addresses without regex hacks.
parent
ce011a00
Changes
1
Hide whitespace changes
Inline
Side-by-side
features/step_definitions/ssh.rb
View file @
18c79d54
require
'socket'
def
assert_not_ipaddr
(
s
)
err_msg
=
"
#{
@ssh_host
}
looks like a LAN IP address."
assert_raise
(
IPAddr
::
InvalidAddressError
,
err_msg
)
do
IPAddr
.
new
(
s
)
end
end
def
read_and_validate_ssh_config
srv_type
conf
=
$config
[
srv_type
]
begin
...
...
@@ -22,16 +29,12 @@ EOF
@ssh_host
=
conf
[
"hostname"
]
@ssh_port
=
conf
[
"port"
].
to_i
if
conf
[
"port"
]
@ssh_username
=
conf
[
"username"
]
assert
(
!
@ssh_host
.
match
(
/^(10|192\.168|172\.(1[6-9]|2[0-9]|3[01]))/
),
"
#{
@ssh_host
}
"
+
"looks like a LAN IP address."
)
assert_not_ipaddr
(
@ssh_host
)
when
'SFTP'
@sftp_host
=
conf
[
"hostname"
]
@sftp_port
=
conf
[
"port"
].
to_i
if
conf
[
"port"
]
@sftp_username
=
conf
[
"username"
]
assert
(
!
@sftp_host
.
match
(
/^(10|192\.168|172\.(1[6-9]|2[0-9]|3[01]))/
),
"
#{
@sftp_host
}
"
+
"looks like a LAN IP address."
)
assert_not_ipaddr
(
@sftp_host
)
end
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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