def test_submit_form(self):
        keypair = generate_test_keypair()
        first_key = EncryptionKey.objects.create(
            public_key=keypair["publickey"], user=self.user, active=True)

        with self.assertRaises(FormServiceException):
            FormService.submit(form_id=self.form.id, content="helo")

        create_signature_key.Command().handle()
        result = FormService.submit(form_id=self.form.id, content="helo")
        pub = pgpy.PGPKey()
        pub.parse(
            SignatureKey.objects.get(
                active=True,
                key_type=SignatureKey.SignatureKeyType.SECONDARY).public_key)

        self.assertEqual(
            bool(pub.verify(result["content"], result["signature"])), True)
        signed_content = json.loads(result["content"])
        self.assertEqual(signed_content["form_data"], "helo")
        self.assertEqual(len(signed_content["public_keys_recipients"]), 1)
        self.assertEqual(
            signed_content["public_key_server"],
            SignatureKey.objects.get(
                active=True,
                key_type=SignatureKey.SignatureKeyType.SECONDARY).public_key)
        self.assertIn("BEGIN PGP PUBLIC KEY BLOCK",
                      signed_content["public_key_server"])
        self.assertNotIn("BEGIN PGP PRIVATE KEY BLOCK",
                         signed_content["public_key_server"])
예제 #2
0
    def setUp(self):
        create_groups.Command().handle()
        self.user = get_user_model().objects.create(username="******")

        self.form = Form.objects.create(name="Hundiformular",
                                        description="Doggo",
                                        js_code="var foo;",
                                        xml_code="<xml></xml>",
                                        active=True)

        # create a group and add a form/user to it
        self.group = Group.objects.create(name="hundigruppe")
        self.user.groups.add(self.group)
        self.user.groups.add(AdministrativeStaffGroup)
        self.form.teams.add(self.group)
        self.keypair = generate_test_keypair()
        self.first_key = EncryptionKey.objects.create(
            public_key=self.keypair["publickey"], user=self.user, active=True)
        create_signature_key.Command().handle()
        self.form_submission = FormService.submit(form_id=self.form.id,
                                                  content="helo")

        self.second_form = Form.objects.create(name="andre",
                                               description="andre",
                                               js_code="var foo;",
                                               xml_code="<xml></xml>",
                                               active=True)
        # create a group and add a form/user to it
        self.second_group = Group.objects.create(name="andre")
        self.second_form.teams.add(self.second_group)
        self.second_form_submission = FormService.submit(
            form_id=self.second_form.id, content="helloo")
예제 #3
0
    def test_retrieve_form_submissions(self):
        self.assertEqual(
            FormReceiverService.retrieve_submitted_forms(self.user).count(), 1)
        FormService.submit(form_id=self.form.id, content="helo")
        self.assertEqual(
            FormReceiverService.retrieve_submitted_forms(self.user).count(), 2)

        self.user.groups.add(self.second_group)
        self.assertEqual(
            FormReceiverService.retrieve_submitted_forms(self.user).count(), 3)
예제 #4
0
 def mutate(self, info, form_id, content):
     try:
         result = FormService.submit(int(from_global_id(form_id)[1]),
                                     content)
     except FormService.exceptions as e:
         raise MutationExecutionException(str(e))
     return SubmitForm(success=True, **result)