Esempio n. 1
0
    def put(self, field_id):
        """
        Update a single field's attributes.

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body,
                                        requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202) # Updated
        self.finish(response)
Esempio n. 2
0
    def test_handler_cache_hit(self):
        GLApiCache.invalidate()

        handler = self.request(path='/public')
        resp = yield handler.get()

        self.assertEqual(len(GLApiCache.memory_cache_dict), 1)

        cached_resp = GLApiCache.get("/public", "en")

        second_resp = yield handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)

        # Check that a different language doesn't blow away a different resource
        handler_fr = self.request(path='/public',
                                  headers={'gl-language': 'fr'})
        resp_fr = yield handler_fr.get()
        cached_resp_fr = GLApiCache.get("/public", "fr")

        self.assertEqual(resp_fr, cached_resp_fr)

        s = reduce(lambda x, y: x + len(y),
                   GLApiCache.memory_cache_dict.values(), 0)

        self.assertEqual(s, 2)
        self.assertNotEqual(resp_fr, cached_resp)
Esempio n. 3
0
    def put(self, lang):
        request = json.loads(self.request.body)

        yield update_custom_texts(lang, request)

        GLApiCache.invalidate()

        self.set_status(202)  # Updated
Esempio n. 4
0
    def put(self, lang):
        request = json.loads(self.request.body)

        yield update_custom_texts(lang, request)

        GLApiCache.invalidate()

        self.set_status(202)  # Updated
Esempio n. 5
0
    def initialization(self):
        self.responses = []

        # we need to reset settings.session to keep each test independent
        GLSessions.clear()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
Esempio n. 6
0
def set_onion_service_info(store, hostname, key):
    node_fact = NodeFactory(store)
    node_fact.set_val(u'onionservice', hostname)

    priv_fact = PrivateFactory(store)
    priv_fact.set_val(u'tor_onion_key', key)

    GLApiCache.invalidate()
Esempio n. 7
0
    def initialization(self):
        self.responses = []

        # we need to reset settings.session to keep each test independent
        GLSessions.clear()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
Esempio n. 8
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()
Esempio n. 9
0
    def delete(self, field_id):
        """
        Delete a single field template.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
Esempio n. 10
0
    def post(self):
        request = self.validate_message(self.request.body, requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)
        # cache must be updated in order to set wizard_done = True
        yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
Esempio n. 11
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()
Esempio n. 12
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()
Esempio n. 13
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()
Esempio n. 14
0
    def delete(self, field_id):
        """
        Delete a single field template.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
Esempio n. 15
0
    def delete(self, step_id):
        """
        Delete the specified step.

        :param step_id:
        :raises StepIdNotFound: if there is no step with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_step(step_id)

        GLApiCache.invalidate()
Esempio n. 16
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
Esempio n. 17
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
Esempio n. 18
0
    def post(self):
        request = self.validate_message(self.request.body,
                                        requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)
        # cache must be updated in order to set wizard_done = True
        yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
Esempio n. 19
0
    def delete(self, step_id):
        """
        Delete the specified step.

        :param step_id:
        :raises StepIdNotFound: if there is no step with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_step(step_id)

        GLApiCache.invalidate()
Esempio n. 20
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()
Esempio n. 21
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()
Esempio n. 22
0
    def post(self):
        request = self.validate_message(self.request.content.read(),
                                        requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)

        yield serialize_node(self.request.language)

        # Invalidation is performed at this stage only after the asserts within
        # wizard have ensured that the wizard can be executed.
        GLApiCache.invalidate()
Esempio n. 23
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
Esempio n. 24
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()

        self.set_status(200)  # Ok and return no content
        self.finish()
Esempio n. 25
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
Esempio n. 27
0
    def post(self):
        """
        """
        request = self.validate_message(self.request.body,
                                        requests.WizardFirstSetupDesc)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
Esempio n. 28
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication
        """
        request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(self.current_user.user_id, request, self.request.language)

        GLApiCache.invalidate()

        self.write(receiver_status)
Esempio n. 29
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        # get the updated list of contexts, and update the cache
        GLApiCache.invalidate('contexts')

        self.set_status(200)
Esempio n. 30
0
    def post(self, obj_key, obj_id):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_model_img(model_map[obj_key], obj_id, uploaded_file['body'].read())
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
Esempio n. 31
0
    def post(self, key):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_file(uploaded_file['body'].read(), key)
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
Esempio n. 32
0
    def post(self, key):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_file(uploaded_file['body'].read(), key)
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
Esempio n. 33
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        p = '/fake/sync/res'
        handler = self.request(handler_cls=FakeSyncHandler, path=p)
        resp = handler.get()

        cached_resp = GLApiCache.get(p, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)
