Exemplo n.º 1
0
    def _configure_testshib_provider(self, **kwargs):
        """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """
        fetch_metadata = kwargs.pop('fetch_metadata', True)
        assert_metadata_updates = kwargs.pop('assert_metadata_updates', True)
        kwargs.setdefault('name', self.PROVIDER_NAME)
        kwargs.setdefault('enabled', True)
        kwargs.setdefault('visible', True)
        kwargs.setdefault('idp_slug', self.PROVIDER_IDP_SLUG)
        kwargs.setdefault('entity_id', TESTSHIB_ENTITY_ID)
        kwargs.setdefault('metadata_source', TESTSHIB_METADATA_URL)
        kwargs.setdefault('icon_class', 'fa-university')
        kwargs.setdefault(
            'attr_email',
            'urn:oid:1.3.6.1.4.1.5923.1.1.1.6')  # eduPersonPrincipalName
        self.configure_saml_provider(**kwargs)

        if fetch_metadata:
            self.assertTrue(httpretty.is_enabled())
            num_changed, num_failed, num_total, failure_messages = fetch_saml_metadata(
            )
            if assert_metadata_updates:
                self.assertEqual(num_failed, 0)
                self.assertEqual(len(failure_messages), 0)
                self.assertEqual(num_changed, 1)
                self.assertEqual(num_total, 1)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        should_pull_saml_metadata = options.get('pull', False)

        if not should_pull_saml_metadata:
            raise CommandError(
                "Command can only be used with '--pull' option.")

        log_handler = logging.StreamHandler(self.stdout)
        log_handler.setLevel(logging.DEBUG)
        log = logging.getLogger('third_party_auth.tasks')
        log.propagate = False
        log.addHandler(log_handler)
        total, skipped, attempted, updated, failed, failure_messages = fetch_saml_metadata(
        )
        self.stdout.write(u"\nDone."
                          u"\n{total} provider(s) found in database."
                          u"\n{skipped} skipped and {attempted} attempted."
                          u"\n{updated} updated and {failed} failed.\n".format(
                              total=total,
                              skipped=skipped,
                              attempted=attempted,
                              updated=updated,
                              failed=failed,
                          ))

        if failed > 0:
            raise CommandError(
                u"Command finished with the following exceptions:\n\n{failures}"
                .format(failures="\n\n".join(failure_messages)))
Exemplo n.º 3
0
 def handle(self, *args, **options):
     if options["pull"]:
         log_handler = logging.StreamHandler(self.stdout)
         log_handler.setLevel(logging.DEBUG)
         log = logging.getLogger("third_party_auth.tasks")
         log.propagate = False
         log.addHandler(log_handler)
         num_changed, num_failed, num_total = fetch_saml_metadata()
         self.stdout.write(
             "\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n".format(
                 num_changed=num_changed, num_failed=num_failed, num_total=num_total
             )
         )
     else:
         raise CommandError("Unknown argment: {}".format(subcommand))
Exemplo n.º 4
0
 def handle(self, *args, **options):
     if options['pull']:
         log_handler = logging.StreamHandler(self.stdout)
         log_handler.setLevel(logging.DEBUG)
         log = logging.getLogger('third_party_auth.tasks')
         log.propagate = False
         log.addHandler(log_handler)
         num_changed, num_failed, num_total = fetch_saml_metadata()
         self.stdout.write(
             "\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n".format(
                 num_changed=num_changed, num_failed=num_failed, num_total=num_total
             )
         )
     else:
         raise CommandError("Unknown argment: {}".format(subcommand))
