From eb49e277245d011abd94a2099b93373f99337c87 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Wed, 29 Oct 2025 19:40:26 +0100 Subject: [PATCH] Simplify saml validation Signed-off-by: Bryan Frimin --- pkg/auth/saml_config_validator.go | 56 +++++++------------------------ 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/pkg/auth/saml_config_validator.go b/pkg/auth/saml_config_validator.go index 540a1536f..efdaa8475 100644 --- a/pkg/auth/saml_config_validator.go +++ b/pkg/auth/saml_config_validator.go @@ -23,15 +23,6 @@ import ( pemutil "github.com/getprobo/probo/pkg/crypto/pem" ) -type ValidationError struct { - Field string - Message string -} - -func (e ValidationError) Error() string { - return fmt.Sprintf("%s: %s", e.Field, e.Message) -} - // ValidateIdPConfiguration validates only the IdP (Identity Provider) configuration. // This validates user-provided data from the IdP. // SP (Service Provider) configuration is generated by the application and doesn't need validation. @@ -39,68 +30,45 @@ func ValidateIdPConfiguration( idpEntityID string, idpSsoURL string, idpCertificate string, -) []ValidationError { - var errors []ValidationError - +) error { // Validate IdP Entity ID if idpEntityID == "" { - errors = append(errors, ValidationError{ - Field: "idp_entity_id", - Message: "IdP Entity ID cannot be empty", - }) + return fmt.Errorf("IdP Entity ID cannot be empty") } // Validate IdP SSO URL - accept both HTTP and HTTPS - if err := validateURL(idpSsoURL, "idp_sso_url"); err != nil { - errors = append(errors, *err) + if err := validateURL(idpSsoURL); err != nil { + return err } // Validate IdP certificate if err := validateCertificate(idpCertificate); err != nil { - errors = append(errors, ValidationError{ - Field: "idp_certificate", - Message: err.Error(), - }) + return err } - return errors + return nil } -func validateURL(urlStr string, fieldName string) *ValidationError { +func validateURL(urlStr string) error { if urlStr == "" { - return &ValidationError{ - Field: fieldName, - Message: "URL cannot be empty", - } + return fmt.Errorf("URL cannot be empty") } parsedURL, err := url.Parse(urlStr) if err != nil { - return &ValidationError{ - Field: fieldName, - Message: fmt.Sprintf("invalid URL format: %v", err), - } + return fmt.Errorf("invalid URL format: %w", err) } if parsedURL.Scheme == "" { - return &ValidationError{ - Field: fieldName, - Message: "URL must have a scheme (http or https)", - } + return fmt.Errorf("URL must have a scheme (http or https)") } if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" { - return &ValidationError{ - Field: fieldName, - Message: "URL scheme must be http or https (found: " + parsedURL.Scheme + ")", - } + return fmt.Errorf("URL scheme must be http or https (found: %s)", parsedURL.Scheme) } if parsedURL.Host == "" { - return &ValidationError{ - Field: fieldName, - Message: "URL must have a host", - } + return fmt.Errorf("URL must have a host") } return nil