Esempio n. 34
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        # get the updated list of contexts, and update the cache
        GLApiCache.invalidate('contexts')

        self.set_status(200)
Esempio n. 35
0
    def post(self):
        """
        """
        request = self.validate_message(self.request.body,
                                        requests.WizardFirstSetupDesc)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish()
Esempio n. 36
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        fake_path = '/xxx'
        fake_uri = 'https://www.globaleaks.org' + fake_path
        handler = self.request(handler_cls=FakeSyncHandler, uri=fake_uri)
        resp = handler.get()

        cached_resp = GLApiCache.get(fake_path, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)
Esempio n. 37
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()

        self.set_status(200)  # OK and return not content
        self.finish()
Esempio n. 38
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language, self.request.request_type)

        GLApiCache.invalidate()

        self.write(response)
Esempio n. 39
0
    def test_get(self):
        handler = self.request()

        yield handler.get(lang=u'en')

        self.assertNotIn('12345', self.responses[0])

        yield admin_l10n.update_custom_texts(u'en', custom_texts)

        GLApiCache.invalidate('l10n')

        yield handler.get(lang=u'en')

        self.assertIn('12345', self.responses[1])
        self.assertEqual('54321', self.responses[1]['12345'])
Esempio n. 40
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()

        self.set_status(200) # OK and return not content
        self.finish()
Esempio n. 41
0
    def test_get(self):
        handler = self.request()

        yield handler.get(lang=u'en')

        self.assertNotIn('12345', self.responses[0])

        yield admin_l10n.update_custom_texts(u'en', custom_texts)

        GLApiCache.invalidate('l10n')

        yield handler.get(lang=u'en')

        self.assertIn('12345', self.responses[1])
        self.assertEqual('54321', self.responses[1]['12345'])
Esempio n. 42
0
    def put(self):
        """
        Update the node infos.

        Request: AdminNodeDesc
        Response: AdminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body, requests.AdminNodeDesc)

        node_description = yield update_node(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202)  # Updated
        self.write(node_description)
Esempio n. 43
0
    def post(self):
        """
        Get the specified receiver.

        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminReceiverDesc)

        response = yield create_receiver(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish(response)
Esempio n. 44
0
    def post(self):
        """
        Create a new context.

        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield create_context(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
Esempio n. 45
0
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        GLApiCache.invalidate()

        self.set_status(200) # OK and return not content
        self.finish()
Esempio n. 46
0
    def put(self, receiver_id):
        """
        Update the specified receiver.

        Parameters: receiver_id
        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound, ContextId
        """
        request = self.validate_message(self.request.body, requests.AdminReceiverDesc)

        response = yield update_receiver(receiver_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)
        self.finish(response)
Esempio n. 47
0
    def put(self):
        """
        Update the node infos.

        Request: AdminNodeDesc
        Response: AdminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminNodeDesc)

        node_description = yield update_node(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202)  # Updated
        self.write(node_description)
Esempio n. 48
0
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        GLApiCache.invalidate()

        self.set_status(200)  # OK and return not content
        self.finish()
Esempio n. 49
0
    def post(self):
        """
        Create a new step.

        :return: the serialized step
        :rtype: StepDesc
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body, requests.StepDesc)

        response = yield create_step(request, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(201)
        self.finish(response)
Esempio n. 50
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
Esempio n. 51
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language,
                                   self.request.request_type)

        GLApiCache.invalidate()

        self.write(response)
Esempio n. 52
0
    def put(self, user_id):
        """
        Update the specified user.

        Parameters: user_id
        Request: AdminUserDesc
        Response: AdminUserDesc
        Errors: InvalidInputFormat, UserIdNotFound
        """
        request = self.validate_message(self.request.body, requests.AdminUserDesc)

        response = yield admin_update_user(user_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)
        self.finish(response)
Esempio n. 53
0
 def test_invalidate(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
Esempio n. 54
0
    def post(self):
        """
        Get the specified receiver.

        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminReceiverDesc)

        response = yield create_receiver(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
Esempio n. 55
0
    def post(self):
        """
        Create a new context.

        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield create_context(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish(response)
Esempio n. 56
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication
        """
        request = self.validate_message(self.request.body,
                                        requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(
            self.current_user.user_id, request, self.request.language)

        GLApiCache.invalidate()

        self.write(receiver_status)
Esempio n. 57
0
    def post(self):
        """
        Create a new field.

        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body, requests.AdminFieldDesc)

        response = yield create_field(request, self.request.language, self.request.request_type)

        GLApiCache.invalidate()

        self.set_status(201)
        self.write(response)
Esempio n. 58
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(200)
        self.finish(response)
Esempio n. 59
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(200)
        self.finish(response)