Exemplo n.º 5
0
 def test_configure_testshib_provider_with_cache_duration(self):
     """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """
     kwargs = {}
     kwargs.setdefault('name', self.PROVIDER_NAME)
     kwargs.setdefault('enabled', True)
     kwargs.setdefault('visible', True)
     kwargs.setdefault('idp_slug', self.PROVIDER_IDP_SLUG)
     kwargs.setdefault('entity_id', TESTSHIB_ENTITY_ID)
     kwargs.setdefault('metadata_source', TESTSHIB_METADATA_URL_WITH_CACHE_DURATION)
     kwargs.setdefault('icon_class', 'fa-university')
     kwargs.setdefault('attr_email', 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6')  # eduPersonPrincipalName
     self.configure_saml_provider(**kwargs)
     self.assertTrue(httpretty.is_enabled())
     num_changed, num_failed, num_total = fetch_saml_metadata()
     self.assertEqual(num_failed, 0)
     self.assertEqual(num_changed, 1)
     self.assertEqual(num_total, 1)
Exemplo n.º 6
0
    def handle(self, *args, **options):
        should_pull_saml_metadata = options.get('pull', False)

        if not should_pull_saml_metadata:
            raise CommandError("Command can only be used with '--pull' option.")

        log_handler = logging.StreamHandler(self.stdout)
        log_handler.setLevel(logging.DEBUG)
        log = logging.getLogger('third_party_auth.tasks')
        log.propagate = False
        log.addHandler(log_handler)
        num_changed, num_failed, num_total = fetch_saml_metadata()
        self.stdout.write(
            "\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n".format(
                num_changed=num_changed, num_failed=num_failed, num_total=num_total
            )
        )
Exemplo n.º 7
0
    def _configure_testshib_provider(self, **kwargs):
        """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """
        fetch_metadata = kwargs.pop('fetch_metadata', True)
        kwargs.setdefault('name', 'TestShib')
        kwargs.setdefault('enabled', True)
        kwargs.setdefault('idp_slug', 'testshib')
        kwargs.setdefault('entity_id', TESTSHIB_ENTITY_ID)
        kwargs.setdefault('metadata_source', TESTSHIB_METADATA_URL)
        kwargs.setdefault('icon_class', 'fa-university')
        kwargs.setdefault('attr_email', 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6')  # eduPersonPrincipalName
        self.configure_saml_provider(**kwargs)

        if fetch_metadata:
            self.assertTrue(httpretty.is_enabled())
            num_changed, num_failed, num_total = fetch_saml_metadata()
            self.assertEqual(num_failed, 0)
            self.assertEqual(num_changed, 1)
            self.assertEqual(num_total, 1)
Exemplo n.º 8
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("saml requires one argument: pull")

        if not SAMLConfiguration.is_enabled():
            raise CommandError("SAML support is disabled via SAMLConfiguration.")

        subcommand = args[0]

        if subcommand == "pull":
            log_handler = logging.StreamHandler(self.stdout)
            log_handler.setLevel(logging.DEBUG)
            log = logging.getLogger('third_party_auth.tasks')
            log.propagate = False
            log.addHandler(log_handler)
            num_changed, num_failed, num_total = fetch_saml_metadata()
            self.stdout.write(
                "\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n".format(
                    num_changed=num_changed, num_failed=num_failed, num_total=num_total
                )
            )
        else:
            raise CommandError("Unknown argment: {}".format(subcommand))
Exemplo n.º 9
0
Arquivo: saml.py Projeto: epixia/spark
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("saml requires one argument: pull")

        if not SAMLConfiguration.is_enabled():
            raise CommandError(
                "SAML support is disabled via SAMLConfiguration.")

        subcommand = args[0]

        if subcommand == "pull":
            log_handler = logging.StreamHandler(self.stdout)
            log_handler.setLevel(logging.DEBUG)
            log = logging.getLogger('third_party_auth.tasks')
            log.propagate = False
            log.addHandler(log_handler)
            num_changed, num_failed, num_total = fetch_saml_metadata()
            self.stdout.write(
                "\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n"
                .format(num_changed=num_changed,
                        num_failed=num_failed,
                        num_total=num_total))
        else:
            raise CommandError("Unknown argment: {}".format(subcommand))
Exemplo n.º 10
0
    def _configure_testshib_provider(self, **kwargs):
        """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """
        fetch_metadata = kwargs.pop('fetch_metadata', True)
        assert_metadata_updates = kwargs.pop('assert_metadata_updates', True)
        kwargs.setdefault('name', self.PROVIDER_NAME)
        kwargs.setdefault('enabled', True)
        kwargs.setdefault('visible', True)
        kwargs.setdefault('idp_slug', self.PROVIDER_IDP_SLUG)
        kwargs.setdefault('entity_id', TESTSHIB_ENTITY_ID)
        kwargs.setdefault('metadata_source', TESTSHIB_METADATA_URL)
        kwargs.setdefault('icon_class', 'fa-university')
        kwargs.setdefault('attr_email', 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6')  # eduPersonPrincipalName
        kwargs.setdefault('max_session_length', None)
        self.configure_saml_provider(**kwargs)

        if fetch_metadata:
            self.assertTrue(httpretty.is_enabled())
            num_total, num_skipped, num_attempted, num_updated, num_failed, failure_messages = fetch_saml_metadata()
            if assert_metadata_updates:
                self.assertEqual(num_total, 1)
                self.assertEqual(num_skipped, 0)
                self.assertEqual(num_attempted, 1)
                self.assertEqual(num_updated, 1)
                self.assertEqual(num_failed, 0)
                self.assertEqual(len(failure_messages), 0)
Exemplo n.º 11
0
    def _configure_testshib_provider(self, **kwargs):
        """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """
        fetch_metadata = kwargs.pop('fetch_metadata', True)
        assert_metadata_updates = kwargs.pop('assert_metadata_updates', True)
        kwargs.setdefault('name', self.PROVIDER_NAME)
        kwargs.setdefault('enabled', True)
        kwargs.setdefault('visible', True)
        kwargs.setdefault("backend_name", "tpa-saml")
        kwargs.setdefault('slug', self.PROVIDER_IDP_SLUG)
        kwargs.setdefault('entity_id', TESTSHIB_ENTITY_ID)
        kwargs.setdefault('metadata_source', TESTSHIB_METADATA_URL)
        kwargs.setdefault('icon_class', 'fa-university')
        kwargs.setdefault(
            'attr_email',
            'urn:oid:1.3.6.1.4.1.5923.1.1.1.6')  # eduPersonPrincipalName
        kwargs.setdefault('max_session_length', None)
        saml_provider = self.configure_saml_provider(**kwargs)  # pylint: disable=no-member

        if fetch_metadata:
            self.assertTrue(httpretty.is_enabled())
            num_total, num_skipped, num_attempted, num_updated, num_failed, failure_messages = fetch_saml_metadata(
            )
            if assert_metadata_updates:
                self.assertEqual(num_total, 1)
                self.assertEqual(num_skipped, 0)
                self.assertEqual(num_attempted, 1)
                self.assertEqual(num_updated, 1)
                self.assertEqual(num_failed, 0)
                self.assertEqual(len(failure_messages), 0)
        return saml_provider