disallow github and bitbucket hosts

These hosts have special usage in module source strings, and can't be
valid registry hosts.
This commit is contained in:
James Bardin 2017-10-24 19:27:36 -04:00
parent 27e578e7fb
commit 666164c369
2 changed files with 21 additions and 2 deletions

View File

@ -32,6 +32,13 @@ var (
moduleSourceRe = regexp.MustCompile(
fmt.Sprintf("^(%s)\\/(%s)\\/(%s)(?:\\/\\/(.*))?$",
nameSubRe, nameSubRe, providerSubRe))
// disallowed is a set of hostnames that have special usage in modules and
// can't be registry hosts
disallowed = map[string]bool{
"github.com": true,
"bitbucket.org": true,
}
)
// Module describes a Terraform Registry Module source.
@ -77,9 +84,11 @@ func NewModule(host, namespace, name, provider, submodule string) *Module {
func ParseModuleSource(source string) (*Module, error) {
// See if there is a friendly host prefix.
host, rest := ParseFriendlyHost(source)
if host != nil && !host.Valid() {
if host != nil {
if !host.Valid() || disallowed[host.Display()] {
return nil, ErrInvalidModuleSource
}
}
matches := moduleSourceRe.FindStringSubmatch(rest)
if len(matches) < 4 {

View File

@ -96,6 +96,16 @@ func TestModule(t *testing.T) {
source: "foo.com/var/baz?otherthing",
wantErr: true,
},
{
name: "disallow github",
source: "github.com/HashiCorp/Consul/aws",
wantErr: true,
},
{
name: "disallow bitbucket",
source: "bitbucket.org/HashiCorp/Consul/aws",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {