Exemplo n.º 1
0
    def test_handle_delete_auth(self):
        applicatie = Applicatie.objects.create(client_ids=["id1"],
                                               label="for delete",
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f"{config.api_root}/applicaties/{uuid}"
        webhook_url = reverse(
            "notificaties-webhook",
            kwargs={"version": settings.REST_FRAMEWORK["DEFAULT_VERSION"]},
        )
        data = {
            "kanaal": "autorisaties",
            "hoofdObject": applicatie_url,
            "resource": "applicatie",
            "resourceUrl": applicatie_url,
            "actie": "delete",
            "aanmaakdatum": "2012-01-14T00:00:00Z",
            "kenmerken": {},
        }

        response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)
        self.assertEqual(
            Applicatie.objects.filter(client_ids=["id1"]).count(), 0)
    def test_handle_delete_auth(self):
        applicatie = Applicatie.objects.create(client_ids=['id1'],
                                               label='for delete',
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f'{config.api_root}/applicaties/{uuid}'
        webhook_url = reverse(
            'notificaties-webhook',
            kwargs={'version': settings.REST_FRAMEWORK['DEFAULT_VERSION']})
        data = {
            'kanaal': 'autorisaties',
            'hoofdObject': applicatie_url,
            'resource': 'applicatie',
            'resourceUrl': applicatie_url,
            'actie': 'delete',
            'aanmaakdatum': '2012-01-14T00:00:00Z',
            'kenmerken': {}
        }

        response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)
        self.assertEqual(
            Applicatie.objects.filter(client_ids=['id1']).count(), 0)
Exemplo n.º 3
0
    def test_handle_update_auth(self):
        applicatie = Applicatie.objects.create(client_ids=["id1"],
                                               label="before",
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f"{config.api_root}/applicaties/{uuid}"

        self.assertEqual(applicatie.autorisaties.count(), 0)

        # webhook_url = get_operation_url('notification_receive')
        webhook_url = reverse(
            "notificaties-webhook",
            kwargs={"version": settings.REST_FRAMEWORK["DEFAULT_VERSION"]},
        )
        responses = {
            applicatie_url: {
                "client_ids": ["id1"],
                "label":
                "after",
                "heeftAlleAutorisaties":
                False,
                "autorisaties": [{
                    "component":
                    "zrc",
                    "scopes": [
                        "zds.scopes.zaken.lezen",
                        "zds.scopes.zaken.aanmaken",
                    ],
                    "zaaktype":
                    "https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1",
                    "maxVertrouwelijkheidaanduiding":
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            "kanaal": "autorisaties",
            "hoofdObject": applicatie_url,
            "resource": "applicatie",
            "resourceUrl": applicatie_url,
            "actie": "partial_update",
            "aanmaakdatum": "2012-01-14T00:00:00Z",
            "kenmerken": {},
        }

        with mock_client(responses):
            response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

        applicatie.refresh_from_db()

        self.assertEqual(applicatie.uuid, uuid)
        self.assertEqual(applicatie.heeft_alle_autorisaties, False)
        self.assertEqual(applicatie.label, "after")
        self.assertEqual(applicatie.autorisaties.count(), 1)
    def test_handle_update_auth(self):
        applicatie = Applicatie.objects.create(client_ids=['id1'],
                                               label='before',
                                               heeft_alle_autorisaties=True)
        uuid = applicatie.uuid
        config = AuthorizationsConfig.get_solo()
        applicatie_url = f'{config.api_root}/applicaties/{uuid}'

        self.assertEqual(applicatie.autorisaties.count(), 0)

        # webhook_url = get_operation_url('notification_receive')
        webhook_url = reverse(
            'notificaties-webhook',
            kwargs={'version': settings.REST_FRAMEWORK['DEFAULT_VERSION']})
        responses = {
            applicatie_url: {
                'client_ids': ['id1'],
                'label':
                'after',
                'heeftAlleAutorisaties':
                False,
                'autorisaties': [{
                    'component':
                    'NRC',
                    'scopes': [
                        'zds.scopes.zaken.lezen',
                        'zds.scopes.zaken.aanmaken',
                    ],
                    'zaaktype':
                    'https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1',
                    'maxVertrouwelijkheidaanduiding':
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            'kanaal': 'autorisaties',
            'hoofdObject': applicatie_url,
            'resource': 'applicatie',
            'resourceUrl': applicatie_url,
            'actie': 'partial_update',
            'aanmaakdatum': '2012-01-14T00:00:00Z',
            'kenmerken': {}
        }

        with mock_client(responses):
            response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

        applicatie.refresh_from_db()

        self.assertEqual(applicatie.uuid, uuid)
        self.assertEqual(applicatie.heeft_alle_autorisaties, False)
        self.assertEqual(applicatie.label, 'after')
        self.assertEqual(applicatie.autorisaties.count(), 1)
Exemplo n.º 5
0
    def test_handle_create_auth(self):
        config = AuthorizationsConfig.get_solo()
        uuid = _uuid.uuid4()
        applicatie_url = f"{config.api_root}applicaties/{uuid}"
        webhook_url = reverse("notificaties-webhook")

        responses = {
            applicatie_url: {
                "client_ids": ["id1"],
                "label":
                "Melding Openbare Ruimte consumer",
                "heeftAlleAutorisaties":
                False,
                "autorisaties": [{
                    "component":
                    "zrc",
                    "scopes": [
                        "zds.scopes.zaken.lezen",
                        "zds.scopes.zaken.aanmaken",
                    ],
                    "zaaktype":
                    "https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1",
                    "maxVertrouwelijkheidaanduiding":
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            "kanaal": "autorisaties",
            "hoofdObject": applicatie_url,
            "resource": "applicatie",
            "resourceUrl": applicatie_url,
            "actie": "create",
            "aanmaakdatum": "2012-01-14T00:00:00Z",
            "kenmerken": {},
        }
        with mock_client(responses):
            response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

        applicatie = Applicatie.objects.get(client_ids=["id1"])

        self.assertEqual(applicatie.uuid, uuid)
    def test_handle_create_auth(self):
        config = AuthorizationsConfig.get_solo()
        uuid = _uuid.uuid4()
        applicatie_url = f'{config.api_root}/applicaties/{uuid}'
        webhook_url = reverse('notificaties-webhook')

        responses = {
            applicatie_url: {
                'client_ids': ['id1'],
                'label':
                'Melding Openbare Ruimte consumer',
                'heeftAlleAutorisaties':
                False,
                'autorisaties': [{
                    'component':
                    'NRC',
                    'scopes': [
                        'zds.scopes.zaken.lezen',
                        'zds.scopes.zaken.aanmaken',
                    ],
                    'zaaktype':
                    'https://ref.tst.vng.cloud/zrc/api/v1/catalogus/1/zaaktypen/1',
                    'maxVertrouwelijkheidaanduiding':
                    VertrouwelijkheidsAanduiding.beperkt_openbaar,
                }],
            }
        }
        data = {
            'kanaal': 'autorisaties',
            'hoofdObject': applicatie_url,
            'resource': 'applicatie',
            'resourceUrl': applicatie_url,
            'actie': 'create',
            'aanmaakdatum': '2012-01-14T00:00:00Z',
            'kenmerken': {}
        }
        with mock_client(responses):
            response = self.client.post(webhook_url, data)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT,
                         response.data)

        applicatie = Applicatie.objects.get(client_ids=['id1'])

        self.assertEqual(applicatie.uuid, uuid)
    def handle(self, *args, **options):
        # For the steps below, see:
        # https://open-zaak.readthedocs.io/en/latest/installation/configuration.html#open-notificaties

        try:
            authorizations_api_root = options["authorizations_api_root"]
            municipality = options["municipality"]
            openzaak_to_notif_secret = options["openzaak_to_notif_secret"]
            notif_to_openzaak_secret = options["notif_to_openzaak_secret"]

            # Step 1
            auth_config = AuthorizationsConfig.get_solo()
            auth_config.api_root = authorizations_api_root
            auth_config.component = ComponentTypes.nrc
            auth_config.save()

            # Step 2
            if not APICredential.objects.filter(
                api_root=authorizations_api_root
            ).exists():
                APICredential.objects.create(
                    api_root=authorizations_api_root,
                    label=f"Open Zaak {municipality}",
                    client_id=f"open-notificaties-{municipality.lower()}",
                    secret=notif_to_openzaak_secret,
                    user_id=f"open-notificaties-{municipality.lower()}",
                    user_representation=f"Open Notificaties {municipality}",
                )

            # Step 3
            JWTSecret.objects.create(
                identifier=f"open-zaak-backend-{municipality.lower()}",
                secret=openzaak_to_notif_secret,
            )

            self.stdout.write(
                self.style.SUCCESS(
                    "Initial configuration for Open Notificaties was setup successfully"
                )
            )
        except Exception as e:
            raise CommandError(
                f"Something went wrong while setting up initial configuration: {e}"
            )
Exemplo n.º 8
0
    def test_setup_configuration(self):
        ac_root = "https://open-zaak.utrecht.nl/autorisaties/api/v1/"
        municipality = "Utrecht"
        openzaak_to_notif_secret = "12345"
        notif_to_openzaak_secret = "54321"

        call_command(
            "setup_configuration",
            ac_root,
            municipality,
            openzaak_to_notif_secret,
            notif_to_openzaak_secret,
        )

        ac_config = AuthorizationsConfig.get_solo()
        self.assertEqual(ac_config.api_root, ac_root)
        self.assertEqual(ac_config.component, ComponentTypes.nrc)

        api_credential = APICredential.objects.get()
        self.assertEqual(api_credential.api_root, ac_root)
        self.assertEqual(
            api_credential.label,
            f"Open Zaak {municipality}",
        )
        self.assertEqual(
            api_credential.client_id, f"open-notificaties-{municipality.lower()}"
        )
        self.assertEqual(api_credential.secret, notif_to_openzaak_secret)
        self.assertEqual(
            api_credential.user_id, f"open-notificaties-{municipality.lower()}"
        )
        self.assertEqual(
            api_credential.user_representation, f"Open Notificaties {municipality}"
        )

        notif_api_jwtsecret_ac = JWTSecret.objects.get()
        self.assertEqual(
            notif_api_jwtsecret_ac.identifier,
            f"open-zaak-backend-{municipality.lower()}",
        )
        self.assertEqual(notif_api_jwtsecret_ac.secret, openzaak_to_notif_secret)