#!/usr/share/ucs-test/runner python
## desc: Check for ucs/server/saml-idp-server/* variable
## tags: [saml]
## exposure: safe
## packages:
##   - univention-saml

from __future__ import print_function
from univention.config_registry import ConfigRegistry
from univention.testing.utils import get_ldap_connection, fail

if __name__ == '__main__':
	ucr = ConfigRegistry()
	ucr.load()

	lo = get_ldap_connection()
	for res in lo.search('univentionService=univention-saml', attr=['cn', 'associatedDomain']):
		print(res[1])
		fqdn = '%s.%s' % (res[1].get('cn')[0], res[1].get('associatedDomain')[0])
		if ucr.get('ucs/server/saml-idp-server/%s' % fqdn) != fqdn:
			fail('ucs/server/saml-idp-server/%s is %s, expected %s' % (fqdn, ucr.get('ucs/server/saml-idp-server/%s' % fqdn), fqdn))
