Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Preserve advanced SSO settings across ordinary provider edits

pulse-triage[bot]bde6a7f550e3
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 884069535c..a65573eede 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -4962,7 +4962,18 @@ the authoritative analysis outcome.
payload must round-trip through `PUT /api/security/sso/providers/{id}`
without clearing existing OIDC redirect, logout, scopes, restrictions,
role mappings, or stored secret markers unless the update explicitly
- replaces them.
+ replaces them. Same-type edits also retain omitted advanced nested settings
+ that the detail/editor cannot represent: OIDC claim names/CA bundle and SAML
+ signing material, trust files, custom paths, attribute/policy and logout
+ settings. Explicit nested empty strings, false values and nulls still clear
+ those fields. No settings or secrets are inherited across protocol changes.
+ Visible fields and restriction clears keep their existing replacement
+ semantics, and blank OIDC secrets keep their existing preserve rule. Never
+ expose signing keys or hidden settings just to round-trip the editor.
+ `TestSSOProviderUnrepresentedFields` covers all omitted persisted fields,
+ aliases, clears and restart readback; `TestContractSSOUnrepresentedSettingsSurviveSignedProviderEdit`
+ verifies that an enabled signed SAML provider remains valid and initializes
+ its real runtime after an ordinary non-secret detail/save cycle.
33. Keep config-archive import reloads fail-closed on the shared API/runtime
boundary. `internal/api/configapi/config_export_import_handlers.go`,
`internal/api/contract_test.go`, and adjacent config/runtime helpers must
diff --git a/internal/api/admin_json.go b/internal/api/admin_json.go
index 2fbc05bd41..bf40ae6ef3 100644
--- a/internal/api/admin_json.go
+++ b/internal/api/admin_json.go
@@ -17,22 +17,32 @@ var errAmbiguousAdminJSON = errors.New("request body must contain one unambiguou
// Callers supply small request structs (no embedded fields or custom decoders).
// Validate before unmarshalling so an invalid request cannot partially apply.
func decodeAdminJSONObject(w http.ResponseWriter, r *http.Request, dst any, limit int64) error {
+ _, err := decodeAdminJSONObjectData(w, r, dst, limit)
+ return err
+}
+
+// decodeAdminJSONObjectData also returns the validated document for callers
+// that must distinguish omitted settings from deliberately supplied zero values.
+func decodeAdminJSONObjectData(w http.ResponseWriter, r *http.Request, dst any, limit int64) ([]byte, error) {
if r.Body == nil {
- return errAmbiguousAdminJSON
+ return nil, errAmbiguousAdminJSON
}
r.Body = http.MaxBytesReader(w, r.Body, limit)
data, err := io.ReadAll(r.Body)
if err != nil {
- return err
+ return nil, err
}
data = bytes.TrimSpace(data)
if len(data) == 0 || data[0] != '{' || !json.Valid(data) {
- return errAmbiguousAdminJSON
+ return nil, errAmbiguousAdminJSON
}
if err := validateAdminJSONMembers(data, reflect.TypeOf(dst)); err != nil {
- return err
+ return nil, err
+ }
+ if err := json.Unmarshal(data, dst); err != nil {
+ return nil, err
}
- return json.Unmarshal(data, dst)
+ return data, nil
}
func validateAdminJSONMembers(data []byte, target reflect.Type) error {
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index a964421d36..a0d501ddf0 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -28350,3 +28350,50 @@ func TestContractSSOOIDCIssuerConsumer(t *testing.T) {
}
t.Logf("OIDC_CONSUMER_FRAMES %s", encoded)
}
+
+// An ordinary editor save must not remove signing material the detail DTO
+// deliberately keeps private, or discard custom paths consumed by SAML runtime.
+func TestContractSSOUnrepresentedSettingsSurviveSignedProviderEdit(t *testing.T) {
+ router, _ := setupTestRouter(t)
+ cert, key, _ := generateTestCert(t)
+ provider := config.SSOProvider{ID: "signed-provider", Name: "Signed provider", Type: config.SSOProviderTypeSAML, Enabled: true,
+ SAML: &config.SAMLProviderConfig{IDPSSOURL: "https://idp.example.test/sso", IDPEntityID: "https://idp.example.test", IDPCertificate: string(cert),
+ SignRequests: true, SPCertificate: string(cert), SPPrivateKey: string(key), SPACSPath: "/custom/acs", SPMetadataPath: "/custom/metadata", ForceAuthn: true, WantAssertionsSigned: true}}
+ if err := router.ssoConfig.AddProvider(provider); err != nil {
+ t.Fatal(err)
+ }
+ if err := router.saveSSOConfig(); err != nil {
+ t.Fatal(err)
+ }
+ detail := httptest.NewRecorder()
+ router.handleGetSSOProvider(detail, httptest.NewRequest(http.MethodGet, "/", nil), provider.ID)
+ if detail.Code != http.StatusOK || strings.Contains(detail.Body.String(), "PRIVATE KEY") {
+ t.Fatal("detail did not preserve the non-secret contract")
+ }
+ update := httptest.NewRecorder()
+ router.handleSSOProvider(update, httptest.NewRequest(http.MethodPut, "/api/security/sso/providers/"+provider.ID, bytes.NewReader(detail.Body.Bytes())))
+ if update.Code != http.StatusOK {
+ t.Fatalf("signed-provider edit failed: %s", update.Body.String())
+ }
+ if strings.Contains(update.Body.String(), "PRIVATE KEY") {
+ t.Fatal("write response exposed a signing key")
+ }
+ persisted, err := router.persistence.LoadSSOConfig()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := persisted.Validate(); err != nil {
+ t.Fatalf("saved signed provider is invalid: %v", err)
+ }
+ saved := persisted.GetProvider(provider.ID)
+ if saved.SAML.SPPrivateKey != string(key) || saved.SAML.SPCertificate != string(cert) || !saved.SAML.WantAssertionsSigned {
+ t.Fatal("editor discarded signing settings")
+ }
+ service := router.samlManager.GetService(provider.ID)
+ if service == nil {
+ t.Fatal("saved provider could not initialize its real SAML service")
+ }
+ if service.sp.Key == nil || service.sp.AcsURL.Path != "/custom/acs" || service.sp.MetadataURL.Path != "/custom/metadata" || service.sp.ForceAuthn == nil || !*service.sp.ForceAuthn {
+ t.Fatal("SAML runtime did not consume retained settings")
+ }
+}
diff --git a/internal/api/identity_sso_handlers.go b/internal/api/identity_sso_handlers.go
index 2fb4d22967..5e323dcf15 100644
--- a/internal/api/identity_sso_handlers.go
+++ b/internal/api/identity_sso_handlers.go
@@ -473,7 +473,8 @@ func (r *Router) handleUpdateSSOProvider(w http.ResponseWriter, req *http.Reques
}
var updated config.SSOProvider
- if err := decodeAdminJSONObject(w, req, &updated, maxRequestBodySize); err != nil {
+ data, err := decodeAdminJSONObjectData(w, req, &updated, maxRequestBodySize)
+ if err != nil {
writeErrorResponse(w, http.StatusBadRequest, "invalid_json", "Invalid JSON payload", nil)
return
}
@@ -524,12 +525,19 @@ func (r *Router) handleUpdateSSOProvider(w http.ResponseWriter, req *http.Reques
return
}
+ // Preserve fields the editor cannot represent, without turning explicit
+ // empty strings/false values into keeps or inheriting across provider types.
+ if err := preserveUnrepresentedSSOFields(data, &updated, existing); err != nil {
+ writeErrorResponse(w, http.StatusBadRequest, "invalid_json", "Invalid JSON payload", nil)
+ return
+ }
+
// Preserve existing config when not provided in update (e.g., toggle enabled/disabled
// sends the flat list response format, which doesn't include nested OIDC/SAML objects)
- if updated.Type == config.SSOProviderTypeOIDC && updated.OIDC == nil && existing.OIDC != nil {
+ if updated.Type == existing.Type && updated.Type == config.SSOProviderTypeOIDC && updated.OIDC == nil && existing.OIDC != nil {
updated.OIDC = existing.OIDC
}
- if updated.Type == config.SSOProviderTypeSAML && updated.SAML == nil && existing.SAML != nil {
+ if updated.Type == existing.Type && updated.Type == config.SSOProviderTypeSAML && updated.SAML == nil && existing.SAML != nil {
updated.SAML = existing.SAML
}
// groupsClaim, groupRoleMappings, allowedGroups, allowedDomains and
@@ -538,7 +546,7 @@ func (r *Router) handleUpdateSSOProvider(w http.ResponseWriter, req *http.Reques
// intentional clear.
// Preserve secrets if not provided in update
- if updated.Type == config.SSOProviderTypeOIDC && updated.OIDC != nil && existing.OIDC != nil {
+ if updated.Type == existing.Type && updated.Type == config.SSOProviderTypeOIDC && updated.OIDC != nil && existing.OIDC != nil {
existingHasSecret := existing.OIDC.ClientSecretSet || existing.OIDC.ClientSecret != ""
if updated.OIDC.ClientSecret == "" && existingHasSecret {
updated.OIDC.ClientSecret = existing.OIDC.ClientSecret
diff --git a/internal/api/sso_config_preservation.go b/internal/api/sso_config_preservation.go
new file mode 100644
index 0000000000..32453debf3
--- /dev/null
+++ b/internal/api/sso_config_preservation.go
@@ -0,0 +1,99 @@
+package api
+
+import (
+ "encoding/json"
+ "strings"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
+
+// preserveUnrepresentedSSOFields keeps only settings absent from the provider
+// detail/editor model. Visible fields retain PUT replacement/clear semantics;
+// client secrets retain their separate blank-means-keep rule. Never expose
+// advanced settings (in particular signing keys) merely to round-trip an edit.
+func preserveUnrepresentedSSOFields(data []byte, updated, existing *config.SSOProvider) error {
+ if updated.Type != existing.Type {
+ return nil
+ }
+ var fields struct {
+ OIDC map[string]json.RawMessage `json:"oidc"`
+ SAML map[string]json.RawMessage `json:"saml"`
+ }
+ if err := json.Unmarshal(data, &fields); err != nil {
+ return err
+ }
+ // Match encoding/json aliases, including escaped names and Unicode folds.
+ // The admission decoder already rejects competing aliases before this point.
+ present := func(fields map[string]json.RawMessage, name string) bool {
+ for key := range fields {
+ if strings.EqualFold(key, name) {
+ return true
+ }
+ }
+ return false
+ }
+ if updated.Type == config.SSOProviderTypeOIDC && updated.OIDC != nil && existing.OIDC != nil {
+ u, e := updated.OIDC, existing.OIDC
+ if !present(fields.OIDC, "usernameClaim") {
+ u.UsernameClaim = e.UsernameClaim
+ }
+ if !present(fields.OIDC, "emailClaim") {
+ u.EmailClaim = e.EmailClaim
+ }
+ if !present(fields.OIDC, "caBundle") {
+ u.CABundle = e.CABundle
+ }
+ }
+ if updated.Type == config.SSOProviderTypeSAML && updated.SAML != nil && existing.SAML != nil {
+ u, e := updated.SAML, existing.SAML
+ if !present(fields.SAML, "idpSloUrl") {
+ u.IDPSLOURL = e.IDPSLOURL
+ }
+ if !present(fields.SAML, "idpCertFile") {
+ u.IDPCertFile = e.IDPCertFile
+ }
+ if !present(fields.SAML, "idpIssuer") {
+ u.IDPIssuer = e.IDPIssuer
+ }
+ if !present(fields.SAML, "spAcsPath") {
+ u.SPACSPath = e.SPACSPath
+ }
+ if !present(fields.SAML, "spMetadataPath") {
+ u.SPMetadataPath = e.SPMetadataPath
+ }
+ if !present(fields.SAML, "spCertificate") {
+ u.SPCertificate = e.SPCertificate
+ }
+ if !present(fields.SAML, "spPrivateKey") {
+ u.SPPrivateKey = e.SPPrivateKey
+ }
+ if !present(fields.SAML, "spCertFile") {
+ u.SPCertFile = e.SPCertFile
+ }
+ if !present(fields.SAML, "spKeyFile") {
+ u.SPKeyFile = e.SPKeyFile
+ }
+ if !present(fields.SAML, "wantAssertionsSigned") {
+ u.WantAssertionsSigned = e.WantAssertionsSigned
+ }
+ if !present(fields.SAML, "allowUnencrypted") {
+ u.AllowUnencrypted = e.AllowUnencrypted
+ }
+ if !present(fields.SAML, "firstNameAttr") {
+ u.FirstNameAttr = e.FirstNameAttr
+ }
+ if !present(fields.SAML, "lastNameAttr") {
+ u.LastNameAttr = e.LastNameAttr
+ }
+ if !present(fields.SAML, "nameIdFormat") {
+ u.NameIDFormat = e.NameIDFormat
+ }
+ if !present(fields.SAML, "forceAuthn") {
+ u.ForceAuthn = e.ForceAuthn
+ }
+ if !present(fields.SAML, "relayStateTemplate") {
+ u.RelayStateTemplate = e.RelayStateTemplate
+ }
+ }
+ return nil
+}
diff --git a/internal/api/sso_config_preservation_test.go b/internal/api/sso_config_preservation_test.go
new file mode 100644
index 0000000000..9972a2f128
--- /dev/null
+++ b/internal/api/sso_config_preservation_test.go
@@ -0,0 +1,237 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+ "github.com/stretchr/testify/require"
+)
+
+// These synthetic settings cover every persisted nested field omitted from the
+// detail DTO, rather than copying the implementation's preservation allowlist.
+func unrepresentedSSOFixture(kind config.SSOProviderType) config.SSOProvider {
+ return config.SSOProvider{
+ ID: "advanced", Name: "Advanced SSO", Type: kind,
+ AllowedGroups: []string{"operators"}, AllowedDomains: []string{"example.test"},
+ AllowedEmails: []string{"[email protected]"}, GroupsClaim: "groups",
+ GroupRoleMappings: map[string]string{"operators": "admin"},
+ OIDC: &config.OIDCProviderConfig{
+ IssuerURL: "https://idp.example.test/oidc", ClientID: "pulse", ClientSecret: "synthetic-oidc-secret", ClientSecretSet: true,
+ RedirectURL: "https://pulse.example.test/callback", LogoutURL: "https://idp.example.test/logout", Scopes: []string{"openid", "email"},
+ UsernameClaim: "preferred_username", EmailClaim: "mail", CABundle: "/synthetic/trust.pem",
+ },
+ SAML: &config.SAMLProviderConfig{
+ IDPSSOURL: "https://idp.example.test/sso", IDPEntityID: "https://idp.example.test", IDPCertificate: "synthetic-idp-certificate",
+ SPEntityID: "https://pulse.example.test", SignRequests: true, UsernameAttr: "username", EmailAttr: "email", GroupsAttr: "groups",
+ IDPSLOURL: "https://idp.example.test/slo", IDPCertFile: "/synthetic/idp.pem", IDPIssuer: "synthetic-issuer",
+ SPACSPath: "/synthetic/acs", SPMetadataPath: "/synthetic/metadata", SPCertificate: "synthetic-sp-certificate", SPPrivateKey: "synthetic-private-key-canary",
+ SPCertFile: "/synthetic/sp.pem", SPKeyFile: "/synthetic/sp.key", WantAssertionsSigned: true, AllowUnencrypted: true,
+ FirstNameAttr: "given_name", LastNameAttr: "family_name", NameIDFormat: "synthetic-name-format", ForceAuthn: true, RelayStateTemplate: "synthetic-relay-state",
+ },
+ }
+}
+
+func unrepresentedSSOFields(kind config.SSOProviderType) []reflect.StructField {
+ var runtime, response reflect.Type
+ if kind == config.SSOProviderTypeOIDC {
+ runtime, response = reflect.TypeOf(config.OIDCProviderConfig{}), reflect.TypeOf(SSOProviderOIDCResponse{})
+ } else {
+ runtime, response = reflect.TypeOf(config.SAMLProviderConfig{}), reflect.TypeOf(SSOProviderSAMLResponse{})
+ }
+ represented := map[string]bool{"clientSecret": true, "-": true}
+ for i := 0; i < response.NumField(); i++ {
+ represented[strings.Split(response.Field(i).Tag.Get("json"), ",")[0]] = true
+ }
+ var hidden []reflect.StructField
+ for i := 0; i < runtime.NumField(); i++ {
+ field := runtime.Field(i)
+ if !represented[strings.Split(field.Tag.Get("json"), ",")[0]] {
+ hidden = append(hidden, field)
+ }
+ }
+ return hidden
+}
+
+func putUnrepresentedSSO(t *testing.T, router *Router, payload interface{}) *httptest.ResponseRecorder {
+ t.Helper()
+ body, err := json.Marshal(payload)
+ require.NoError(t, err)
+ req := httptest.NewRequest(http.MethodPut, "/api/security/sso/providers/advanced", strings.NewReader(string(body)))
+ rec := httptest.NewRecorder()
+ router.handleSSOProvider(rec, req)
+ require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
+ require.NotContains(t, rec.Body.String(), "synthetic-oidc-secret")
+ require.NotContains(t, rec.Body.String(), "synthetic-private-key-canary")
+ return rec
+}
+
+func seedUnrepresentedSSO(t *testing.T, kind config.SSOProviderType) (*Router, config.SSOProvider) {
+ t.Helper()
+ router, _ := setupTestRouter(t)
+ provider := unrepresentedSSOFixture(kind)
+ // Only the selected protocol is persisted in ordinary configurations.
+ if kind == config.SSOProviderTypeOIDC {
+ provider.SAML = nil
+ } else {
+ provider.OIDC = nil
+ }
+ require.NoError(t, router.ssoConfig.AddProvider(provider))
+ require.NoError(t, router.saveSSOConfig())
+ return router, provider
+}
+
+func TestSSOProviderUnrepresentedFields(t *testing.T) {
+ for _, kind := range []config.SSOProviderType{config.SSOProviderTypeOIDC, config.SSOProviderTypeSAML} {
+ t.Run(string(kind), func(t *testing.T) {
+ hidden := unrepresentedSSOFields(kind)
+ wantCount := 3
+ if kind == config.SSOProviderTypeSAML {
+ wantCount = 16
+ }
+ require.Len(t, hidden, wantCount)
+ for _, mode := range []string{"detail round trip", "toggle", "null config", "empty config"} {
+ t.Run(mode, func(t *testing.T) {
+ router, original := seedUnrepresentedSSO(t, kind)
+ snapshot := router.ensureSSOConfig()
+ before, err := json.Marshal(snapshot)
+ require.NoError(t, err)
+ payload := map[string]interface{}{}
+ detail := providerToDetailResponse(&original, router.config.PublicURL, httptest.NewRequest("GET", "/", nil))
+ raw, err := json.Marshal(detail)
+ require.NoError(t, err)
+ require.NoError(t, json.Unmarshal(raw, &payload))
+ payload["name"] = "Renamed SSO"
+ switch mode {
+ case "toggle":
+ delete(payload, string(kind))
+ case "null config":
+ payload[string(kind)] = nil
+ case "empty config":
+ payload[string(kind)] = map[string]interface{}{}
+ }
+ putUnrepresentedSSO(t, router, payload)
+ loaded, err := router.persistence.LoadSSOConfig()
+ require.NoError(t, err)
+ stored := loaded.GetProvider("advanced")
+ require.Equal(t, "Renamed SSO", stored.Name)
+ var actual, prior reflect.Value
+ if kind == config.SSOProviderTypeOIDC {
+ actual, prior = reflect.ValueOf(stored.OIDC).Elem(), reflect.ValueOf(original.OIDC).Elem()
+ require.Equal(t, original.OIDC.ClientSecret, stored.OIDC.ClientSecret)
+ } else {
+ actual, prior = reflect.ValueOf(stored.SAML).Elem(), reflect.ValueOf(original.SAML).Elem()
+ }
+ for _, field := range hidden {
+ require.Equal(t, prior.FieldByIndex(field.Index).Interface(), actual.FieldByIndex(field.Index).Interface(), field.Name)
+ }
+ after, err := json.Marshal(snapshot)
+ require.NoError(t, err)
+ require.Equal(t, string(before), string(after), "published prior snapshot mutated")
+ // A fresh router reads the same saved advanced settings, without exposing them.
+ fresh := &Router{persistence: router.persistence, config: router.config}
+ require.Equal(t, stored, fresh.ensureSSOConfig().GetProvider("advanced"))
+ rec := httptest.NewRecorder()
+ fresh.handleGetSSOProvider(rec, httptest.NewRequest("GET", "/", nil), "advanced")
+ require.NotContains(t, rec.Body.String(), "synthetic-private-key-canary")
+ require.NotContains(t, rec.Body.String(), "synthetic-oidc-secret")
+ })
+ }
+ for _, field := range hidden {
+ key := strings.Split(field.Tag.Get("json"), ",")[0]
+ for _, mode := range []string{"clear", "null", "replace folded"} {
+ t.Run(key+"/"+mode, func(t *testing.T) {
+ router, _ := seedUnrepresentedSSO(t, kind)
+ var value interface{} = ""
+ if field.Type.Kind() == reflect.Bool {
+ value = false
+ }
+ want := value
+ if mode == "null" {
+ value = nil
+ }
+ if mode == "replace folded" {
+ key = strings.ToUpper(key)
+ if field.Type.Kind() == reflect.String {
+ value = "https://replacement.example.test/value"
+ want = value
+ }
+ }
+ payload := map[string]interface{}{"name": "Advanced SSO", "type": kind, string(kind): map[string]interface{}{key: value}}
+ putUnrepresentedSSO(t, router, payload)
+ saved, err := router.persistence.LoadSSOConfig()
+ require.NoError(t, err)
+ var actual reflect.Value
+ if kind == config.SSOProviderTypeOIDC {
+ actual = reflect.ValueOf(saved.GetProvider("advanced").OIDC).Elem()
+ } else {
+ actual = reflect.ValueOf(saved.GetProvider("advanced").SAML).Elem()
+ }
+ require.Equal(t, want, actual.FieldByIndex(field.Index).Interface())
+ })
+ }
+ }
+ })
+ }
+}
+
+func TestSSOProviderUnrepresentedFieldsRespectProtocolChanges(t *testing.T) {
+ for _, kind := range []config.SSOProviderType{config.SSOProviderTypeOIDC, config.SSOProviderTypeSAML} {
+ t.Run(string(kind), func(t *testing.T) {
+ router, _ := setupTestRouter(t)
+ opposite := config.SSOProviderTypeSAML
+ if kind == opposite {
+ opposite = config.SSOProviderTypeOIDC
+ }
+ // Even an old/inactive protocol block must not donate settings or secrets
+ // when switching types. Only this switch's supplied settings are accepted.
+ prior := unrepresentedSSOFixture(opposite)
+ require.NoError(t, router.ssoConfig.AddProvider(prior))
+ require.NoError(t, router.saveSSOConfig())
+ nested := map[string]interface{}{}
+ if kind == config.SSOProviderTypeOIDC {
+ nested["issuerUrl"] = "https://new.example.test"
+ nested["clientId"] = "new-client"
+ } else {
+ nested["idpSsoUrl"] = "https://new.example.test/sso"
+ }
+ putUnrepresentedSSO(t, router, map[string]interface{}{"name": "New protocol", "type": kind, string(kind): nested})
+ saved, err := router.persistence.LoadSSOConfig()
+ require.NoError(t, err)
+ p := saved.GetProvider("advanced")
+ var value reflect.Value
+ if kind == config.SSOProviderTypeOIDC {
+ value = reflect.ValueOf(p.OIDC).Elem()
+ require.Empty(t, p.OIDC.ClientSecret)
+ require.False(t, p.OIDC.ClientSecretSet)
+ require.Nil(t, p.SAML)
+ } else {
+ value = reflect.ValueOf(p.SAML).Elem()
+ require.Nil(t, p.OIDC)
+ }
+ for _, field := range unrepresentedSSOFields(kind) {
+ require.True(t, value.FieldByIndex(field.Index).IsZero(), field.Name)
+ }
+ })
+ }
+}
+
+func TestSSOProviderUnrepresentedAliasesAndBooleans(t *testing.T) {
+ router, _ := seedUnrepresentedSSO(t, config.SSOProviderTypeSAML)
+ // JSON aliases retain the admission decoder's Unicode and escape semantics.
+ req := httptest.NewRequest("PUT", "/api/security/sso/providers/advanced", strings.NewReader(`{"name":"Advanced SSO","type":"saml","SAML":{"wantAſſertionsSigned":false,"spPrivateKe\u0079":""}}`))
+ rec := httptest.NewRecorder()
+ router.handleSSOProvider(rec, req)
+ require.Equal(t, http.StatusOK, rec.Code)
+ require.False(t, router.ensureSSOConfig().GetProvider("advanced").SAML.WantAssertionsSigned)
+ require.Empty(t, router.ensureSSOConfig().GetProvider("advanced").SAML.SPPrivateKey)
+ putUnrepresentedSSO(t, router, map[string]interface{}{"name": "Advanced SSO", "type": "saml", "saml": map[string]interface{}{"wantAssertionsSigned": true, "allowUnencrypted": false, "forceAuthn": false}})
+ p := router.ensureSSOConfig().GetProvider("advanced")
+ require.True(t, p.SAML.WantAssertionsSigned)
+ require.False(t, p.SAML.AllowUnencrypted)
+ require.False(t, p.SAML.ForceAuthn)
+}