@@ -15,34 +15,64 @@ func TestAccKeycloakDataSourceSamlClientInstallationProvider_basic(t *testing.T)
1515 clientId := acctest .RandomWithPrefix ("tf-acc" )
1616
1717 resourceName := "keycloak_saml_client.saml_client"
18- dataSourceName := "data.keycloak_saml_client_installation_provider.saml_sp_descriptor "
18+ dataSourceName := "data.keycloak_saml_client_installation_provider.descriptor "
1919
2020 resource .Test (t , resource.TestCase {
2121 ProviderFactories : testAccProviderFactories ,
2222 PreCheck : func () { testAccPreCheck (t ) },
2323 CheckDestroy : testAccCheckKeycloakSamlClientDestroy (),
2424 Steps : []resource.TestStep {
2525 {
26- Config : testDataSourceKeycloakSamlClientInstallationProvider_basic (clientId ),
26+ Config : testDataSourceKeycloakSamlClientInstallationProvider (clientId , "saml-sp-descriptor" ),
2727 Check : resource .ComposeTestCheckFunc (
2828 resource .TestCheckResourceAttrPair (dataSourceName , "realm_id" , resourceName , "realm_id" ),
2929 resource .TestCheckResourceAttrPair (dataSourceName , "client_id" , resourceName , "id" ),
3030 resource .TestCheckResourceAttr (dataSourceName , "provider_id" , "saml-sp-descriptor" ),
31- testAccCheckDataKeycloakSamlClientInstallationProvider (dataSourceName ),
31+ resource .TestCheckResourceAttr (dataSourceName , "zip_files.%" , "0" ),
32+ testAccCheckDataKeycloakSamlClientInstallationProvider_isXML (dataSourceName , "value" ),
3233 ),
3334 },
3435 },
3536 })
3637}
3738
38- func testAccCheckDataKeycloakSamlClientInstallationProvider (resourceName string ) resource.TestCheckFunc {
39+ func TestAccKeycloakDataSourceSamlClientInstallationProvider_zip (t * testing.T ) {
40+ t .Parallel ()
41+ clientId := acctest .RandomWithPrefix ("tf-acc" )
42+
43+ resourceName := "keycloak_saml_client.saml_client"
44+ dataSourceName := "data.keycloak_saml_client_installation_provider.descriptor"
45+
46+ resource .Test (t , resource.TestCase {
47+ ProviderFactories : testAccProviderFactories ,
48+ PreCheck : func () { testAccPreCheck (t ) },
49+ CheckDestroy : testAccCheckKeycloakSamlClientDestroy (),
50+ Steps : []resource.TestStep {
51+ {
52+ Config : testDataSourceKeycloakSamlClientInstallationProvider (clientId , "mod-auth-mellon" ),
53+ Check : resource .ComposeTestCheckFunc (
54+ resource .TestCheckResourceAttrPair (dataSourceName , "realm_id" , resourceName , "realm_id" ),
55+ resource .TestCheckResourceAttrPair (dataSourceName , "client_id" , resourceName , "id" ),
56+ resource .TestCheckResourceAttr (dataSourceName , "provider_id" , "mod-auth-mellon" ),
57+ resource .TestCheckResourceAttr (dataSourceName , "zip_files.%" , "4" ),
58+ testAccCheckDataKeycloakSamlClientInstallationProvider_isXML (dataSourceName , "zip_files.idp-metadata.xml" ),
59+ testAccCheckDataKeycloakSamlClientInstallationProvider_isXML (dataSourceName , "zip_files.sp-metadata.xml" ),
60+ resource .TestCheckResourceAttrSet (dataSourceName , "zip_files.client-cert.pem" ),
61+ resource .TestCheckResourceAttrSet (dataSourceName , "zip_files.client-private-key.pem" ),
62+ ),
63+ },
64+ },
65+ })
66+ }
67+
68+ func testAccCheckDataKeycloakSamlClientInstallationProvider_isXML (resourceName string , attributeName string ) resource.TestCheckFunc {
3969 return func (s * terraform.State ) error {
4070 rs , ok := s .RootModule ().Resources [resourceName ]
4171 if ! ok {
4272 return fmt .Errorf ("resource not found: %s" , resourceName )
4373 }
4474
45- value := rs .Primary .Attributes ["value" ]
75+ value := rs .Primary .Attributes [attributeName ]
4676
4777 err := xml .Unmarshal ([]byte (value ), new (interface {}))
4878 if err != nil {
@@ -53,7 +83,7 @@ func testAccCheckDataKeycloakSamlClientInstallationProvider(resourceName string)
5383 }
5484}
5585
56- func testDataSourceKeycloakSamlClientInstallationProvider_basic (clientId string ) string {
86+ func testDataSourceKeycloakSamlClientInstallationProvider (clientId string , providerId string ) string {
5787 return fmt .Sprintf (`
5888data "keycloak_realm" "realm" {
5989 realm = "%s"
@@ -64,10 +94,10 @@ resource "keycloak_saml_client" "saml_client" {
6494 realm_id = data.keycloak_realm.realm.id
6595}
6696
67- data "keycloak_saml_client_installation_provider" "saml_sp_descriptor " {
97+ data "keycloak_saml_client_installation_provider" "descriptor " {
6898 realm_id = data.keycloak_realm.realm.id
6999 client_id = keycloak_saml_client.saml_client.id
70- provider_id = "saml-sp-descriptor "
100+ provider_id = "%s "
71101}
72- ` , testAccRealm .Realm , clientId )
102+ ` , testAccRealm .Realm , clientId , providerId )
73103}
0 commit comments