Skip to content

Commit

Permalink
OCM-12442 | feat: Added github hostname validation
Browse files Browse the repository at this point in the history
  • Loading branch information
den-rgb committed Nov 28, 2024
1 parent 12ddbbc commit 73d3d43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 0 additions & 10 deletions provider/identityprovider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package identityprovider
import (
"context"
"fmt"
"net/url"
"strings"

"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
Expand Down Expand Up @@ -91,9 +90,6 @@ func githubHostnameValidator() validator.String {
// Validate hostname
if !hostname.IsUnknown() && !hostname.IsNull() && len(hostname.ValueString()) > 0 {
hostnameStr := hostname.ValueString()
if hostnameStr == "" {
return
}
if hostnameStr == "github.com" || strings.HasSuffix(hostnameStr, ".github.com") {
resp.Diagnostics.AddAttributeError(req.Path, "invalid hostname",
fmt.Sprintf("'%s' hostname cannot be equal to [*.]github.com", hostnameStr),
Expand All @@ -106,12 +102,6 @@ func githubHostnameValidator() validator.String {
)
return
}
_, err := url.ParseRequestURI(hostnameStr)
if err != nil {
resp.Diagnostics.AddAttributeError(req.Path, "invalid hostname",
fmt.Sprintf("Expected a valid GitHub hostname. Got %v", hostnameStr),
)
}
}
})
}
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/idps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
}
}

validateIDPArgAgainstNoError := func(svc exec.IDPService, idpArgs *exec.IDPArgs) {
_, err := svc.Apply(idpArgs)
Expect(err).ToNot(HaveOccurred())
}

It("the mandatory idp's attributes must be set - [id:68939]", ci.Medium, func() {
var err error
idpServices.htpasswd, err = profileHandler.Services().GetIDPService(constants.IDPHTPassword)
Expand Down Expand Up @@ -695,6 +700,16 @@ var _ = Describe("Identity Providers", ci.Day2, ci.FeatureIDP, func() {
args.HostedDomain = helper.StringPointer(" invalid hostname ")
validateIDPArgAgainstErrorSubstrings(idpServices.github, args, "hostname must be a valid DNS subdomain or IP address")

By("Create github idp with hostname myhost.com/aa")
args = getDefaultGitHubArgs(idpName)
args.HostedDomain = helper.StringPointer("myhost.com/aa")
validateIDPArgAgainstNoError(idpServices.github, args)

By("Create github idp with hostname example.com")
args = getDefaultGitHubArgs(idpName)
args.HostedDomain = helper.StringPointer("example.com")
validateIDPArgAgainstNoError(idpServices.github, args)

By("Create github idp with empty hostname")
args = getDefaultGitHubArgs(idpName)
args.HostedDomain = helper.EmptyStringPointer
Expand Down

0 comments on commit 73d3d43

Please sign in to comment.