@@ -89,6 +89,22 @@ func TestSSOSettings_basic_saml(t *testing.T) {
89
89
resource .TestCheckResourceAttr (resourceName , "saml_settings.0.certificate_path" , "devenv/docker/blocks/auth/saml-enterprise/cert.crt" ),
90
90
resource .TestCheckResourceAttr (resourceName , "saml_settings.0.private_key_path" , "devenv/docker/blocks/auth/saml-enterprise/key.pem" ),
91
91
resource .TestCheckResourceAttr (resourceName , "saml_settings.0.idp_metadata_url" , "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml" ),
92
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.signature_algorithm" , "rsa-sha256" ),
93
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.metadata_valid_duration" , "24h" ),
94
+ ),
95
+ },
96
+ {
97
+ Config : testConfigForSamlProviderUpdated ,
98
+ Check : resource .ComposeTestCheckFunc (
99
+ resource .TestCheckResourceAttr (resourceName , "provider_name" , provider ),
100
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.#" , "1" ),
101
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.certificate_path" , "devenv/docker/blocks/auth/saml-enterprise/cert.crt" ),
102
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.private_key_path" , "devenv/docker/blocks/auth/saml-enterprise/key.pem" ),
103
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.idp_metadata_url" , "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml" ),
104
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.signature_algorithm" , "rsa-sha512" ),
105
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.metadata_valid_duration" , "48h" ),
106
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.assertion_attribute_email" , "email" ),
107
+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.allow_sign_up" , "true" ),
92
108
),
93
109
},
94
110
{
@@ -157,6 +173,51 @@ func TestSSOSettings_customFields(t *testing.T) {
157
173
},
158
174
),
159
175
},
176
+ {
177
+ Config : testConfigWithCustomFieldsUpdated ,
178
+ Check : resource .ComposeTestCheckFunc (
179
+ resource .TestCheckResourceAttr (resourceName , "provider_name" , provider ),
180
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.#" , "1" ),
181
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.client_id" , "client_id_updated" ),
182
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.client_secret" , "client_secret" ),
183
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.scopes" , "email profile" ),
184
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.custom.custom_field" , "custom1_updated" ),
185
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.custom.another_custom_field" , "custom2_updated" ),
186
+ resource .TestCheckResourceAttr (resourceName , "oauth2_settings.0.custom.one_more_custom_field" , "custom4" ),
187
+ // check that all custom fields are returned by the API
188
+ func (s * terraform.State ) error {
189
+ resp , err := api .SsoSettings .GetProviderSettings (provider )
190
+ if err != nil {
191
+ return err
192
+ }
193
+
194
+ payload := resp .GetPayload ()
195
+ settings := payload .Settings .(map [string ]any )
196
+
197
+ // the API returns the settings names in camelCase
198
+ if settings ["clientId" ] != "client_id_updated" {
199
+ t .Fatalf ("expected value for client_id is not equal to the actual value: %s" , settings ["clientId" ])
200
+ }
201
+ if settings ["scopes" ] != "email profile" {
202
+ t .Fatalf ("expected value for scopes is not equal to the actual value: %s" , settings ["scopes" ])
203
+ }
204
+ if settings ["customField" ] != "custom1_updated" {
205
+ t .Fatalf ("expected value for custom_field is not equal to the actual value: %s" , settings ["customField" ])
206
+ }
207
+ if settings ["anotherCustomField" ] != "custom2_updated" {
208
+ t .Fatalf ("expected value for another_custom_field is not equal to the actual value: %s" , settings ["anotherCustomField" ])
209
+ }
210
+ if settings ["oneMoreCustomField" ] != "custom4" {
211
+ t .Fatalf ("expected value for one_more_custom_field is not equal to the actual value: %s" , settings ["oneMoreCustomField" ])
212
+ }
213
+ if _ , ok := settings ["camelCaseField" ]; ok {
214
+ t .Fatalf ("camelCaseField custom field is not expected to exist" )
215
+ }
216
+
217
+ return nil
218
+ },
219
+ ),
220
+ },
160
221
{
161
222
ResourceName : resourceName ,
162
223
ImportState : true ,
@@ -299,9 +360,24 @@ func testConfigForOAuth2Provider(provider string, prefix string) string {
299
360
const testConfigForSamlProvider = `resource "grafana_sso_settings" "saml_sso_settings" {
300
361
provider_name = "saml"
301
362
saml_settings {
302
- certificate_path = "devenv/docker/blocks/auth/saml-enterprise/cert.crt"
303
- private_key_path = "devenv/docker/blocks/auth/saml-enterprise/key.pem"
304
- idp_metadata_url = "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml"
363
+ certificate_path = "devenv/docker/blocks/auth/saml-enterprise/cert.crt"
364
+ private_key_path = "devenv/docker/blocks/auth/saml-enterprise/key.pem"
365
+ idp_metadata_url = "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml"
366
+ signature_algorithm = "rsa-sha256"
367
+ metadata_valid_duration = "24h"
368
+ }
369
+ }`
370
+
371
+ const testConfigForSamlProviderUpdated = `resource "grafana_sso_settings" "saml_sso_settings" {
372
+ provider_name = "saml"
373
+ saml_settings {
374
+ certificate_path = "devenv/docker/blocks/auth/saml-enterprise/cert.crt"
375
+ private_key_path = "devenv/docker/blocks/auth/saml-enterprise/key.pem"
376
+ idp_metadata_url = "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml"
377
+ allow_sign_up = true
378
+ signature_algorithm = "rsa-sha512"
379
+ metadata_valid_duration = "48h"
380
+ assertion_attribute_email = "email"
305
381
}
306
382
}`
307
383
@@ -318,6 +394,20 @@ const testConfigWithCustomFields = `resource "grafana_sso_settings" "sso_setting
318
394
}
319
395
}`
320
396
397
+ const testConfigWithCustomFieldsUpdated = `resource "grafana_sso_settings" "sso_settings" {
398
+ provider_name = "github"
399
+ oauth2_settings {
400
+ client_id = "client_id_updated"
401
+ client_secret = "client_secret"
402
+ scopes = "email profile"
403
+ custom = {
404
+ custom_field = "custom1_updated"
405
+ another_custom_field = "custom2_updated"
406
+ one_more_custom_field = "custom4"
407
+ }
408
+ }
409
+ }`
410
+
321
411
const testConfigWithEmptySettings = `resource "grafana_sso_settings" "sso_settings" {
322
412
provider_name = "okta"
323
413
oauth2_settings {
@@ -449,6 +539,8 @@ var testConfigsWithValidationErrors = []string{
449
539
saml_settings {
450
540
certificate = "this-is-a-valid-certificate"
451
541
certificate_path = "/valid/certificate/path"
542
+ private_key = "this-is-a-valid-private-key"
543
+ idp_metadata_path = "/path/to/metadata"
452
544
}
453
545
}` ,
454
546
// missing idp_metadata for saml
0 commit comments