@@ -82,23 +82,13 @@ func TestSSOSettings_basic_saml(t *testing.T) {
8282 CheckDestroy : checkSsoSettingsReset (api , provider , defaultSettings .Payload ),
8383 Steps : []resource.TestStep {
8484 {
85- Config : testConfigForSamlProvider ( "new" ) ,
85+ Config : testConfigForSamlProvider ,
8686 Check : resource .ComposeTestCheckFunc (
8787 resource .TestCheckResourceAttr (resourceName , "provider_name" , provider ),
8888 resource .TestCheckResourceAttr (resourceName , "saml_settings.#" , "1" ),
89- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.certificate_path" , "/var/certificate_new" ),
90- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.private_key_path" , "/var/private_key_new" ),
91- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.idp_metadata_path" , "/var/idp_metadata_new" ),
92- ),
93- },
94- {
95- Config : testConfigForSamlProvider ("updated" ),
96- Check : resource .ComposeTestCheckFunc (
97- resource .TestCheckResourceAttr (resourceName , "provider_name" , provider ),
98- resource .TestCheckResourceAttr (resourceName , "saml_settings.#" , "1" ),
99- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.certificate_path" , "/var/certificate_updated" ),
100- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.private_key_path" , "/var/private_key_updated" ),
101- resource .TestCheckResourceAttr (resourceName , "saml_settings.0.idp_metadata_path" , "/var/idp_metadata_updated" ),
89+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.certificate_path" , "devenv/docker/blocks/auth/saml-enterprise/cert.crt" ),
90+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.private_key_path" , "devenv/docker/blocks/auth/saml-enterprise/key.pem" ),
91+ resource .TestCheckResourceAttr (resourceName , "saml_settings.0.idp_metadata_url" , "https://nexus.microsoftonline-p.com/federationmetadata/saml20/federationmetadata.xml" ),
10292 ),
10393 },
10494 {
@@ -305,16 +295,15 @@ func testConfigForOAuth2Provider(provider string, prefix string) string {
305295}` , prefix , provider , urls )
306296}
307297
308- func testConfigForSamlProvider ( prefix string ) string {
309- return fmt . Sprintf ( `resource "grafana_sso_settings" "saml_sso_settings" {
298+ // the SAML configuration needs a valid certificate, private_key and idp_metadata to be accepted by Grafana API
299+ const testConfigForSamlProvider = `resource "grafana_sso_settings" "saml_sso_settings" {
310300 provider_name = "saml"
311301 saml_settings {
312- certificate_path = "/var/certificate_%[1]s "
313- private_key_path = "/var/private_key_%[1]s "
314- idp_metadata_path = "/var/idp_metadata_%[1]s "
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 "
315305 }
316- }` , prefix )
317- }
306+ }`
318307
319308const testConfigWithCustomFields = `resource "grafana_sso_settings" "sso_settings" {
320309 provider_name = "github"
@@ -453,5 +442,21 @@ var testConfigsWithValidationErrors = []string{
453442 client_id = "client_id"
454443 api_url = "https://login.microsoftonline.com/12345/oauth2/v2.0/userinfo"
455444 }
445+ }` ,
446+ // certificate and certificate_path are both configured for saml
447+ `resource "grafana_sso_settings" "saml_sso_settings" {
448+ provider_name = "saml"
449+ saml_settings {
450+ certificate = "this-is-a-valid-certificate"
451+ certificate_path = "/valid/certificate/path"
452+ }
453+ }` ,
454+ // missing idp_metadata for saml
455+ `resource "grafana_sso_settings" "saml_sso_settings" {
456+ provider_name = "saml"
457+ saml_settings {
458+ certificate = "this-is-a-valid-certificate"
459+ private_key = "this-is-a-valid-private-key"
460+ }
456461}` ,
457462}
0 commit comments