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:
parent
27e578e7fb
commit
666164c369
|
@ -32,6 +32,13 @@ var (
|
||||||
moduleSourceRe = regexp.MustCompile(
|
moduleSourceRe = regexp.MustCompile(
|
||||||
fmt.Sprintf("^(%s)\\/(%s)\\/(%s)(?:\\/\\/(.*))?$",
|
fmt.Sprintf("^(%s)\\/(%s)\\/(%s)(?:\\/\\/(.*))?$",
|
||||||
nameSubRe, nameSubRe, providerSubRe))
|
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.
|
// Module describes a Terraform Registry Module source.
|
||||||
|
@ -77,8 +84,10 @@ func NewModule(host, namespace, name, provider, submodule string) *Module {
|
||||||
func ParseModuleSource(source string) (*Module, error) {
|
func ParseModuleSource(source string) (*Module, error) {
|
||||||
// See if there is a friendly host prefix.
|
// See if there is a friendly host prefix.
|
||||||
host, rest := ParseFriendlyHost(source)
|
host, rest := ParseFriendlyHost(source)
|
||||||
if host != nil && !host.Valid() {
|
if host != nil {
|
||||||
return nil, ErrInvalidModuleSource
|
if !host.Valid() || disallowed[host.Display()] {
|
||||||
|
return nil, ErrInvalidModuleSource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := moduleSourceRe.FindStringSubmatch(rest)
|
matches := moduleSourceRe.FindStringSubmatch(rest)
|
||||||
|
|
|
@ -96,6 +96,16 @@ func TestModule(t *testing.T) {
|
||||||
source: "foo.com/var/baz?otherthing",
|
source: "foo.com/var/baz?otherthing",
|
||||||
wantErr: true,
|
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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue