コード例 #1
0
    def process_post(self):
        protocol = flask.request.form.get("protocol")
        id = flask.request.form.get("id")
        auth_service = ExternalIntegration.admin_authentication(self._db)
        fields = {"protocol": protocol, "id": id, "auth_service": auth_service}
        error = self.validate_form_fields(**fields)
        if error:
            return error

        is_new = False

        if not auth_service:
            if protocol:
                auth_service, is_new = get_one_or_create(
                    self._db,
                    ExternalIntegration,
                    protocol=protocol,
                    goal=ExternalIntegration.ADMIN_AUTH_GOAL,
                )
            else:
                return NO_PROTOCOL_FOR_NEW_SERVICE

        name = flask.request.form.get("name")
        auth_service.name = name

        [protocol] = [p for p in self.protocols if p.get("name") == protocol]
        result = self._set_integration_settings_and_libraries(auth_service, protocol)
        if isinstance(result, ProblemDetail):
            return result

        if is_new:
            return Response(str(auth_service.protocol), 201)
        else:
            return Response(str(auth_service.protocol), 200)
コード例 #2
0
    def test_admin_auth_services_post_create(self):
        with self.request_context_with_admin("/", method="POST"):
            flask.request.form = MultiDict([
                ("name", "oauth"),
                ("protocol", "Google OAuth"),
                ("url", "http://url2"),
                ("username", "username"),
                ("password", "password"),
                (
                    "libraries",
                    json.dumps([{
                        "short_name": self._default_library.short_name,
                        "domains": ["nypl.org", "gmail.com"],
                    }]),
                ),
            ])
            response = (self.manager.admin_auth_services_controller.
                        process_admin_auth_services())
            assert response.status_code == 201

        # The auth service was created and configured properly.
        auth_service = ExternalIntegration.admin_authentication(self._db)
        assert auth_service.protocol == response.get_data(as_text=True)
        assert "oauth" == auth_service.name
        assert "http://url2" == auth_service.url
        assert "username" == auth_service.username
        assert "password" == auth_service.password

        assert [self._default_library] == auth_service.libraries
        setting = ConfigurationSetting.for_library_and_externalintegration(
            self._db, "domains", self._default_library, auth_service)
        assert "domains" == setting.key
        assert ["nypl.org", "gmail.com"] == json.loads(setting.value)
コード例 #3
0
    def test_admin_auth_services_post_create(self):
        with self.request_context_with_admin("/", method="POST"):
            flask.request.form = MultiDict([
                ("name", "oauth"),
                ("protocol", "Google OAuth"),
                ("url", "http://url2"),
                ("username", "username"),
                ("password", "password"),
                ("libraries",
                 json.dumps([{
                     "short_name": self._default_library.short_name,
                     "domains": ["nypl.org", "gmail.com"]
                 }])),
            ])
            response = self.manager.admin_auth_services_controller.process_admin_auth_services(
            )
            eq_(response.status_code, 201)

        # The auth service was created and configured properly.
        auth_service = ExternalIntegration.admin_authentication(self._db)
        eq_(auth_service.protocol, response.response[0])
        eq_("oauth", auth_service.name)
        eq_("http://url2", auth_service.url)
        eq_("username", auth_service.username)
        eq_("password", auth_service.password)

        eq_([self._default_library], auth_service.libraries)
        setting = ConfigurationSetting.for_library_and_externalintegration(
            self._db, "domains", self._default_library, auth_service)
        eq_("domains", setting.key)
        eq_(["nypl.org", "gmail.com"], json.loads(setting.value))
コード例 #4
0
    def test_admin_auth_services_post_create(self):
        with self.request_context_with_admin("/", method="POST"):
            flask.request.form = MultiDict([
                ("name", "oauth"),
                ("protocol", "Google OAuth"),
                ("url", "http://url2"),
                ("username", "username"),
                ("password", "password"),
                ("libraries", json.dumps([{ "short_name": self._default_library.short_name,
                                            "domains": ["nypl.org", "gmail.com"] }])),
            ])
            response = self.manager.admin_auth_services_controller.process_admin_auth_services()
            eq_(response.status_code, 201)

        # The auth service was created and configured properly.
        auth_service = ExternalIntegration.admin_authentication(self._db)
        eq_(auth_service.protocol, response.response[0])
        eq_("oauth", auth_service.name)
        eq_("http://url2", auth_service.url)
        eq_("username", auth_service.username)
        eq_("password", auth_service.password)

        eq_([self._default_library], auth_service.libraries)
        setting = ConfigurationSetting.for_library_and_externalintegration(
            self._db, "domains", self._default_library, auth_service
        )
        eq_("domains", setting.key)
        eq_(["nypl.org", "gmail.com"], json.loads(setting.value))