Пример #1
0
    def from_config(cls, _db):
        """Initialize an AuthdataUtility from site configuration.

        :return: An AuthdataUtility if one is configured; otherwise
        None.

        :raise CannotLoadConfiguration: If an AuthdataUtility is
        incompletely configured.
        """
        integration = Configuration.integration(
            Configuration.ADOBE_VENDOR_ID_INTEGRATION)
        if not integration:
            return None
        vendor_id = integration.get(Configuration.ADOBE_VENDOR_ID)
        library_uri = integration.get(cls.LIBRARY_URI_KEY)
        library = Library.instance(_db)
        library_short_name = library.library_registry_short_name
        secret = library.library_registry_shared_secret
        other_libraries = integration.get(cls.OTHER_LIBRARIES_KEY, {})
        if (not vendor_id or not library_uri or not library_short_name
                or not secret):
            raise CannotLoadConfiguration(
                "Adobe Vendor ID configuration is incomplete. %s, %s, library.library_registry_short_name and library.library_registry_shared_secret must all be defined."
                % (cls.LIBRARY_URI_KEY, Configuration.ADOBE_VENDOR_ID))
        if '|' in library_short_name:
            raise CannotLoadConfiguration(
                "Library short name cannot contain the pipe character.")
        return cls(vendor_id, library_uri, library_short_name, secret,
                   other_libraries)
Пример #2
0
    def temp_config(self):
        """Configure a basic Vendor ID Service setup."""
        with temp_config() as config:
            library_uri = "http://a-library/"
            secret = "a-secret"
            vendor_id = "Some Vendor"
            short_name = "a library"
            config[Configuration.INTEGRATIONS][
                Configuration.ADOBE_VENDOR_ID_INTEGRATION] = {
                    Configuration.ADOBE_VENDOR_ID: vendor_id,
                    AuthdataUtility.LIBRARY_URI_KEY: library_uri,
                }
            library = Library.instance(self._db)
            library.library_registry_short_name = short_name
            library.library_registry_shared_secret = secret

            yield config
    library.collections.append(collection)
    collection.password = basic_token
    collection.external_account_id = library_id
    collection.url = url
    collection.set_setting("ebook_loan_length", ebook_loan_length)
    collection.set_setting("eaudio_loan_length", eaudio_loan_length)


def convert_content_server(_db, library):
    config = Configuration.integration("Content Server")
    if not config:
        print u"No content server configuration, not creating a Collection for it."
        return
    url = config.get('url')
    collection, ignore = get_one_or_create(_db,
                                           Collection,
                                           protocol=Collection.OPDS_IMPORT,
                                           name="Open Access Content Server")
    library.collections.append(collection)
    collection.url = url


library = Library.instance(_db)
copy_library_registry_information(_db, library)
convert_overdrive(_db, library)
convert_bibliotheca(_db, library)
convert_axis(_db, library)
convert_one_click(_db, library)
convert_content_server(_db, library)
_db.commit()
Пример #4
0
 def initialize_library(cls, _db):
     """Initialize the Library object with default data."""
     library = Library.instance(_db)
     library.library_registry_short_name = cls.LIBRARY_REGISTRY_SHORT_NAME
     library.library_registry_shared_secret = cls.LIBRARY_REGISTRY_SHARED_SECRET
Пример #5
0
    def test_loans_status(self):
        
        provider = MockAuthenticationProvider(
            patrons={"user": "******"},
            test_username="******",
            test_password="******",
        )
        library = Library.instance(self._db)
        auth = Authenticator(library, provider)

        class MockPatronActivity(object):
            def __init__(self, _db, data_source_name):
                self.source = DataSource.lookup(_db, data_source_name)
                self.succeed = True
                
            def patron_activity(self, patron, pin):
                if self.succeed:
                    # Simulate a patron with nothing going on.
                    return
                else:
                    raise ValueError("Doomed to fail!")
        
        overdrive = MockPatronActivity(self._db, DataSource.OVERDRIVE)
        threem = MockPatronActivity(self._db, DataSource.BIBLIOTHECA)
        axis = MockPatronActivity(self._db, DataSource.AXIS_360)

        # Test a scenario where all providers succeed.
        status = ServiceStatus(self._db, auth, overdrive, threem, axis)
        response = status.loans_status(response=True)
        for value in response.values():
            assert value.startswith('SUCCESS')

        # Simulate a failure in one of the providers.
        overdrive.succeed = False
        response = status.loans_status(response=True)
        eq_("FAILURE: Doomed to fail!", response['Overdrive patron account'])

        # Simulate failures on the ILS level.
        def test_with_broken_basic_auth_provider(value):
            class BrokenBasicAuthProvider(object):
                def testing_patron(self, _db):
                    return value
        
            auth.basic_auth_provider = BrokenBasicAuthProvider()
            response = status.loans_status(response=True)
            eq_({'Patron authentication':
                 'Could not create patron with configured credentials.'},
                response)

        # Test patron can't authenticate
        test_with_broken_basic_auth_provider(
            (None, "password that didn't work")
        )

        # Auth provider is just totally broken.
        test_with_broken_basic_auth_provider(None)

        # If the auth process returns a problem detail, the problem
        # detail is used as the basis for the error message.
        class ExpiredPatronProvider(object):
            def testing_patron(self, _db):
                return EXPIRED_CREDENTIALS, None

        auth.basic_auth_provider = ExpiredPatronProvider()
        response = status.loans_status(response=True)
        eq_({'Patron authentication': EXPIRED_CREDENTIALS.response[0]},
            response
        )