Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e39965e3
Commit
e39965e3
authored
Jun 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: validate iso_url more strictly
parent
c98c16a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
3 deletions
+47
-3
builder/vmware/builder.go
builder/vmware/builder.go
+32
-0
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+15
-3
No files found.
builder/vmware/builder.go
View file @
e39965e3
...
...
@@ -8,8 +8,10 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"math/rand"
"net/url"
"os"
"path/filepath"
"strings"
"time"
)
...
...
@@ -93,6 +95,36 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
if
b
.
config
.
ISOUrl
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An iso_url must be specified."
))
}
else
{
url
,
err
:=
url
.
Parse
(
b
.
config
.
ISOUrl
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"iso_url is not a valid URL: %s"
,
err
))
}
else
{
if
url
.
Scheme
==
""
{
url
.
Scheme
=
"file"
}
if
url
.
Scheme
==
"file"
{
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
ISOUrl
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"iso_url points to bad file: %s"
,
err
))
}
}
else
{
supportedSchemes
:=
[]
string
{
"file"
,
"http"
,
"https"
}
scheme
:=
strings
.
ToLower
(
url
.
Scheme
)
found
:=
false
for
_
,
supported
:=
range
supportedSchemes
{
if
scheme
==
supported
{
found
=
true
break
}
}
if
!
found
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unsupported URL scheme in iso_url: %s"
,
scheme
))
}
}
}
}
if
b
.
config
.
SSHUser
==
""
{
...
...
builder/vmware/builder_test.go
View file @
e39965e3
...
...
@@ -8,7 +8,7 @@ import (
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"iso_url"
:
"
fo
o"
,
"iso_url"
:
"
http://www.packer.i
o"
,
"ssh_username"
:
"foo"
,
}
}
...
...
@@ -104,10 +104,22 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
t
.
Fatal
(
"should have error"
)
}
config
[
"iso_url"
]
=
"exists"
config
[
"iso_url"
]
=
"i/am/a/file/that/doesnt/exist"
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Error
(
"should have error"
)
}
config
[
"iso_url"
]
=
"file:i/am/a/file/that/doesnt/exist"
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Error
(
"should have error"
)
}
config
[
"iso_url"
]
=
"http://www.packer.io"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatal
f
(
"should not have error: %s"
,
err
)
t
.
Error
f
(
"should not have error: %s"
,
err
)
}
}
...
...
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